Class HashLongLongArray


  • public class HashLongLongArray
    extends java.lang.Object
    A Hash using primitive types instead or warped object The idea is to be able to add many long values for each key This could be implemented by simply doing HashMap > (but it would consume much more memory) Note: We call each 'long[]' a bucket WARNING: This collection does NOT allow elements to be deleted! But you can replace values.
    Author:
    pcingola
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static long EMPTY_VALUE  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean contains​(long key, long value)
      Return true if value is in the hash
      long[] getBucket​(long key)
      Return all values for a given key WARNING: Not all elements in a bucket are used.
      int getBucketLength​(long key)
      Return used length of a bucket
      int getLatestBucketLength()
      Get bucket length for latest bucket search WARNING: Obviously this is not a thread safe operation
      long[] keys()
      Return an array with all the keys to this hash
      void put​(long key, long value)
      Insert a pair How does it work? - bucket_number = hash.get( key ) - bu = bucket[ bucket_number ] - append 'value' to 'bu'
      boolean replace​(long key, long value, long newValue)
      Replace a value with newValue
      java.lang.String toString()  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Constructor Detail

      • HashLongLongArray

        public HashLongLongArray()
    • Method Detail

      • contains

        public boolean contains​(long key,
                                long value)
        Return true if value is in the hash
        Parameters:
        key -
        value -
      • getBucket

        public long[] getBucket​(long key)
        Return all values for a given key WARNING: Not all elements in a bucket are used. Use getBucketLength(key) to know how many elements are used
        Parameters:
        key -
        Returns:
        All associated values, or null if key is not found
      • getBucketLength

        public int getBucketLength​(long key)
        Return used length of a bucket
        Parameters:
        key -
        Returns:
      • getLatestBucketLength

        public int getLatestBucketLength()
        Get bucket length for latest bucket search WARNING: Obviously this is not a thread safe operation
        Returns:
      • keys

        public long[] keys()
        Return an array with all the keys to this hash
        Returns:
      • put

        public void put​(long key,
                        long value)
        Insert a pair How does it work? - bucket_number = hash.get( key ) - bu = bucket[ bucket_number ] - append 'value' to 'bu'
        Parameters:
        key -
        value -
      • replace

        public boolean replace​(long key,
                               long value,
                               long newValue)
        Replace a value with newValue
        Parameters:
        key -
        value -
      • toString

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