Class IntMap<V>
- All Implemented Interfaces:
ICollection<IMap<Long,
,V>, IEntry<Long, V>> IMap<Long,
,V> ISortedMap<Long,
,V> Iterable<IEntry<Long,
,V>> Function<Long,
V>
A map which has integer keys, which is an combination of Okasaki and Gill's
Fast Mergeable Integer Maps with the memory layout
suggested by Steindorfer and Vinju used in
Map
, with which it shares the same broad
performance
characteristics.
This collection keeps the keys in sorted order, and can thought of as either a map of integers or a sparse vector.
It provides slice(long, long)
, inclusiveFloorIndex(Long)
, and ceilIndex(Long)
methods which
allow for lookups and filtering on its keys.
-
Nested Class Summary
Nested classes/interfaces inherited from interface io.lacuna.bifurcan.IMap
IMap.Mixin<K,
V> Nested classes/interfaces inherited from interface io.lacuna.bifurcan.ISortedMap
ISortedMap.Mixin<K,
V> -
Field Summary
Fields inherited from class io.lacuna.bifurcan.IMap.Mixin
hash
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionceilIndex
(long key) clone()
boolean
contains
(long key) boolean
difference
(IMap<Long, ?> b) difference
(ISet<Long> keys) boolean
boolean
floorIndex
(long key) 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 <V> IntMap
<V> static <V> IntMap
<V> static <V> IntMap
<V> from
(Collection<Map.Entry<Number, V>> collection) static <V> IntMap
<V> get
(long key) inclusiveFloorIndex
(Long key) indexOf
(long key) intersection
(IMap<Long, ?> b) intersection
(ISet<Long> keys) boolean
isLinear()
iterator()
keyHash()
linear()
This returns a data structure which is linear, or temporarily mutable.<U> IntMap
<U> mapValues
(BiFunction<Long, V, U> f) nth
(long idx) put
(long key, V value, BinaryOperator<V> merge) put
(long key, V value, BinaryOperator<V> merge, Object editor) put
(Long key, V value, BinaryOperator<V> merge) remove
(long key) long
size()
slice
(long min, long max) slice
(long min, ISortedSet.Bound minBound, long max, ISortedSet.Bound maxBound) split
(int parts) Splits the collection into roughly even pieces, for parallel processing.update
(long key, UnaryOperator<V> update) update
(long key, UnaryOperator<V> update, Object editor) update
(Long key, UnaryOperator<V> update) 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, spliterator, stream, toMap, values
Methods inherited from interface io.lacuna.bifurcan.ISortedMap
ceil, ceil, ceilIndex, first, floor, floor, floorIndex, floorIndex, keys, last, slice, slice, sliceIndices
-
Constructor Details
-
IntMap
public IntMap()
-
-
Method Details
-
from
-
from
-
from
-
from
-
comparator
-
keyHash
- Returns:
- the hash function used by the map
-
keyEquality
- Returns:
- the key equality semantics used by the map
-
slice
-
slice
-
merge
-
difference
-
intersection
-
union
-
difference
-
intersection
-
put
-
put
-
put
- Parameters:
key
- a primitivelong
keyvalue
- a valuemerge
- 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
-
put
-
put
-
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
-
remove
-
remove
-
remove
-
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
-
get
-
get
-
get
-
update
- Parameters:
update
- a function which takes the existing value, ornull
if none exists, and returns an updated value.- Returns:
- an updated map with
update(value)
underkey
.
-
update
-
update
-
contains
public boolean contains(long key) -
contains
- Returns:
- true if
key
is in the map, false otherwise
-
indexOf
- Returns:
- the index of
key
within the collection, if it's present
-
indexOf
-
nth
-
iterator
-
floorIndex
- Returns:
- the entry whose key is either equal to
key
, or just below it. Ifkey
is less than the minimum value in the map, returnsnull
.
-
inclusiveFloorIndex
-
ceilIndex
- Returns:
- the entry whose key is either equal to
key
, or just above it. Ifkey
is greater than the maximum value in the map, returnsnull
.
-
ceilIndex
-
size
public long size()- Returns:
- the number of elements in the collection
-
isLinear
public boolean isLinear()- Returns:
- true, if the collection is linear
-
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
-
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.
-
equals
-
equals
- Overrides:
equals
in classIMap.Mixin<Long,
V>
-
clone
-