1 cananian 1.1.2.1 // WorkSet.java, created Tue Feb 23 01:18:37 1999 by cananian
 2 cananian 1.1.2.1 // Copyright (C) 1999 C. Scott Ananian <cananian@alumni.princeton.edu>
 3 cananian 1.1.2.1 // Licensed under the terms of the GNU GPL; see COPYING for details.
 4 cananian 1.1.2.1 package harpoon.Util.Collections;
 5 cananian 1.1.2.1 
 6 cananian 1.1.2.1 import harpoon.Util.Worklist;
 7 cananian 1.1.2.1 
 8 cananian 1.1.2.1 /**
 9 cananian 1.1.2.1  * A <code>WorkSet</code> is a <code>Set</code> offering constant-time
10 cananian 1.1.2.1  * access to the first/last element inserted, and an iterator whose speed
11 cananian 1.1.2.1  * is not dependent on the total capacity of the underlying hashtable.
12 cananian 1.1.2.1  * <p>Conforms to the JDK 1.2 Collections API.
13 cananian 1.1.2.1  * 
14 cananian 1.1.2.1  * @author  C. Scott Ananian <cananian@alumni.princeton.edu>
15 cananian 1.7      * @version $Id: WorkSet.java,v 1.7 2004/02/08 01:56:38 cananian Exp $
16 cananian 1.1.2.1  */
17 cananian 1.7     public class WorkSet<E> extends net.cscott.jutil.WorkSet<E> implements Worklist<E> {
18 cananian 1.7         public WorkSet() { super(); }
19 cananian 1.1.2.1     /** Constructs a new, empty <code>WorkSet</code> with the specified
20 cananian 1.1.2.1      *  initial capacity and default load factor. */
21 cananian 1.7         public WorkSet(int initialCapacity) { super(initialCapacity); }
22 cananian 1.1.2.1     /** Constructs a new, empty <code>WorkSet</code> with the specified
23 cananian 1.1.2.1      *  initial capacity and the specified load factor. */
24 cananian 1.1.2.1     public WorkSet(int initialCapacity, float loadFactor) {
25 cananian 1.7             super(initialCapacity, loadFactor);
26 cananian 1.1.2.1     }
27 cananian 1.1.2.1     /** Constructs a new <code>WorkSet</code> with the contents of the
28 cananian 1.1.2.1      *  specified <code>Collection</code>. */
29 cananian 1.7         public WorkSet(java.util.Collection<? extends E> c) {
30 cananian 1.7             super(c);
31 cananian 1.1.2.1     }
32 cananian 1.1.2.1 
33 cananian 1.1.2.1     /** Looks at the object as the top of this <code>WorkSet</code>
34 cananian 1.1.2.1      *  (treating it as a <code>Stack</code>) without removing it
35 cananian 1.1.2.1      *  from the set/stack. */
36 cananian 1.3.2.2     public E peek() { return getLast(); }
37 cananian 1.1.2.1 
38 cananian 1.1.2.1     /** Removes some item from this and return it (Worklist adaptor
39 cananian 1.1.2.1         method). 
40 cananian 1.1.2.1         <BR> <B>modifies:</B> <code>this</code>
41 cananian 1.1.2.1         <BR> <B>effects:</B> If there exists an <code>Object</code>,
42 cananian 1.1.2.1                              <code>item</code>, that is an element of
43 cananian 1.1.2.1                              <code>this</code>, removes
44 cananian 1.1.2.1                              <code>item</code> from <code>this</code>
45 cananian 1.1.2.1                              and returns <code>item</code>. Else does
46 cananian 1.1.2.1                              nothing.
47 cananian 1.1.2.1     */
48 cananian 1.3.2.2     public E pull() { return removeLast(); }
49 cananian 1.1.2.1 
50 cananian 1.1.2.1     /** Removes the item at the top of this <code>WorkSet</code>
51 cananian 1.1.2.1      *  (treating it as a <code>Stack</code>) and returns that object
52 cananian 1.1.2.1      *  as the value of this function. */
53 cananian 1.3.2.2     public E pop() { return removeLast(); }
54 cananian 1.1.2.1 
55 cananian 1.1.2.1     /** Pushes item onto the top of this <code>WorkSet</code> (treating
56 cananian 1.1.2.1      *  it as a <code>Stack</code>), if it is not already there.
57 cananian 1.1.2.1      *  If the <code>item</code> is already in the set/on the stack,
58 cananian 1.1.2.1      *  then this method does nothing.
59 cananian 1.1.2.1         <BR> <B>modifies:</B> <code>this</code>
60 cananian 1.1.2.1         <BR> <B>effects:</B> If <code>item</code> is not already an
61 cananian 1.1.2.1                              element of <code>this</code>, adds
62 cananian 1.1.2.1                              <code>item</code> to <code>this</code>.
63 cananian 1.1.2.1                              Else does nothing. 
64 cananian 1.1.2.1     */
65 cananian 1.3.2.2     public void push(E item) {
66 cananian 1.1.2.1         this.add(item);
67 cananian 1.1.2.1     }
68 cananian 1.2     }