// Graph.java // applet/application for displaying pointer graphs // see (near) end of file for original copyright notice import java.util.*; import java.awt.*; import java.awt.event.*; // WindowListener import java.applet.Applet; import java.io.*; // Serializable // ===================== tty/listbox abstraction ======================= // generic output device interface OutputDest { public void newReport(); public void println(String s); } // output to debugging console class ConsoleDest implements OutputDest { public void newReport() {} public void println(String s) { System.out.println(s); } } // output to a gui list box class ListboxDest implements OutputDest { List list; public ListboxDest(List L) { list = L; } public void newReport() { list.removeAll(); } public void println(String s) { list.add(s); } } // ======================== graph representation =========================== // characterizes node neighbors class Degree implements Serializable { // same constants as appear in Node class // (defines kinds of nodes) static final int STACK = Node.STACK; static final int DATA = Node.DATA; static final int HEAP = Node.HEAP; static final int SELF = Node.SELF; static final int OTHER = Node.OTHER; static final int NUM_KINDS = Node.NUM_KINDS; // both arrays indexed by STACK/DATA/HEAP/SELF/OTHER int from[]; // # of ptrs from each kind of obj int to[]; // # of ptrs to each kind of obj Degree() { from = new int[NUM_KINDS]; to = new int[NUM_KINDS]; clear(); } void clear() { for (int i=0; i= 0 && to[i] >= 0); // counts are never negative } assert(from[SELF] == to[SELF]); } // memberwise equality public boolean equals(Object obj) { Degree o = (Degree)obj; for (int i=0; i