Class LongToNumberMap<N extends java.lang.Comparable<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>
    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.
    • 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
    • Method Detail

      • 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()
        Specified by:
        clear in interface java.util.Map<java.lang.Long,​N extends java.lang.Comparable<N>>
      • comparator

        public java.util.Comparator<? super java.lang.Long> comparator()
        Specified by:
        comparator in interface java.util.SortedMap<java.lang.Long,​N extends java.lang.Comparable<N>>
      • containsKey

        public boolean containsKey​(long key)
      • containsKey

        public boolean containsKey​(java.lang.Object key)
        Specified by:
        containsKey in interface java.util.Map<java.lang.Long,​N extends java.lang.Comparable<N>>
      • containsValue

        public boolean containsValue​(double value)
      • containsValue

        public boolean containsValue​(java.lang.Object value)
        Specified by:
        containsValue in interface java.util.Map<java.lang.Long,​N extends java.lang.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 interface Structure1D
      • doubleValue

        public double doubleValue​(int key)
        Specified by:
        doubleValue in interface Access1D<N extends java.lang.Comparable<N>>
      • doubleValue

        public double doubleValue​(long key)
        Specified by:
        doubleValue in interface Access1D<N extends java.lang.Comparable<N>>
      • entrySet

        public java.util.Set<java.util.Map.Entry<java.lang.Long,​N>> entrySet()
        Specified by:
        entrySet in interface java.util.Map<java.lang.Long,​N extends java.lang.Comparable<N>>
        Specified by:
        entrySet in interface java.util.SortedMap<java.lang.Long,​N extends java.lang.Comparable<N>>
      • firstKey

        public java.lang.Long firstKey()
        Specified by:
        firstKey in interface java.util.SortedMap<java.lang.Long,​N extends java.lang.Comparable<N>>
      • get

        public N get​(long key)
        Specified by:
        get in interface Access1D<N extends java.lang.Comparable<N>>
      • get

        public N get​(java.lang.Object key)
        Specified by:
        get in interface java.util.Map<java.lang.Long,​N extends java.lang.Comparable<N>>
      • headMap

        public LongToNumberMap<N> headMap​(java.lang.Long toKey)
        Specified by:
        headMap in interface java.util.SortedMap<java.lang.Long,​N extends java.lang.Comparable<N>>
      • isEmpty

        public boolean isEmpty()
        Specified by:
        isEmpty in interface java.util.Map<java.lang.Long,​N extends java.lang.Comparable<N>>
      • keySet

        public java.util.Set<java.lang.Long> keySet()
        Specified by:
        keySet in interface java.util.Map<java.lang.Long,​N extends java.lang.Comparable<N>>
        Specified by:
        keySet in interface java.util.SortedMap<java.lang.Long,​N extends java.lang.Comparable<N>>
      • lastKey

        public java.lang.Long lastKey()
        Specified by:
        lastKey in interface java.util.SortedMap<java.lang.Long,​N extends java.lang.Comparable<N>>
      • mix

        public double mix​(long key,
                          BinaryFunction<N> mixer,
                          double addend)
        Specified by:
        mix in interface Mutate1D.Mixable<N extends java.lang.Comparable<N>>
        Returns:
        The new/mixed value
      • nonzeros

        public SparseArray.NonzeroView<N> nonzeros()
        Description copied from interface: Access1D
        Similar to Access1D.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 the Access1D.nonzeros() and Access1D.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 interface Access1D<N extends java.lang.Comparable<N>>
      • put

        public double put​(long key,
                          double value)
      • put

        public N put​(long key,
                     N value)
      • put

        public N put​(java.lang.Long key,
                     N value)
        Specified by:
        put in interface java.util.Map<java.lang.Long,​N extends java.lang.Comparable<N>>
      • putAll

        public void putAll​(java.util.Map<? extends java.lang.Long,​? extends N> m)
        Specified by:
        putAll in interface java.util.Map<java.lang.Long,​N extends java.lang.Comparable<N>>
      • remove

        public N remove​(long key)
      • remove

        public N remove​(java.lang.Object key)
        Specified by:
        remove in interface java.util.Map<java.lang.Long,​N extends java.lang.Comparable<N>>
      • size

        public int size()
        Description copied from interface: Structure1D
        The total number of elements in this structure.
        Specified by:
        size in interface java.util.Map<java.lang.Long,​N extends java.lang.Comparable<N>>
        Specified by:
        size in interface Structure1D
      • subMap

        public LongToNumberMap<N> subMap​(java.lang.Long fromKey,
                                         java.lang.Long toKey)
        Specified by:
        subMap in interface java.util.SortedMap<java.lang.Long,​N extends java.lang.Comparable<N>>
      • tailMap

        public LongToNumberMap<N> tailMap​(java.lang.Long fromKey)
        Specified by:
        tailMap in interface java.util.SortedMap<java.lang.Long,​N extends java.lang.Comparable<N>>
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • values

        public NumberList<N> values()
        Specified by:
        values in interface java.util.Map<java.lang.Long,​N extends java.lang.Comparable<N>>
        Specified by:
        values in interface java.util.SortedMap<java.lang.Long,​N extends java.lang.Comparable<N>>
      • values

        public Access1D<N> values​(long fromKey,
                                  long toKey)
        Should return the same elements/values as first calling subMap(Long, Long) and then values() but this method does not create any copies. Any change in the underlying data structure (this map) will corrupt this method's output.