Package org.ojalgo.array
Class LongToNumberMap<N extends Comparable<N>>
java.lang.Object
org.ojalgo.array.LongToNumberMap<N>
- All Implemented Interfaces:
Map<Long,
,N> SequencedMap<Long,
,N> SortedMap<Long,
,N> Access1D<N>
,Mutate1D.Mixable<N>
,Structure1D
public final class LongToNumberMap<N extends Comparable<N>>
extends Object
implements SortedMap<Long,N>, Access1D<N>, Mutate1D.Mixable<N>
A
SortedMap
with primitive valued long keys and Comparable
values (incl. possibly primitive
double values). The main benefits of using this class is its use of primitive keys and values, and how it
integrates with other parts of ojAlgo. As a general purpose Map
implementation (usage with high
frequency of randomly ordered put and remove operations) it is not very efficient.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final class
LongToNumberMap.MapFactory<N extends Comparable<N>>
Nested classes/interfaces inherited from interface org.ojalgo.structure.Access1D
Access1D.Aggregatable<N extends Comparable<N>>, Access1D.Collectable<N extends Comparable<N>,
R extends Mutate1D>, Access1D.ElementView<N extends Comparable<N>>, Access1D.SelectionView<N extends Comparable<N>>, Access1D.Sliceable<N extends Comparable<N>>, Access1D.Visitable<N extends Comparable<N>> Nested classes/interfaces inherited from interface org.ojalgo.structure.Structure1D
Structure1D.BasicMapper<T>, Structure1D.IndexMapper<T>, Structure1D.IntIndex, Structure1D.Logical<S extends Structure1D,
B extends Structure1D.Logical<S, B>>, Structure1D.LongIndex, Structure1D.LoopCallback -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final DenseArray.Factory
<N> private final GrowthStrategy
private final SparseArray
<N> -
Constructor Summary
ConstructorsConstructorDescriptionLongToNumberMap
(DenseArray.Factory<N> denseFactory, GrowthStrategy growthStrategy) -
Method Summary
Modifier and TypeMethodDescriptionlong
capacity()
The current capacity of the underlying data structure.void
clear()
Comparator
<? super Long> boolean
containsKey
(long key) boolean
containsKey
(Object key) boolean
containsValue
(double value) boolean
containsValue
(Object value) long
count()
The total number of elements in this structure.double
doubleValue
(int key) double
doubleValue
(long key) entrySet()
static <N extends Comparable<N>>
LongToNumberMap.MapFactory<N> factory
(DenseArray.Factory<N> denseFactory) firstKey()
get
(long key) (package private) SparseArray
<N> headMap
(long toKey) boolean
isEmpty()
keySet()
lastKey()
double
mix
(long key, BinaryFunction<N> mixer, double addend) mix
(long key, BinaryFunction<N> mixer, N addend) nonzeros()
Similar toAccess1D.elements()
but avoids elements that are structurally known to be zero.double
put
(long key, double value) void
void
putAll
(LongToNumberMap<N> m) remove
(long key) int
size()
The total number of elements in this structure.subMap
(long fromKey, long toKey) tailMap
(long fromKey) toString()
values()
values
(long fromKey, long toKey) Should return the same elements/values as first callingsubMap(Long, Long)
and thenvalues()
but this method does not create any copies.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface org.ojalgo.structure.Access1D
asCollectable1D, asKeyed1D, axpy, byteValue, byteValue, dot, elements, floatValue, floatValue, intValue, intValue, longValue, longValue, select, shortValue, shortValue, supplyTo, toRawCopy1D
Methods inherited from interface java.util.Map
compute, computeIfAbsent, computeIfPresent, equals, forEach, getOrDefault, hashCode, merge, putIfAbsent, remove, replace, replace, replaceAll
Methods inherited from interface java.util.SequencedMap
firstEntry, lastEntry, pollFirstEntry, pollLastEntry, sequencedEntrySet, sequencedKeySet, sequencedValues
-
Field Details
-
myStorage
-
myDenseFactory
-
myGrowthStrategy
-
-
Constructor Details
-
LongToNumberMap
LongToNumberMap(DenseArray.Factory<N> denseFactory, GrowthStrategy growthStrategy)
-
-
Method Details
-
factory
public static <N extends Comparable<N>> LongToNumberMap.MapFactory<N> factory(DenseArray.Factory<N> denseFactory) -
capacity
public long capacity()The current capacity of the underlying data structure. The capacity is always greater than or equal to the current number of entries in the map. When you add entries to the map the capacity may have to grow. -
clear
public void clear() -
comparator
- Specified by:
comparator
in interfaceSortedMap<Long,
N extends Comparable<N>>
-
containsKey
public boolean containsKey(long key) -
containsKey
- Specified by:
containsKey
in interfaceMap<Long,
N extends Comparable<N>>
-
containsValue
public boolean containsValue(double value) -
containsValue
- Specified by:
containsValue
in interfaceMap<Long,
N extends Comparable<N>>
-
count
public long count()Description copied from interface:Structure1D
The total number of elements in this structure.You only need to implement this method if the structure can contain more than Integer.MAX_VALUE elements.
- Specified by:
count
in interfaceStructure1D
-
doubleValue
public double doubleValue(int key) - Specified by:
doubleValue
in interfaceAccess1D<N extends Comparable<N>>
-
doubleValue
public double doubleValue(long key) - Specified by:
doubleValue
in interfaceAccess1D<N extends Comparable<N>>
-
entrySet
-
firstKey
-
get
- Specified by:
get
in interfaceAccess1D<N extends Comparable<N>>
-
get
-
headMap
-
headMap
-
isEmpty
public boolean isEmpty() -
keySet
-
lastKey
-
mix
- Specified by:
mix
in interfaceMutate1D.Mixable<N extends Comparable<N>>
- Returns:
- The new/mixed value
-
mix
- Specified by:
mix
in interfaceMutate1D.Mixable<N extends Comparable<N>>
-
nonzeros
Description copied from interface:Access1D
Similar toAccess1D.elements()
but avoids elements that are structurally known to be zero. (That does not eliminate all zero-values from this view.) With an arbitrary (dense) unstructured implementation theAccess1D.nonzeros()
andAccess1D.elements()
methods do the same thing! Only some specific implementations are able to actually exploit structure/sparsity to view fewer elements.- Specified by:
nonzeros
in interfaceAccess1D<N extends Comparable<N>>
-
put
public double put(long key, double value) -
put
-
put
-
putAll
-
putAll
-
remove
-
remove
-
size
public int size()Description copied from interface:Structure1D
The total number of elements in this structure.- Specified by:
size
in interfaceMap<Long,
N extends Comparable<N>> - Specified by:
size
in interfaceStructure1D
-
subMap
-
subMap
-
tailMap
-
tailMap
-
toString
-
values
-
values
Should return the same elements/values as first callingsubMap(Long, Long)
and thenvalues()
but this method does not create any copies. Any change in the underlying data structure (this map) will corrupt this method's output. -
getStorage
SparseArray<N> getStorage()
-