Class Map<K,V>
- All Implemented Interfaces:
ICollection<IMap<K,
,V>, IEntry<K, V>> IMap<K,
,V> Iterable<IEntry<K,
,V>> Function<K,
V>
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 implementation.
-
Nested Class Summary
Nested classes/interfaces inherited from interface io.lacuna.bifurcan.IMap
IMap.Mixin<K,
V> -
Field Summary
FieldsFields inherited from class io.lacuna.bifurcan.IMap.Mixin
hash
-
Constructor Summary
ConstructorsConstructorDescriptionMap()
Map
(ToLongFunction<K> hashFn, BiPredicate<K, K> equalsFn) Creates a map. -
Method Summary
Modifier and TypeMethodDescriptionclone()
boolean
difference
(IMap<K, ?> m) difference
(ISet<K> keys) static <K,
V> Map <K, V> empty()
boolean
boolean
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> static <K,
V> Map <K, V> static <K,
V> Map <K, V> static <K,
V> Map <K, V> intersection
(IMap<K, ?> m) intersection
(ISet<K> keys) boolean
isLinear()
iterator()
keyHash()
keys()
linear()
This returns a data structure which is linear, or temporarily mutable.mapValues
(BiFunction<K, V, U> f) nth
(long idx) put
(K key, V value, BinaryOperator<V> merge) long
size()
split
(int parts) Splits the collection into roughly even pieces, for parallel processing.update
(K key, UnaryOperator<V> update) update
(K key, UnaryOperator<V> update, Object editor) Methods inherited from class io.lacuna.bifurcan.IMap.Mixin
hashCode, toString
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface io.lacuna.bifurcan.ICollection
nth
Methods inherited from interface io.lacuna.bifurcan.IMap
apply, containsAll, containsAll, containsAny, containsAny, entries, get, getOrCreate, iterator, put, sliceIndices, spliterator, stream, toMap, values
-
Field Details
-
EMPTY
-
-
Constructor Details
-
Map
Creates a map.- Parameters:
hashFn
- a function which yields the hash value of keysequalsFn
- a function which checks equality of keys
-
Map
public Map()
-
-
Method Details
-
from
-
from
-
from
-
from
-
empty
-
keys
-
keyHash
- Returns:
- the hash function used by the map
-
keyEquality
- Returns:
- the key equality semantics used by the map
-
get
-
put
- Parameters:
merge
- a function which will be invoked if there is a pre-existing value underkey
, with the current value as the first argument and new value as the second, to determine the combined result- Returns:
- an updated map with
value
underkey
-
put
-
update
-
update
-
remove
-
remove
-
contains
- Returns:
- true if
key
is in the map, false otherwise
-
indexOf
- Returns:
- the index of
key
within the collection, if it's present
-
nth
-
forked
Description copied from interface:ICollection
This returns a data structure which is forked, which is equivalent to Clojure's persistent data structures, also sometimes called functional or immutable. This is called "forked" because it means that multiple functions can make divergent changes to the data structure without affecting each other.If 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.
- Returns:
- a forked form of the data structure
-
linear
Description copied from interface:ICollection
This returns a data structure which is linear, or temporarily mutable. The term "linear", as used here, does not completely align with the formal definition of linear types as used in type theory. It is meant to describe the linear dataflow of the method calls, and as a converse to "forked" data structures.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.
- Returns:
- a linear form of this data structure
-
mapValues
- Type Parameters:
U
- the new type of the values- Parameters:
f
- a function which transforms the values- Returns:
- a transformed map which shares the same equality semantics
-
split
Description copied from interface:ICollection
Splits the collection into roughly even pieces, for parallel processing. Depending on the size and contents of the collection, this function may not return exactlyparts
subsets.- Parameters:
parts
- the target number of pieces- Returns:
- a list containing subsets of the collection.
-
union
-
merge
-
difference
-
intersection
-
difference
-
intersection
-
size
public long size()- Returns:
- the number of elements in the collection
-
isLinear
public boolean isLinear()- Returns:
- true, if the collection is linear
-
iterator
-
equals
-
equals
- Overrides:
equals
in classIMap.Mixin<K,
V>
-
clone
-