change Invokable from two arguments to 3
[sbp.git] / src / edu / berkeley / sbp / util / FastSet.java
index e7ae063..88475e2 100644 (file)
@@ -1,3 +1,5 @@
+// Copyright 2006 all rights reserved; see LICENSE file for BSD-style license
+
 package edu.berkeley.sbp.util;
 import java.util.*;
 
@@ -28,10 +30,23 @@ public /*final*/ class FastSet<T> implements Iterator<T>, Iterable<T>, Visitable
         for(T t : s) array[size++] = t;
     }
 
-    public <B,C> void visit(Invokable<T,B,C> ivbc, B b, C c) {
-        if (only!=null) ivbc.invoke(only, b, c);
+    public void remove(T t) {
+        if (only != null) {
+            if (only==t) only=null;
+            return;
+        }
+        boolean found = false;
+        for(int j=0; j<size; j++) {
+            if (array[j]==t) found = true;
+            if (found && j<size-1) array[j] = array[j+1];
+        }
+        if (found) size--;
+    }
+
+    public <B> void visit(Invokable<T,B> ivbc, B b) {
+        if (only!=null) ivbc.invoke(only, b);
         else for(int j=0; j<size; j++)
-            ivbc.invoke((T)array[j], b, c);
+            ivbc.invoke((T)array[j], b);
     }
 
     public int size() { return only==null ? size : 1; }