Package org.ojalgo.array
Class LongToNumberMap<N extends java.lang.Comparable<N>>
- java.lang.Object
-
- org.ojalgo.array.LongToNumberMap<N>
-
- All Implemented Interfaces:
java.util.Map<java.lang.Long,N>
,java.util.SortedMap<java.lang.Long,N>
,Access1D<N>
,Mutate1D.Mixable<N>
,Structure1D
public final class LongToNumberMap<N extends java.lang.Comparable<N>> extends java.lang.Object implements java.util.SortedMap<java.lang.Long,N>, Access1D<N>, Mutate1D.Mixable<N>
ASortedMap
with primitive valued long keys andComparable
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 purposeMap
implementation (usage with high frequency of randomly ordered put and remove operations) it is not very efficient.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
LongToNumberMap.MapFactory<N extends java.lang.Comparable<N>>
-
Nested classes/interfaces inherited from interface org.ojalgo.structure.Access1D
Access1D.Aggregatable<N extends java.lang.Comparable<N>>, Access1D.Collectable<N extends java.lang.Comparable<N>,R extends Mutate1D>, Access1D.ElementView<N extends java.lang.Comparable<N>>, Access1D.SelectionView<N extends java.lang.Comparable<N>>, Access1D.Sliceable<N extends java.lang.Comparable<N>>, Access1D.Visitable<N extends java.lang.Comparable<N>>
-
Nested classes/interfaces inherited from interface java.util.Map
java.util.Map.Entry<K extends java.lang.Object,V extends java.lang.Object>
-
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
Fields Modifier and Type Field Description private DenseArray.Factory<N>
myDenseFactory
private GrowthStrategy
myGrowthStrategy
private SparseArray<N>
myStorage
-
Constructor Summary
Constructors Constructor Description LongToNumberMap(DenseArray.Factory<N> denseFactory, GrowthStrategy growthStrategy)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description long
capacity()
The current capacity of the underlying data structure.void
clear()
java.util.Comparator<? super java.lang.Long>
comparator()
boolean
containsKey(long key)
boolean
containsKey(java.lang.Object key)
boolean
containsValue(double value)
boolean
containsValue(java.lang.Object value)
long
count()
The total number of elements in this structure.double
doubleValue(int key)
double
doubleValue(long key)
java.util.Set<java.util.Map.Entry<java.lang.Long,N>>
entrySet()
static <N extends java.lang.Comparable<N>>
LongToNumberMap.MapFactory<N>factory(DenseArray.Factory<N> denseFactory)
java.lang.Long
firstKey()
N
get(long key)
N
get(java.lang.Object key)
(package private) SparseArray<N>
getStorage()
LongToNumberMap<N>
headMap(long toKey)
LongToNumberMap<N>
headMap(java.lang.Long toKey)
boolean
isEmpty()
java.util.Set<java.lang.Long>
keySet()
java.lang.Long
lastKey()
double
mix(long key, BinaryFunction<N> mixer, double addend)
N
mix(long key, BinaryFunction<N> mixer, N addend)
SparseArray.NonzeroView<N>
nonzeros()
Similar toAccess1D.elements()
but avoids elements that are structurally known to be zero.double
put(long key, double value)
N
put(long key, N value)
N
put(java.lang.Long key, N value)
void
putAll(java.util.Map<? extends java.lang.Long,? extends N> m)
void
putAll(LongToNumberMap<N> m)
N
remove(long key)
N
remove(java.lang.Object key)
int
size()
The total number of elements in this structure.LongToNumberMap<N>
subMap(long fromKey, long toKey)
LongToNumberMap<N>
subMap(java.lang.Long fromKey, java.lang.Long toKey)
LongToNumberMap<N>
tailMap(long fromKey)
LongToNumberMap<N>
tailMap(java.lang.Long fromKey)
java.lang.String
toString()
NumberList<N>
values()
Access1D<N>
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
-
-
-
-
Field Detail
-
myStorage
private final SparseArray<N extends java.lang.Comparable<N>> myStorage
-
myDenseFactory
private final DenseArray.Factory<N extends java.lang.Comparable<N>> myDenseFactory
-
myGrowthStrategy
private final GrowthStrategy myGrowthStrategy
-
-
Constructor Detail
-
LongToNumberMap
LongToNumberMap(DenseArray.Factory<N> denseFactory, GrowthStrategy growthStrategy)
-
-
Method Detail
-
factory
public static <N extends java.lang.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
public java.util.Comparator<? super java.lang.Long> comparator()
-
containsKey
public boolean containsKey(long key)
-
containsKey
public boolean containsKey(java.lang.Object key)
-
containsValue
public boolean containsValue(double value)
-
containsValue
public boolean containsValue(java.lang.Object value)
-
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 java.lang.Comparable<N>>
-
doubleValue
public double doubleValue(long key)
- Specified by:
doubleValue
in interfaceAccess1D<N extends java.lang.Comparable<N>>
-
entrySet
public java.util.Set<java.util.Map.Entry<java.lang.Long,N>> entrySet()
-
firstKey
public java.lang.Long firstKey()
-
get
public N get(long key)
-
get
public N get(java.lang.Object key)
-
headMap
public LongToNumberMap<N> headMap(long toKey)
-
headMap
public LongToNumberMap<N> headMap(java.lang.Long toKey)
-
isEmpty
public boolean isEmpty()
-
keySet
public java.util.Set<java.lang.Long> keySet()
-
lastKey
public java.lang.Long lastKey()
-
mix
public double mix(long key, BinaryFunction<N> mixer, double addend)
- Specified by:
mix
in interfaceMutate1D.Mixable<N extends java.lang.Comparable<N>>
- Returns:
- The new/mixed value
-
mix
public N mix(long key, BinaryFunction<N> mixer, N addend)
- Specified by:
mix
in interfaceMutate1D.Mixable<N extends java.lang.Comparable<N>>
-
nonzeros
public SparseArray.NonzeroView<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.
-
put
public double put(long key, double value)
-
putAll
public void putAll(LongToNumberMap<N> m)
-
putAll
public void putAll(java.util.Map<? extends java.lang.Long,? extends N> m)
-
remove
public N remove(long key)
-
remove
public N remove(java.lang.Object key)
-
size
public int size()
Description copied from interface:Structure1D
The total number of elements in this structure.- Specified by:
size
in interfacejava.util.Map<java.lang.Long,N extends java.lang.Comparable<N>>
- Specified by:
size
in interfaceStructure1D
-
subMap
public LongToNumberMap<N> subMap(long fromKey, long toKey)
-
subMap
public LongToNumberMap<N> subMap(java.lang.Long fromKey, java.lang.Long toKey)
-
tailMap
public LongToNumberMap<N> tailMap(long fromKey)
-
tailMap
public LongToNumberMap<N> tailMap(java.lang.Long fromKey)
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
values
public NumberList<N> values()
-
values
public Access1D<N> 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. Any change in the underlying data structure (this map) will corrupt this method's output.
-
getStorage
SparseArray<N> getStorage()
-
-