mirror of
https://github.com/corda/corda.git
synced 2025-06-13 20:58:19 +00:00
implement ConcurrentHashMap and AtomicReferenceArray
This is the simplest possible ConcurrentHashMap I could come up with that works and is actually concurrent in the way one would expect. It's pretty unconventional, being based on a persistent red-black tree, and not particularly memory-efficient or cache-friendly. I think this is a good place to start, though, and it should perform reasonably well for most workloads. Patches for a more efficient implementation are welcome! I also implemented AtomicReferenceArray, since I was using it in my first, naive attempt to implement ConcurrentHashMap. I had to do a bit of refactoring, including moving some non-standard stuff from java.util.Collections to avian.Data so I could make it available to code outside the java.util package, which is why I had to modify several unrelated files.
This commit is contained in:
@ -42,7 +42,7 @@ public class TreeMap<K,V> implements Map<K,V> {
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return Collections.toString(this);
|
||||
return avian.Data.toString(this);
|
||||
}
|
||||
|
||||
public V get(Object key) {
|
||||
@ -164,7 +164,7 @@ public class TreeMap<K,V> implements Map<K,V> {
|
||||
}
|
||||
|
||||
public <T> T[] toArray(T[] array) {
|
||||
return Collections.toArray(this, array);
|
||||
return avian.Data.toArray(this, array);
|
||||
}
|
||||
|
||||
public void clear() {
|
||||
@ -172,7 +172,7 @@ public class TreeMap<K,V> implements Map<K,V> {
|
||||
}
|
||||
|
||||
public Iterator<K> iterator() {
|
||||
return new Collections.KeyIterator(set.iterator());
|
||||
return new avian.Data.KeyIterator(set.iterator());
|
||||
}
|
||||
}
|
||||
|
||||
@ -225,7 +225,7 @@ public class TreeMap<K,V> implements Map<K,V> {
|
||||
}
|
||||
|
||||
public <T> T[] toArray(T[] array) {
|
||||
return Collections.toArray(this, array);
|
||||
return avian.Data.toArray(this, array);
|
||||
}
|
||||
|
||||
public void clear() {
|
||||
@ -233,7 +233,7 @@ public class TreeMap<K,V> implements Map<K,V> {
|
||||
}
|
||||
|
||||
public Iterator<V> iterator() {
|
||||
return new Collections.ValueIterator(set.iterator());
|
||||
return new avian.Data.ValueIterator(set.iterator());
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user