forked from jasder/antlr
rm singleton set; didn't help.
This commit is contained in:
parent
ee233f7dd3
commit
68275eb998
|
@ -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<ATNConfig> {
|
|||
/** 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<ATNConfig> configLookup;
|
||||
public ConfigHashSet configLookup;
|
||||
|
||||
/** Track the elements as they are added to the set; supports get(i) */
|
||||
public final ArrayList<ATNConfig> configs = new ArrayList<ATNConfig>(7);
|
||||
|
|
|
@ -32,7 +32,6 @@ public class Array2DHashSet<T> implements EquivalenceSet<T> {
|
|||
/** 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);
|
||||
|
|
|
@ -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<T> extends ExtSet<T>, EquivalenceRelation<T> {
|
||||
public interface EquivalenceSet<T> extends Set<T>, EquivalenceRelation<T> {
|
||||
}
|
||||
|
|
|
@ -1,10 +0,0 @@
|
|||
package org.antlr.v4.runtime.misc;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
public interface ExtSet<T> extends Set<T> {
|
||||
/** 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);
|
||||
}
|
|
@ -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<T> implements EquivalenceSet<T> {
|
||||
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<T> iterator() {
|
||||
return new Iterator<T>() {
|
||||
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> 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<? extends T> 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; }
|
||||
}
|
Loading…
Reference in New Issue