checkpoint
[sbp.git] / src / edu / berkeley / sbp / util / FastSet.java
index a433b7c..d3be774 100644 (file)
@@ -1,19 +1,24 @@
 package edu.berkeley.sbp.util;
 import java.util.*;
 
 package edu.berkeley.sbp.util;
 import java.util.*;
 
-public final class FastSet<T> implements Iterator<T>, Iterable<T> {
+public /*final*/ class FastSet<T> implements Iterator<T>, Iterable<T> {
 
     public static final int INITIAL_SIZE = 128;
 
     private       Object[] array;
     private       T        only  = null;
 
     public static final int INITIAL_SIZE = 128;
 
     private       Object[] array;
     private       T        only  = null;
-    private       int      i     = 0;
+    private       int      i     = -1;
     private       int      size  = 0;
 
     public Iterator<T> iterator() { i=0; return this; }
     public void        remove()   { throw new Error(); }
     public boolean     hasNext()  { return only==null ? i<size : i<1; }
     public T           next()     { return only==null ? (T)array[i++] : (i++)==0 ? only : null; }
     private       int      size  = 0;
 
     public Iterator<T> iterator() { i=0; return this; }
     public void        remove()   { throw new Error(); }
     public boolean     hasNext()  { return only==null ? i<size : i<1; }
     public T           next()     { return only==null ? (T)array[i++] : (i++)==0 ? only : null; }
+    public T get(int i) {
+        if (i==0 && only!=null) return only;
+        if (array==null) return null;
+        return (T)array[i];
+    }
 
     public FastSet() { }
     public FastSet(T t) { only = t; }
 
     public FastSet() { }
     public FastSet(T t) { only = t; }