public class Map<K,V> extends Object implements IMap<K,V>, Cloneable
PersistentHashMap for lookups and construction for collections smaller than 100k entries, and has
equivalent performance for larger collections.
By ensuring that equivalent maps always have equivalent layout in memory, it can perform equality checks and set operations (union, difference, intersection) significantly faster than a more naive implementation.. By keeping the memory layout of each node more compact, iteration is at least 2x faster than Clojure's map.
| Constructor and Description |
|---|
Map() |
Map(ToLongFunction<K> hashFn,
BiPredicate<K,K> equalsFn)
Creates a map.
|
| Modifier and Type | Method and Description |
|---|---|
Map<K,V> |
clone() |
boolean |
contains(K key) |
Map<K,V> |
difference(IMap<K,?> m) |
Map<K,V> |
difference(ISet<K> keys) |
boolean |
equals(IMap<K,V> m,
BiPredicate<V,V> valEquals) |
boolean |
equals(Object obj) |
Map<K,V> |
forked()
This returns a data structure which is forked, which is equivalent to Clojure's persistent
data structures, also sometimes called functional or immutable.
|
static <K,V> Map<K,V> |
from(IList<IEntry<K,V>> entries) |
static <K,V> Map<K,V> |
from(IMap<K,V> map) |
static <K,V> Map<K,V> |
from(Iterator<IEntry<K,V>> entries) |
static <K,V> Map<K,V> |
from(Map<K,V> map) |
V |
get(K key,
V defaultValue) |
int |
hashCode() |
OptionalLong |
indexOf(K key) |
Map<K,V> |
intersection(IMap<K,?> m) |
Map<K,V> |
intersection(ISet<K> keys) |
boolean |
isLinear() |
Iterator<IEntry<K,V>> |
iterator() |
BiPredicate<K,K> |
keyEquality() |
ToLongFunction<K> |
keyHash() |
Set<K> |
keys() |
Map<K,V> |
linear()
This returns a data structure which is linear, or temporarily mutable.
|
<U> Map<K,U> |
mapValues(BiFunction<K,V,U> f) |
Map<K,V> |
merge(IMap<K,V> m,
BinaryOperator<V> mergeFn) |
IEntry<K,V> |
nth(long idx) |
Map<K,V> |
put(K key,
V value,
BinaryOperator<V> merge) |
Map<K,V> |
put(K key,
V value,
BinaryOperator<V> merge,
Object editor) |
Map<K,V> |
remove(K key) |
Map<K,V> |
remove(K key,
Object editor) |
long |
size() |
List<Map<K,V>> |
split(int parts)
Splits the collection into roughly even pieces, for parallel processing.
|
String |
toString() |
Map<K,V> |
union(IMap<K,V> m) |
Map<K,V> |
update(K key,
UnaryOperator<V> update) |
Map<K,V> |
update(K key,
UnaryOperator<V> update,
Object editor) |
finalize, getClass, notify, notifyAll, wait, wait, waitapply, containsAll, containsAll, containsAny, containsAny, entries, get, getOrCreate, hashSortedEntries, put, save, spliterator, stream, toMap, valuesnth, savepublic static final Map EMPTY
public Map(ToLongFunction<K> hashFn, BiPredicate<K,K> equalsFn)
hashFn - a function which yields the hash value of keysequalsFn - a function which checks equality of keyspublic Map()
public static <K,V> Map<K,V> from(IMap<K,V> map)
map - another mappublic static <K,V> Map<K,V> from(Map<K,V> map)
mappublic static <K,V> Map<K,V> from(Iterator<IEntry<K,V>> entries)
entries - an iterator of IEntry objectspublic static <K,V> Map<K,V> from(IList<IEntry<K,V>> entries)
entries - a list of IEntry objectspublic ToLongFunction<K> keyHash()
public BiPredicate<K,K> keyEquality()
keyEquality in interface IMap<K,V>public boolean contains(K key)
public OptionalLong indexOf(K key)
public Map<K,V> forked()
ICollectionIf only a single function or scope uses the data structure, it can be left as a linear data structure, which can have significant performance benefits.
If the data structure is already forked, it will simply return itself.
public Map<K,V> linear()
ICollection
If ICollection.forked() is called on a linear collection, all references to that linear collection should be discarded.
If the data structure is already linear, it will simply return itself.
public <U> Map<K,U> mapValues(BiFunction<K,V,U> f)
public List<Map<K,V>> split(int parts)
ICollectionparts subsets.public Map<K,V> difference(ISet<K> keys)
difference in interface IMap<K,V>keyspublic Map<K,V> intersection(ISet<K> keys)
intersection in interface IMap<K,V>keyspublic Map<K,V> difference(IMap<K,?> m)
difference in interface IMap<K,V>mpublic Map<K,V> intersection(IMap<K,?> m)
intersection in interface IMap<K,V>mpublic long size()
public boolean isLinear()