public interface RandomAccess extends List { }
public interface Queue extends Basket {
- // FIXME
- //public void enqueue(Object o);
- //public Object dequeue();
+ public void enqueue(Object o);
+ public Object dequeue();
}
public interface Stack extends Basket {
public Array(int initialCapacity) { o = new Object[initialCapacity]; }
public Array(Object entry) { this(1); add(entry); }
+ public void enqueue(Object o) { add(o); }
+
+ // FEATURE: make this more efficient with general wraparound
+ public Object dequeue() {
+ if (size==0) return null;
+ Object ret = o[0];
+ for(int i=1; i<size; i++) o[i-1]=o[i];
+ return ret;
+ }
+
public void add(Object obj) { add(size, obj); }
public void add(int i, Object obj) {
size(size + 1);
o[i] = obj; size++;
}
public Object set(int i, Object obj) {
- if (i >= size) throw new IndexOutOfBoundsException(
+ if (i >= o.length) throw new IndexOutOfBoundsException(
"index "+i+" is beyond list boundary "+size);
- Object old = o[i]; o[i] = obj; return old;
+ Object old = o[i]; o[i] = obj;
+ size = Math.max(i+1, size);
+ return old;
}
public Object get(int i) {
if (i >= size) throw new IndexOutOfBoundsException(
public void push(Object o) { add(o); }
}
- //public class Tree implements RandomAccess { } FIXME
-
- //public class IndexedTree extends Tree { } FIXME
-
/** Implementation of a hash table using Radke's quadratic residue
* linear probing. Uses a single array to store all entries.
*
*
* @author adam@ibex.org, crawshaw@ibex.org
*/
- public abstract class Hash implements Basket {
+ public class Hash implements Basket, Map {
static final long serialVersionUID = 3948384093L;
/** Used internally to record used slots. */
int dest = orig * indexmultiple;
int tries = 1;
boolean plus = true;
-
while (entries[dest] != null) {
if (equals(k, entries[dest])) return dest;
dest = Math.abs((orig + (plus ? 1 : -1) * tries * tries) % (entries.length / indexmultiple)) * indexmultiple;
}
}
- public class HashMap extends Hash implements Map {
- public HashMap() { super(); }
- public HashMap(int x, float y) { super(x,y); }
- public HashMap(int x, int z, float y) { super(x,z,y); }
- }
+ // FIXME, BalancedTree goes here
}