public class IntMap<V> extends ISortedMap.Mixin<Long,V>
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 IntMap#slice(Long, Long)
, inclusiveFloorIndex(Long)
, and ceilIndex(Long)
methods which
allow for lookups and filtering on its keys.
ISortedMap.Mixin<K,V>
IMap.Durable<K,V>
hash
Constructor and Description |
---|
IntMap() |
Modifier and Type | Method and Description |
---|---|
OptionalLong |
ceilIndex(long key) |
OptionalLong |
ceilIndex(Long key) |
IntMap<V> |
clone() |
Comparator<Long> |
comparator() |
boolean |
contains(long key) |
boolean |
contains(Long key) |
IntMap<V> |
difference(IMap<Long,?> b) |
IntMap<V> |
difference(ISet<Long> keys) |
boolean |
equals(IMap<Long,V> o,
BiPredicate<V,V> valEquals) |
boolean |
equals(Object obj) |
OptionalLong |
floorIndex(long key) |
IntMap<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 <V> IntMap<V> |
from(Collection<Map.Entry<Number,V>> collection) |
static <V> IntMap<V> |
from(IList<IEntry<Number,V>> list) |
static <V> IntMap<V> |
from(IMap<Number,V> m) |
static <V> IntMap<V> |
from(Map<Number,V> m) |
Optional<V> |
get(long key) |
V |
get(long key,
V defaultValue) |
V |
get(Long key,
V defaultValue) |
OptionalLong |
inclusiveFloorIndex(Long key) |
OptionalLong |
indexOf(long key) |
OptionalLong |
indexOf(Long key) |
IntMap<V> |
intersection(IMap<Long,?> b) |
IntMap<V> |
intersection(ISet<Long> keys) |
boolean |
isLinear() |
Iterator<IEntry<Long,V>> |
iterator() |
BiPredicate<Long,Long> |
keyEquality() |
ToLongFunction<Long> |
keyHash() |
IntMap<V> |
linear()
This returns a data structure which is linear, or temporarily mutable.
|
<U> IntMap<U> |
mapValues(BiFunction<Long,V,U> f) |
IntMap<V> |
merge(IMap<Long,V> b,
BinaryOperator<V> mergeFn) |
IEntry<Long,V> |
nth(long idx) |
IntMap<V> |
put(long key,
V value) |
IntMap<V> |
put(Long key,
V value) |
IntMap<V> |
put(long key,
V value,
BinaryOperator<V> merge) |
IntMap<V> |
put(Long key,
V value,
BinaryOperator<V> merge) |
IntMap<V> |
put(long key,
V value,
BinaryOperator<V> merge,
Object editor) |
IntMap<V> |
put(long key,
V value,
Object editor) |
IntMap<V> |
remove(long key) |
IntMap<V> |
remove(Long key) |
IntMap<V> |
remove(long key,
Object editor) |
long |
size() |
IntMap<V> |
slice(long min,
long max) |
IntMap<V> |
sliceReal(Long min,
Long max) |
List<IntMap<V>> |
split(int parts)
Splits the collection into roughly even pieces, for parallel processing.
|
IntMap<V> |
union(IMap<Long,V> m) |
IntMap<V> |
update(long key,
UnaryOperator<V> update) |
IntMap<V> |
update(Long key,
UnaryOperator<V> update) |
IntMap<V> |
update(long key,
UnaryOperator<V> update,
Object editor) |
hashCode, toString
finalize, getClass, notify, notifyAll, wait, wait, wait
ceil, ceil, ceilIndex, diffSorted, first, floor, floor, floorIndex, floorIndex, keys, last, slice, slice, sliceIndices
apply, containsAll, containsAll, containsAny, containsAny, diff, entries, get, getOrCreate, hashSortedEntries, iterator, save, spliterator, stream, toMap, values
nth
public static <V> IntMap<V> from(IMap<Number,V> m)
m
- another mappublic static <V> IntMap<V> from(Collection<Map.Entry<Number,V>> collection)
public Comparator<Long> comparator()
public ToLongFunction<Long> keyHash()
public BiPredicate<Long,Long> keyEquality()
public IntMap<V> slice(long min, long max)
min
- the inclusive minimum key valuemax
- the inclusive maximum key value[min, max]
public IntMap<V> merge(IMap<Long,V> b, BinaryOperator<V> mergeFn)
b
- another mapmergeFn
- a function which, in the case of key collisions, takes two values and returns the merged resultpublic IntMap<V> difference(ISet<Long> keys)
keys
public IntMap<V> intersection(ISet<Long> keys)
keys
public IntMap<V> union(IMap<Long,V> m)
m
shadowing those in this amppublic IntMap<V> difference(IMap<Long,?> b)
m
public IntMap<V> intersection(IMap<Long,?> b)
m
public IntMap<V> put(long key, V value)
key
- a primitive long
keyvalue
- a valueIntMap
with value
under key
public IntMap<V> put(long key, V value, BinaryOperator<V> merge)
key
- a primitive long
keyvalue
- a valuemerge
- a function which will be invoked if there is a pre-existing value under key
, with the current
value as the first argument and new value as the second, to determine the combined resultpublic IntMap<V> put(Long key, V value, BinaryOperator<V> merge)
merge
- a function which will be invoked if there is a pre-existing value under key
, with the current
value as the first argument and new value as the second, to determine the combined resultvalue
under key
public <U> IntMap<U> mapValues(BiFunction<Long,V,U> f)
U
- the new type of the valuesf
- a function which transforms the valuespublic V get(Long key, V defaultValue)
key
, or defaultValue
if there is no such keypublic IntMap<V> update(Long key, UnaryOperator<V> update)
update
- a function which takes the existing value, or null
if none exists, and returns an updated
value.update(value)
under key
.public IntMap<V> update(long key, UnaryOperator<V> update)
public IntMap<V> update(long key, UnaryOperator<V> update, Object editor)
public boolean contains(long key)
public boolean contains(Long key)
key
is in the map, false otherwisepublic OptionalLong indexOf(Long key)
key
within the collection, if it's presentpublic OptionalLong indexOf(long key)
public OptionalLong floorIndex(long key)
key
, or just below it. If key
is less than the
minimum value in the map, returns null
.public OptionalLong inclusiveFloorIndex(Long key)
public OptionalLong ceilIndex(long key)
key
, or just above it. If key
is greater than the
maximum value in the map, returns null
.public OptionalLong ceilIndex(Long key)
public long size()
public boolean isLinear()
public IntMap<V> forked()
ICollection
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.
public IntMap<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<IntMap<V>> split(int parts)
ICollection
parts
subsets.parts
- the target number of piecespublic boolean equals(IMap<Long,V> o, BiPredicate<V,V> valEquals)
o
- another mapvalEquals
- a predicate which checks value equalitiespublic boolean equals(Object obj)
equals
in class IMap.Mixin<Long,V>