// the Histogram class. /****************************************************************************** CHANGE LOG. 16 Mar 1999: Creation. [pike] ******************************************************************************/ import java.io.PrintStream; import java.io.FileOutputStream; class Histogram_long { private long key; int count; private Histogram_long local left, right; public Histogram_long() { count = 0; left = right = null; } public local int add(long k) { Histogram_long local z = this; System.out.println("A " + k); while (z.count != 0) { if (k == key) return ++z.count; else if (k < key) { if (z.left == null) z.left = new Histogram_long(); z = z.left; } else { if (z.right == null) z.right = new Histogram_long(); z = z.right; } } z.key = k; z.count = 1; return 1; } public local int size() { return (count + (left == null ? 0 : left.size()) + (right == null ? 0 : right.size())); } public local void dump() { dump(System.out); } public local void dump(PrintStream s) { dump(s, null); } public local void dump(String label) { dump(System.out, label); } public local void dump(PrintStream s, String label) { if (count == 0) s.println(label + "\nEmpty."); else { s.println(" " + size() + " total."); dumpNoCount(s, label); } } public local void dumpNoCount(PrintStream s, String label) { if (left == null) s.println(label); else left.dumpNoCount(s, label); s.println(" " + key + ": " + count); if (right != null) right.dumpNoCount(s, label); } }