From 68275eb998401bb950172ee8989ae992b4a70085 Mon Sep 17 00:00:00 2001 From: Terence Parr Date: Sat, 28 Jul 2012 13:23:52 -0700 Subject: [PATCH] rm singleton set; didn't help. --- .../antlr/v4/runtime/atn/ATNConfigSet.java | 3 +- .../antlr/v4/runtime/misc/Array2DHashSet.java | 1 - .../antlr/v4/runtime/misc/EquivalenceSet.java | 4 +- .../src/org/antlr/v4/runtime/misc/ExtSet.java | 10 -- .../antlr/v4/runtime/misc/SingletonSet.java | 121 ------------------ 5 files changed, 4 insertions(+), 135 deletions(-) delete mode 100644 runtime/Java/src/org/antlr/v4/runtime/misc/ExtSet.java delete mode 100644 runtime/Java/src/org/antlr/v4/runtime/misc/SingletonSet.java diff --git a/runtime/Java/src/org/antlr/v4/runtime/atn/ATNConfigSet.java b/runtime/Java/src/org/antlr/v4/runtime/atn/ATNConfigSet.java index 5d681e405..fc9fd9dc2 100755 --- a/runtime/Java/src/org/antlr/v4/runtime/atn/ATNConfigSet.java +++ b/runtime/Java/src/org/antlr/v4/runtime/atn/ATNConfigSet.java @@ -30,7 +30,6 @@ package org.antlr.v4.runtime.atn; import org.antlr.v4.runtime.misc.Array2DHashSet; -import org.antlr.v4.runtime.misc.EquivalenceSet; import org.antlr.v4.runtime.misc.IntervalSet; import java.util.ArrayList; @@ -272,7 +271,7 @@ public class ATNConfigSet implements Set { /** All configs but hashed by (s, i, _, pi) not incl context. Wiped out * when we go readonly as this set becomes a DFA state. */ - public EquivalenceSet configLookup; + public ConfigHashSet configLookup; /** Track the elements as they are added to the set; supports get(i) */ public final ArrayList configs = new ArrayList(7); diff --git a/runtime/Java/src/org/antlr/v4/runtime/misc/Array2DHashSet.java b/runtime/Java/src/org/antlr/v4/runtime/misc/Array2DHashSet.java index 174c09704..83fe98bb7 100644 --- a/runtime/Java/src/org/antlr/v4/runtime/misc/Array2DHashSet.java +++ b/runtime/Java/src/org/antlr/v4/runtime/misc/Array2DHashSet.java @@ -32,7 +32,6 @@ public class Array2DHashSet implements EquivalenceSet { /** Add o to set if not there; return existing value if already there. * Absorb is used as synonym for add. */ - @Override public T absorb(T o) { if ( n > threshold ) expand(); return absorb_(o); diff --git a/runtime/Java/src/org/antlr/v4/runtime/misc/EquivalenceSet.java b/runtime/Java/src/org/antlr/v4/runtime/misc/EquivalenceSet.java index 31a8ee4e0..65954ada4 100644 --- a/runtime/Java/src/org/antlr/v4/runtime/misc/EquivalenceSet.java +++ b/runtime/Java/src/org/antlr/v4/runtime/misc/EquivalenceSet.java @@ -1,10 +1,12 @@ package org.antlr.v4.runtime.misc; +import java.util.Set; + /** A set that allows us to override equivalence. For a single set, we might * want multiple subset perspectives as defined by different hash code * and equivalence methods. HashSet does not allow us to subclass and * override the equivalence operations, so we have to implement our own * sets that are flexible in terms of equivalence. */ -public interface EquivalenceSet extends ExtSet, EquivalenceRelation { +public interface EquivalenceSet extends Set, EquivalenceRelation { } diff --git a/runtime/Java/src/org/antlr/v4/runtime/misc/ExtSet.java b/runtime/Java/src/org/antlr/v4/runtime/misc/ExtSet.java deleted file mode 100644 index d0e0c11e5..000000000 --- a/runtime/Java/src/org/antlr/v4/runtime/misc/ExtSet.java +++ /dev/null @@ -1,10 +0,0 @@ -package org.antlr.v4.runtime.misc; - -import java.util.Set; - -public interface ExtSet extends Set { - /** Add o to set if not there; return existing value if already there. - * Absorb is used as synonym for add. Need to "fix" Set to be smarter. - */ - public T absorb(T o); -} diff --git a/runtime/Java/src/org/antlr/v4/runtime/misc/SingletonSet.java b/runtime/Java/src/org/antlr/v4/runtime/misc/SingletonSet.java deleted file mode 100644 index f8b1379f0..000000000 --- a/runtime/Java/src/org/antlr/v4/runtime/misc/SingletonSet.java +++ /dev/null @@ -1,121 +0,0 @@ -package org.antlr.v4.runtime.misc; - -import java.util.Collection; -import java.util.Iterator; -import java.util.NoSuchElementException; - -/** A set with a single element. */ -public class SingletonSet implements EquivalenceSet { - protected T element = null; - - public SingletonSet(T o) { - element = o; - } - - @Override - public T absorb(T o) { - if ( o==null ) { - element = o; - return o; - } - if ( element.equals(o) ) return element; - throw new IllegalStateException("Can't add more than one to a singleton set"); - } - - @Override - public int hashCode(T o) { - return o!=null ? o.hashCode() : 0; - } - - @Override - public boolean equals(T a, T b) { - return a==b || a.equals(b); - } - - @Override - public boolean add(T o) { - T a = absorb(o); - return a!=o; - } - - @Override - public int size() { - return element!=null ? 1 : 0; - } - - @Override - public boolean isEmpty() { - return element==null; - } - - @Override - public boolean contains(Object o) { - return element!=null && - (o==element || element.equals(o)); - } - - @Override - public Iterator iterator() { - return new Iterator() { - boolean returned = false; - @Override - public boolean hasNext() { return !returned; } - - @Override - public T next() { - if ( hasNext() ) return element; - throw new NoSuchElementException(); - } - - @Override - public void remove() { element = null; } - }; - } - - @Override - public Object[] toArray() { - Object[] a = { element }; - if ( !isEmpty() ) return a; - return new Object[0]; - } - - @Override - public U[] toArray(U[] a) { - if ( !isEmpty() ) { a[0] = (U)element; return a; } - return a; - } - - @Override - public boolean remove(Object o) { - if ( isEmpty() ) return false; - if ( element.equals(o) ) { element = null; return true; } - return false; - } - - @Override - public boolean containsAll(Collection c) { - return size() == c.size() && this.contains(c.toArray()[0]); - } - - @Override - public boolean addAll(Collection c) { - boolean changed = false; - for (T o : c) { - changed |= add(o); - } - return changed; - } - - @Override - public boolean retainAll(Collection c) { - throw new UnsupportedOperationException(); - } - - @Override - public boolean removeAll(Collection c) { - return false; - } - - @Override - public void clear() { element = null; } -}