01: package prefuse.util.collections;
02:
03: import java.util.HashMap;
04: import java.util.LinkedList;
05:
06: /**
07: * Maintains a breadth-first-search queue as well as depth labels.
08: *
09: * @author <a href="http://jheer.org">jeffrey heer</a>
10: */
11: public class Queue {
12:
13: // TODO: create an optimized implementation of this class
14:
15: private LinkedList m_list = new LinkedList();
16: private HashMap m_map = new HashMap();
17:
18: public void clear() {
19: m_list.clear();
20: m_map.clear();
21: }
22:
23: public boolean isEmpty() {
24: return m_list.isEmpty();
25: }
26:
27: public void add(Object o, int depth) {
28: m_list.add(o);
29: visit(o, depth);
30: }
31:
32: public int getDepth(Object o) {
33: Integer d = (Integer) m_map.get(o);
34: return (d == null ? -1 : d.intValue());
35: }
36:
37: public void visit(Object o, int depth) {
38: m_map.put(o, new Integer(depth));
39: }
40:
41: public Object removeFirst() {
42: return m_list.removeFirst();
43: }
44:
45: public Object removeLast() {
46: return m_list.removeLast();
47: }
48:
49: } // end of class Queue
|