public class LinearMap<K,V> extends Object implements IMap<K,V>, Cloneable
HashMap for lookups and construction, and superior in the
case of poor hash distribution. Because entries are stored contiguously, performance of clone() and
iteration is significantly better than HashMap.
The IMap.entries() method is O(1) and allows random access, returning an IList that proxies through to an
underlying array. Partitioning this list is the most efficient way to process the collection in parallel.
However, LinearMap also exposes O(N) split(int) and merge(IMap, BinaryOperator)
methods, which despite their asymptotic complexity can be quite fast in practice. The appropriate way to split this
collection will depend on the use case.
| Modifier and Type | Field and Description |
|---|---|
static int |
MAX_CAPACITY |
| Constructor and Description |
|---|
LinearMap() |
LinearMap(int initialCapacity) |
LinearMap(int initialCapacity,
ToLongFunction<K> hashFn,
BiPredicate<K,K> equalsFn) |
LinearMap(ToLongFunction<K> hashFn,
BiPredicate<K,K> equalsFn) |
| Modifier and Type | Method and Description |
|---|---|
LinearMap<K,V> |
clear() |
LinearMap<K,V> |
clone() |
boolean |
containsAll(IMap<K,?> map) |
boolean |
containsAll(ISet<K> set) |
boolean |
containsAny(IMap<K,?> map) |
boolean |
containsAny(ISet<K> set) |
LinearMap<K,V> |
difference(IMap<K,?> m) |
IMap<K,V> |
difference(ISet<K> keys) |
boolean |
equals(Object obj) |
IMap<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> LinearMap<K,V> |
from(Collection<Map.Entry<K,V>> collection) |
static <K,V> LinearMap<K,V> |
from(IMap<K,V> map) |
static <K,V> LinearMap<K,V> |
from(Iterable<IEntry<K,V>> entries) |
static <K,V> LinearMap<K,V> |
from(Iterator<IEntry<K,V>> iterator) |
static <K,V> LinearMap<K,V> |
from(Map<K,V> map) |
V |
get(K key,
V defaultValue) |
int |
hashCode() |
OptionalLong |
indexOf(K key) |
LinearMap<K,V> |
intersection(IMap<K,?> m) |
LinearMap<K,V> |
intersection(ISet<K> keys) |
boolean |
isLinear() |
BiPredicate<K,K> |
keyEquality() |
ToLongFunction<K> |
keyHash() |
ISet<K> |
keys() |
IMap<K,V> |
linear()
This returns a data structure which is linear, or temporarily mutable.
|
<U> LinearMap<K,U> |
mapValues(BiFunction<K,V,U> f) |
LinearMap<K,V> |
merge(IMap<K,V> m,
BinaryOperator<V> mergeFn) |
IEntry<K,V> |
nth(long index) |
LinearMap<K,V> |
put(K key,
V value) |
LinearMap<K,V> |
put(K key,
V value,
BinaryOperator<V> merge) |
LinearMap<K,V> |
remove(K key) |
long |
size() |
List<LinearMap<K,V>> |
split(int parts)
Splits the collection into roughly even pieces, for parallel processing.
|
String |
toString() |
LinearMap<K,V> |
union(IMap<K,V> m) |
LinearMap<K,V> |
update(K key,
UnaryOperator<V> update) |
finalize, getClass, notify, notifyAll, wait, wait, waitapply, contains, entries, equals, get, getOrCreate, hashSortedEntries, iterator, save, spliterator, stream, toMap, valuesnth, savepublic static final int MAX_CAPACITY
public LinearMap()
public LinearMap(int initialCapacity)
initialCapacity - the initial capacity of the mappublic LinearMap(ToLongFunction<K> hashFn, BiPredicate<K,K> equalsFn)
hashFn - a function which yields the hash value of keysequalsFn - a function which checks equality of keyspublic LinearMap(int initialCapacity,
ToLongFunction<K> hashFn,
BiPredicate<K,K> equalsFn)
initialCapacity - the initial capacity of the maphashFn - a function which yields the hash value of keysequalsFn - a function which checks equality of keyspublic static <K,V> LinearMap<K,V> from(IMap<K,V> map)
map, with the same equality semanticspublic static <K,V> LinearMap<K,V> from(Iterable<IEntry<K,V>> entries)
entriespublic static <K,V> LinearMap<K,V> from(Iterator<IEntry<K,V>> iterator)
iteratorpublic static <K,V> LinearMap<K,V> from(Collection<Map.Entry<K,V>> collection)
collectionpublic ToLongFunction<K> keyHash()
public BiPredicate<K,K> keyEquality()
keyEquality in interface IMap<K,V>public <U> LinearMap<K,U> mapValues(BiFunction<K,V,U> f)
public OptionalLong indexOf(K key)
public long size()
public boolean isLinear()
public IMap<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 IMap<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 List<LinearMap<K,V>> split(int parts)
ICollectionparts subsets.public LinearMap<K,V> difference(IMap<K,?> m)
difference in interface IMap<K,V>mpublic IMap<K,V> difference(ISet<K> keys)
difference in interface IMap<K,V>keyspublic LinearMap<K,V> intersection(IMap<K,?> m)
intersection in interface IMap<K,V>mpublic LinearMap<K,V> intersection(ISet<K> keys)
intersection in interface IMap<K,V>keyspublic boolean containsAll(ISet<K> set)
containsAll in interface IMap<K,V>setpublic boolean containsAll(IMap<K,?> map)
containsAll in interface IMap<K,V>mappublic boolean containsAny(ISet<K> set)
containsAny in interface IMap<K,V>set