Class TrieNodeMap<V>


  • public class TrieNodeMap<V>
    extends Object
    Custom implementation copied from TIntObjectHashMap but with less attribute to reduce the heap size in Trie.
    Source is copied from class hierarchy (with manually merging methods): The implementation is modified to keep the minimum attribute count on this Map because this TrieNodeMap will be created a lot of time ! Original source code
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected int _free
      the current number of free slots in the hash.
      protected int _maxSize
      The maximum number of elements allowed without allocating more space.
      int[] _set
      the set of ints
      protected int _size
      the current number of occupied slots in the hash.
      byte[] _states
      flags indicating whether each position in the hash is FREE, FULL, or REMOVED
      protected V[] _values
      the values of the map
      protected boolean consumeFreeSlot  
      static byte FREE
      flag indicating that a slot in the hashtable is available
      static byte FULL
      flag indicating that a slot in the hashtable is occupied
      static int oneInstanceCount  
      static byte REMOVED
      flag indicating that the value of a slot in the hashtable was deleted
    • Constructor Summary

      Constructors 
      Constructor Description
      TrieNodeMap()
      Creates a new THash instance with a prime capacity at or near the minimum needed to hold initialCapacity elements with load factor loadFactor without triggering a rehash.
    • Field Detail

      • FREE

        public static final byte FREE
        flag indicating that a slot in the hashtable is available
        See Also:
        Constant Field Values
      • FULL

        public static final byte FULL
        flag indicating that a slot in the hashtable is occupied
        See Also:
        Constant Field Values
      • REMOVED

        public static final byte REMOVED
        flag indicating that the value of a slot in the hashtable was deleted
        See Also:
        Constant Field Values
      • _size

        protected transient int _size
        the current number of occupied slots in the hash.
      • _free

        protected transient int _free
        the current number of free slots in the hash.
      • _set

        public transient int[] _set
        the set of ints
      • consumeFreeSlot

        protected boolean consumeFreeSlot
      • _maxSize

        protected int _maxSize
        The maximum number of elements allowed without allocating more space.
      • _states

        public transient byte[] _states
        flags indicating whether each position in the hash is FREE, FULL, or REMOVED
      • _values

        protected transient V[] _values
        the values of the map
      • oneInstanceCount

        public static int oneInstanceCount
    • Constructor Detail

      • TrieNodeMap

        public TrieNodeMap()
        Creates a new THash instance with a prime capacity at or near the minimum needed to hold initialCapacity elements with load factor loadFactor without triggering a rehash.
    • Method Detail

      • isEmpty

        public boolean isEmpty()
        Tells whether this set is currently holding any elements.
        Returns:
        a boolean value
      • size

        public int size()
        Returns the number of distinct elements in this collection.
        Returns:
        an int value
      • compact

        public void compact()
        Compresses the hashtable to the minimum prime size (as defined by PrimeFinder) that will hold all of the elements currently in the table. If you have done a lot of remove operations and plan to do a lot of queries or insertions or iteration, it is a good idea to invoke this method. Doing so will accomplish two things:
        1. You'll free memory allocated to the table but no longer needed because of the remove()s.
        2. You'll get better query/insert/iterator performance because there won't be any REMOVED slots to skip over when probing for indices in the table.
      • trimToSize

        public final void trimToSize()
        This simply calls compact. It is included for symmetry with other collection classes. Note that the name of this method is somewhat misleading (which is why we prefer compact) as the load factor may require capacity above and beyond the size of this collection.
        See Also:
        compact()
      • removeAt

        protected void removeAt​(int index)
        Delete the record at index. Reduces the size of the collection by one.
        Parameters:
        index - an int value
      • clear

        public void clear()
        Empties the collection.
      • setUp

        protected int setUp​(int initialCapacity)
        initializes the hashtable to a prime capacity which is at least initialCapacity + 1.
        Parameters:
        initialCapacity - an int value
        Returns:
        the actual capacity chosen
      • computeMaxSize

        protected void computeMaxSize​(int capacity)
        Computes the values of maxSize. There will always be at least one free slot required.
        Parameters:
        capacity - an int value
      • postInsertHook

        protected final void postInsertHook​(boolean usedFreeSlot)
        After an insert, this hook is called to adjust the size/free values of the set and to perform rehashing if necessary.
        Parameters:
        usedFreeSlot - the slot
      • calculateGrownCapacity

        protected int calculateGrownCapacity()
      • capacity

        public int capacity()
        Returns the capacity of the hash table. This is the true physical capacity, without adjusting for the load factor.
        Returns:
        the physical capacity of the hash table.
      • contains

        public boolean contains​(int val)
        Searches the set for val
        Parameters:
        val - an int value
        Returns:
        a boolean value
      • forEach

        public boolean forEach​(TIntProcedure procedure)
        Executes procedure for each element in the set.
        Parameters:
        procedure - a TObjectProcedure value
        Returns:
        false if the loop over the set terminated because the procedure returned false for some value.
      • index

        protected int index​(int val)
        Locates the index of val.
        Parameters:
        val - an int value
        Returns:
        the index of val or -1 if it isn't in the set.
      • insertKey

        protected int insertKey​(int val)
        Locates the index at which val can be inserted. if there is already a value equal()ing val in the set, returns that value as a negative integer.
        Parameters:
        val - an int value
        Returns:
        an int value
      • rehash

        protected void rehash​(int newCapacity)
      • containsKey

        public boolean containsKey​(int key)
      • containsValue

        public boolean containsValue​(Object val)
      • get

        public V get​(int key)
      • put

        public V put​(int key,
                     V value)
      • putIfAbsent

        public V putIfAbsent​(int key,
                             V value)
      • remove

        public V remove​(int key)
      • putAll

        public void putAll​(Map<? extends Integer,​? extends V> map)
      • keys

        public int[] keys()
      • keys

        public int[] keys​(int[] dest)
      • values

        public Object[] values()
      • values

        public V[] values​(V[] dest)
      • forEachKey

        public boolean forEachKey​(TIntProcedure procedure)
      • forEachValue

        public boolean forEachValue​(TObjectProcedure<? super V> procedure)
      • forEachValue

        public boolean forEachValue​(Consumer<? super V> procedure)
      • transformValues

        public void transformValues​(TObjectFunction<V,​V> function)
      • testAll

        public void testAll()