Class Long2LongHashMap

  • All Implemented Interfaces:
    java.util.Map<java.lang.Long,​java.lang.Long>

    public class Long2LongHashMap
    extends java.lang.Object
    implements java.util.Map<java.lang.Long,​java.lang.Long>
    An open-addressing with linear probing hash map specialised for primitive key and value pairs.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods 
      Modifier and Type Method Description
      int capacity()
      Get the total capacity for the map to which the load factor will be a fraction of.
      private void capacity​(int newCapacity)  
      void clear()
      void compact()
      Compact the backing arrays by rehashing with a capacity just larger than current size and giving consideration to the load factor.
      private void compactChain​(int deleteKeyIndex)  
      long compute​(long key, java.util.function.LongBinaryOperator remappingFunction)
      Primitive specialised version of Map.compute(Object, BiFunction).
      long computeIfAbsent​(long key, java.util.function.LongUnaryOperator mappingFunction)
      Primitive specialised version of Map.computeIfAbsent(Object, Function).
      long computeIfPresent​(long key, java.util.function.LongBinaryOperator remappingFunction)
      Primitive specialised version of Map.computeIfPresent(Object, BiFunction).
      boolean containsKey​(long key)
      Long primitive specialised containsKey.
      boolean containsKey​(java.lang.Object key)
      boolean containsValue​(long value)
      Does the map contain the value.
      boolean containsValue​(java.lang.Object value)
      Long2LongHashMap.EntrySet entrySet()
      boolean equals​(java.lang.Object o)
      void forEach​(java.util.function.BiConsumer<? super java.lang.Long,​? super java.lang.Long> action)
      void forEachLong​(LongLongConsumer consumer)
      Primitive specialised forEach implementation.
      long get​(long key)
      Get a value using provided key avoiding boxing.
      java.lang.Long get​(java.lang.Object key)
      long getOrDefault​(long key, long defaultValue)
      Returns the value to which the specified key is mapped, or defaultValue if this map contains no mapping for the key.
      int hashCode()
      private void increaseCapacity()  
      boolean isEmpty()
      Long2LongHashMap.KeySet keySet()
      float loadFactor()
      Get the load factor applied for resize operations.
      void longForEach​(LongLongConsumer consumer)
      Deprecated.
      long maxValue()
      Get the maximum value stored in the map.
      long merge​(long key, long value, LongLongFunction remappingFunction)
      Primitive specialised version of Map.merge(Object, Object, BiFunction).
      long minValue()
      Get the minimum value stored in the map.
      long missingValue()
      The value to be used as a null marker in the map.
      private static int next​(int index, int mask)  
      long put​(long key, long value)
      Put a key value pair in the map.
      java.lang.Long put​(java.lang.Long key, java.lang.Long value)
      void putAll​(java.util.Map<? extends java.lang.Long,​? extends java.lang.Long> map)
      void putAll​(Long2LongHashMap map)
      Put all values from the given map longo this map without allocation.
      long putIfAbsent​(long key, long value)
      Primitive specialised version of Map.putIfAbsent(Object, Object) method.
      java.lang.Long putIfAbsent​(java.lang.Long key, java.lang.Long value)
      private void rehash​(int newCapacity)  
      long remove​(long key)
      Remove value from the map using given key avoiding boxing.
      boolean remove​(long key, long value)
      Primitive specialised version of Map.remove(Object, Object).
      java.lang.Long remove​(java.lang.Object key)
      boolean remove​(java.lang.Object key, java.lang.Object value)
      long replace​(long key, long value)
      Primitive specialised version of Map.replace(Object, Object).
      boolean replace​(long key, long oldValue, long newValue)
      Primitive specialised version of Map.replace(Object, Object, Object).
      java.lang.Long replace​(java.lang.Long key, java.lang.Long value)
      boolean replace​(java.lang.Long key, java.lang.Long oldValue, java.lang.Long newValue)
      void replaceAll​(java.util.function.BiFunction<? super java.lang.Long,​? super java.lang.Long,​? extends java.lang.Long> function)
      void replaceAllLong​(LongLongFunction function)
      Primitive specialised version of Map.replaceAll(BiFunction).
      int resizeThreshold()
      Get the actual threshold which when reached the map will resize.
      int size()
      java.lang.String toString()
      private java.lang.Long valOrNull​(long value)  
      Long2LongHashMap.ValueCollection values()
      • Methods inherited from class java.lang.Object

        clone, finalize, getClass, notify, notifyAll, wait, wait, wait
      • Methods inherited from interface java.util.Map

        compute, computeIfAbsent, computeIfPresent, getOrDefault, merge
    • Constructor Detail

      • Long2LongHashMap

        public Long2LongHashMap​(long missingValue)
        Parameters:
        missingValue - for the map that represents null.
      • Long2LongHashMap

        public Long2LongHashMap​(int initialCapacity,
                                float loadFactor,
                                long missingValue)
        Parameters:
        initialCapacity - for the map to override MIN_CAPACITY
        loadFactor - for the map to override Hashing.DEFAULT_LOAD_FACTOR.
        missingValue - for the map that represents null.
      • Long2LongHashMap

        public Long2LongHashMap​(int initialCapacity,
                                float loadFactor,
                                long missingValue,
                                boolean shouldAvoidAllocation)
        Parameters:
        initialCapacity - for the map to override MIN_CAPACITY
        loadFactor - for the map to override Hashing.DEFAULT_LOAD_FACTOR.
        missingValue - for the map that represents null.
        shouldAvoidAllocation - should allocation be avoided by caching iterators and map entries.
      • Long2LongHashMap

        public Long2LongHashMap​(Long2LongHashMap mapToCopy)
        Copy construct a new map from an existing one.
        Parameters:
        mapToCopy - for construction.
    • Method Detail

      • missingValue

        public long missingValue()
        The value to be used as a null marker in the map.
        Returns:
        value to be used as a null marker in the map.
      • loadFactor

        public float loadFactor()
        Get the load factor applied for resize operations.
        Returns:
        the load factor applied for resize operations.
      • capacity

        public int capacity()
        Get the total capacity for the map to which the load factor will be a fraction of.
        Returns:
        the total capacity for the map.
      • resizeThreshold

        public int resizeThreshold()
        Get the actual threshold which when reached the map will resize. This is a function of the current capacity and load factor.
        Returns:
        the threshold when the map will resize.
      • size

        public int size()
        Specified by:
        size in interface java.util.Map<java.lang.Long,​java.lang.Long>
      • isEmpty

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

        public long getOrDefault​(long key,
                                 long defaultValue)
        Returns the value to which the specified key is mapped, or defaultValue if this map contains no mapping for the key.
        Parameters:
        key - whose associated value is to be returned.
        defaultValue - to be returned if there is no value in the map for a given key.
        Returns:
        the value to which the specified key is mapped, or defaultValue if this map contains no mapping for the key.
      • get

        public long get​(long key)
        Get a value using provided key avoiding boxing.
        Parameters:
        key - lookup key.
        Returns:
        value associated with the key or missingValue() if key is not found in the map.
      • put

        public long put​(long key,
                        long value)
        Put a key value pair in the map.
        Parameters:
        key - lookup key
        value - new value, must not be missingValue()
        Returns:
        previous value associated with the key, or missingValue() if none found
        Throws:
        java.lang.IllegalArgumentException - if value is missingValue()
      • putIfAbsent

        public long putIfAbsent​(long key,
                                long value)
        Primitive specialised version of Map.putIfAbsent(Object, Object) method.
        Parameters:
        key - key with which the specified value is to be associated
        value - value to be associated with the specified key
        Returns:
        the previous value associated with the specified key, or missingValue() if there was no mapping for the key.
        Throws:
        java.lang.IllegalArgumentException - if value is missingValue()
      • increaseCapacity

        private void increaseCapacity()
      • rehash

        private void rehash​(int newCapacity)
      • forEachLong

        public void forEachLong​(LongLongConsumer consumer)
        Primitive specialised forEach implementation.

        NB: Renamed from forEach to avoid overloading on parameter types of lambda expression, which doesn't play well with type inference in lambda expressions.

        Parameters:
        consumer - a callback called for each key/value pair in the map.
      • containsKey

        public boolean containsKey​(long key)
        Long primitive specialised containsKey.
        Parameters:
        key - the key to check.
        Returns:
        true if the map contains key as a key, false otherwise.
      • containsValue

        public boolean containsValue​(long value)
        Does the map contain the value.
        Parameters:
        value - to be tested against contained values.
        Returns:
        true if contained otherwise value.
      • clear

        public void clear()
        Specified by:
        clear in interface java.util.Map<java.lang.Long,​java.lang.Long>
      • compact

        public void compact()
        Compact the backing arrays by rehashing with a capacity just larger than current size and giving consideration to the load factor.
      • computeIfAbsent

        public long computeIfAbsent​(long key,
                                    java.util.function.LongUnaryOperator mappingFunction)
        Primitive specialised version of Map.computeIfAbsent(Object, Function).
        Parameters:
        key - to search on.
        mappingFunction - to provide a value if the get returns null.
        Returns:
        the value if found otherwise the missing value.
      • computeIfPresent

        public long computeIfPresent​(long key,
                                     java.util.function.LongBinaryOperator remappingFunction)
        Primitive specialised version of Map.computeIfPresent(Object, BiFunction).
        Parameters:
        key - to search on.
        remappingFunction - to compute a value if a mapping is found.
        Returns:
        the updated value if a mapping was found, otherwise the missing value.
      • compute

        public long compute​(long key,
                            java.util.function.LongBinaryOperator remappingFunction)
        Primitive specialised version of Map.compute(Object, BiFunction).
        Parameters:
        key - to search on.
        remappingFunction - to compute a value.
        Returns:
        the updated value.
      • get

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

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

        public void forEach​(java.util.function.BiConsumer<? super java.lang.Long,​? super java.lang.Long> action)
        Specified by:
        forEach in interface java.util.Map<java.lang.Long,​java.lang.Long>
      • containsKey

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

        public boolean containsValue​(java.lang.Object value)
        Specified by:
        containsValue in interface java.util.Map<java.lang.Long,​java.lang.Long>
      • putAll

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

        public void putAll​(Long2LongHashMap map)
        Put all values from the given map longo this map without allocation.
        Parameters:
        map - whose value are to be added.
      • putIfAbsent

        public java.lang.Long putIfAbsent​(java.lang.Long key,
                                          java.lang.Long value)
        Specified by:
        putIfAbsent in interface java.util.Map<java.lang.Long,​java.lang.Long>
      • replace

        public java.lang.Long replace​(java.lang.Long key,
                                      java.lang.Long value)
        Specified by:
        replace in interface java.util.Map<java.lang.Long,​java.lang.Long>
      • replace

        public boolean replace​(java.lang.Long key,
                               java.lang.Long oldValue,
                               java.lang.Long newValue)
        Specified by:
        replace in interface java.util.Map<java.lang.Long,​java.lang.Long>
      • replaceAll

        public void replaceAll​(java.util.function.BiFunction<? super java.lang.Long,​? super java.lang.Long,​? extends java.lang.Long> function)
        Specified by:
        replaceAll in interface java.util.Map<java.lang.Long,​java.lang.Long>
      • keySet

        public Long2LongHashMap.KeySet keySet()
        Specified by:
        keySet in interface java.util.Map<java.lang.Long,​java.lang.Long>
      • entrySet

        public Long2LongHashMap.EntrySet entrySet()
        Specified by:
        entrySet in interface java.util.Map<java.lang.Long,​java.lang.Long>
      • remove

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

        public boolean remove​(java.lang.Object key,
                              java.lang.Object value)
        Specified by:
        remove in interface java.util.Map<java.lang.Long,​java.lang.Long>
      • remove

        public long remove​(long key)
        Remove value from the map using given key avoiding boxing.
        Parameters:
        key - whose mapping is to be removed from the map.
        Returns:
        removed value or missingValue() if key was not found in the map.
      • remove

        public boolean remove​(long key,
                              long value)
        Primitive specialised version of Map.remove(Object, Object).
        Parameters:
        key - with which the specified value is associated.
        value - expected to be associated with the specified key.
        Returns:
        true if the value was removed.
      • merge

        public long merge​(long key,
                          long value,
                          LongLongFunction remappingFunction)
        Primitive specialised version of Map.merge(Object, Object, BiFunction).
        Parameters:
        key - with which the resulting value is to be associated.
        value - to be merged with the existing value associated with the key or, if no existing value or a null value is associated with the key, to be associated with the key.
        remappingFunction - the function to recompute a value if present.
        Returns:
        the new value associated with the specified key, or missingValue() if no value is associated with the key as the result of this operation.
      • compactChain

        private void compactChain​(int deleteKeyIndex)
      • minValue

        public long minValue()
        Get the minimum value stored in the map. If the map is empty then it will return missingValue().
        Returns:
        the minimum value stored in the map.
      • maxValue

        public long maxValue()
        Get the maximum value stored in the map. If the map is empty then it will return missingValue().
        Returns:
        the maximum value stored in the map.
      • toString

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

        public long replace​(long key,
                            long value)
        Primitive specialised version of Map.replace(Object, Object).
        Parameters:
        key - key with which the specified value is associated.
        value - value to be associated with the specified key.
        Returns:
        the previous value associated with the specified key, or missingValue() if there was no mapping for the key.
      • replace

        public boolean replace​(long key,
                               long oldValue,
                               long newValue)
        Primitive specialised version of Map.replace(Object, Object, Object).
        Parameters:
        key - key with which the specified value is associated.
        oldValue - value expected to be associated with the specified key.
        newValue - value to be associated with the specified key.
        Returns:
        true if the value was replaced.
      • replaceAllLong

        public void replaceAllLong​(LongLongFunction function)
        Primitive specialised version of Map.replaceAll(BiFunction).

        NB: Renamed from replaceAll to avoid overloading on parameter types of lambda expression, which doesn't play well with type inference in lambda expressions.

        Parameters:
        function - to apply to each entry.
      • equals

        public boolean equals​(java.lang.Object o)
        Specified by:
        equals in interface java.util.Map<java.lang.Long,​java.lang.Long>
        Overrides:
        equals in class java.lang.Object
      • hashCode

        public int hashCode()
        Specified by:
        hashCode in interface java.util.Map<java.lang.Long,​java.lang.Long>
        Overrides:
        hashCode in class java.lang.Object
      • next

        private static int next​(int index,
                                int mask)
      • capacity

        private void capacity​(int newCapacity)
      • valOrNull

        private java.lang.Long valOrNull​(long value)