import java.util.Iterator;
import java.util.List;
import java.util.Map;
-import java.util.NoSuchElementException;
import java.util.Set;
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.atomic.AtomicReferenceFieldUpdater;
}
}
- private final Hashing<K> hashingobj;
- private final Equiv<K> equalityobj;
-
- Hashing<K> hashing () {
- return hashingobj;
- }
-
- Equiv<K> equality () {
- return equalityobj;
- }
+ private final Equivalence<? super K> equiv;
private transient volatile Object root;
private final transient boolean readOnly;
- TrieMap (final Hashing<K> hashf, final Equiv<K> ef, final boolean readOnly) {
- this.hashingobj = hashf;
- this.equalityobj = ef;
- this.readOnly = readOnly;
- }
-
- TrieMap (final Object r, final Hashing<K> hashf, final Equiv<K> ef, final boolean readOnly) {
- this(hashf, ef, readOnly);
+ TrieMap (final Object r, final Equivalence<? super K> equiv, final boolean readOnly) {
this.root = r;
- }
+ this.equiv = equiv;
+ this.readOnly = readOnly;
- public TrieMap (final Hashing<K> hashf, final Equiv<K> ef) {
- this(newRootNode(), hashf, ef, false);
}
- public TrieMap () {
- this (new Hashing.Default<K>(), Equiv.universal);
+ public TrieMap() {
+ this(newRootNode(), Equivalence.equals(), false);
}
/* internal methods */
INode<K, V> r = RDCSS_READ_ROOT ();
final MainNode<K, V> expmain = r.gcasRead (this);
if (RDCSS_ROOT (r, expmain, r.copyToGen (new Gen (), this))) {
- return new TrieMap<> (r.copyToGen (new Gen (), this), hashing (), equality (), readOnly);
+ return new TrieMap<> (r.copyToGen (new Gen (), this), equiv, readOnly);
} else {
// return snapshot ();
// tailrec
INode<K, V> r = RDCSS_READ_ROOT ();
MainNode<K, V> expmain = r.gcasRead (this);
if (RDCSS_ROOT (r, expmain, r.copyToGen (new Gen (), this))) {
- return new TrieMap<> (r, hashing (), equality (), true);
+ return new TrieMap<> (r, equiv, true);
} else {
// return readOnlySnapshot ();
continue;
}
}
- // @inline
- int computeHash (final K k) {
- return hashingobj.hash (k);
+ int computeHash(final K k) {
+ return equiv.hash(k);
+ }
+
+ boolean equal(final K k1, final K k2) {
+ return equiv.equivalent(k1, k2);
}
final V lookup (final K k) {
}
}
- final V apply (final K k) {
- int hc = computeHash (k);
- Object res = lookuphc (k, hc);
- if (res == null) {
- throw new NoSuchElementException ();
- } else {
- return (V) res;
- }
- }
-
-// final public Option<V> get (K k) {
-// int hc = computeHash (k);
-// return Option.makeOption ((V)lookuphc (k, hc));
-// }
-
@Override
final public V get (final Object k) {
return lookup((K)k);
}
lastReturned = r;
- if(r instanceof Map.Entry) {
+ if (r != null) {
final Map.Entry<K, V> rr = r;
return nextEntry(rr);
}