Class Reference2ReferenceLinkedOpenHashMap<K,​V>

  • All Implemented Interfaces:
    Function<K,​V>, Hash, Reference2ReferenceFunction<K,​V>, Reference2ReferenceMap<K,​V>, Reference2ReferenceSortedMap<K,​V>, Serializable, Cloneable, Function<K,​V>, Map<K,​V>, SortedMap<K,​V>

    public class Reference2ReferenceLinkedOpenHashMap<K,​V>
    extends AbstractReference2ReferenceSortedMap<K,​V>
    implements Serializable, Cloneable, Hash
    A type-specific linked hash map with with a fast, small-footprint implementation.

    Instances of this class use a hash table to represent a map. The table is filled up to a specified load factor, and then doubled in size to accommodate new entries. If the table is emptied below one fourth of the load factor, it is halved in size; however, the table is never reduced to a size smaller than that at creation time: this approach makes it possible to create maps with a large capacity in which insertions and deletions do not cause immediately rehashing. Moreover, halving is not performed when deleting entries from an iterator, as it would interfere with the iteration process.

    Note that clear() does not modify the hash table size. Rather, a family of trimming methods lets you control the size of the table; this is particularly useful if you reuse instances of this class.

    Iterators generated by this map will enumerate pairs in the same order in which they have been added to the map (addition of pairs whose key is already present in the map does not change the iteration order). Note that this order has nothing in common with the natural order of the keys. The order is kept by means of a doubly linked list, represented via an array of longs parallel to the table.

    This class implements the interface of a sorted map, so to allow easy access of the iteration order: for instance, you can get the first key in iteration order with firstKey() without having to create an iterator; however, this class partially violates the SortedMap contract because all submap methods throw an exception and comparator() returns always null.

    Additional methods, such as getAndMoveToFirst(), make it easy to use instances of this class as a cache (e.g., with LRU policy).

    The iterators provided by the views of this class using are type-specific list iterators, and can be started at any element which is a key of the map, or a NoSuchElementException exception will be thrown. If, however, the provided element is not the first or last key in the map, the first access to the list index will require linear time, as in the worst case the entire key set must be scanned in iteration order to retrieve the positional index of the starting key. If you use just the methods of a type-specific BidirectionalIterator, however, all operations will be performed in constant time.

    See Also:
    Hash, HashCommon, Serialized Form
    • Constructor Detail

      • Reference2ReferenceLinkedOpenHashMap

        public Reference2ReferenceLinkedOpenHashMap​(int expected,
                                                    float f)
        Creates a new hash map.

        The actual table size will be the least power of two greater than expected/f.

        Parameters:
        expected - the expected number of elements in the hash map.
        f - the load factor.
      • Reference2ReferenceLinkedOpenHashMap

        public Reference2ReferenceLinkedOpenHashMap​(int expected)
        Creates a new hash map with Hash.DEFAULT_LOAD_FACTOR as load factor.
        Parameters:
        expected - the expected number of elements in the hash map.
      • Reference2ReferenceLinkedOpenHashMap

        public Reference2ReferenceLinkedOpenHashMap​(Map<? extends K,​? extends V> m,
                                                    float f)
        Creates a new hash map copying a given one.
        Parameters:
        m - a Map to be copied into the new hash map.
        f - the load factor.
      • Reference2ReferenceLinkedOpenHashMap

        public Reference2ReferenceLinkedOpenHashMap​(Map<? extends K,​? extends V> m)
        Creates a new hash map with Hash.DEFAULT_LOAD_FACTOR as load factor copying a given one.
        Parameters:
        m - a Map to be copied into the new hash map.
      • Reference2ReferenceLinkedOpenHashMap

        public Reference2ReferenceLinkedOpenHashMap​(Reference2ReferenceMap<K,​V> m,
                                                    float f)
        Creates a new hash map copying a given type-specific one.
        Parameters:
        m - a type-specific map to be copied into the new hash map.
        f - the load factor.
      • Reference2ReferenceLinkedOpenHashMap

        public Reference2ReferenceLinkedOpenHashMap​(Reference2ReferenceMap<K,​V> m)
        Creates a new hash map with Hash.DEFAULT_LOAD_FACTOR as load factor copying a given type-specific one.
        Parameters:
        m - a type-specific map to be copied into the new hash map.
      • Reference2ReferenceLinkedOpenHashMap

        public Reference2ReferenceLinkedOpenHashMap​(K[] k,
                                                    V[] v,
                                                    float f)
        Creates a new hash map using the elements of two parallel arrays.
        Parameters:
        k - the array of keys of the new hash map.
        v - the array of corresponding values in the new hash map.
        f - the load factor.
        Throws:
        IllegalArgumentException - if k and v have different lengths.
      • Reference2ReferenceLinkedOpenHashMap

        public Reference2ReferenceLinkedOpenHashMap​(K[] k,
                                                    V[] v)
        Creates a new hash map with Hash.DEFAULT_LOAD_FACTOR as load factor using the elements of two parallel arrays.
        Parameters:
        k - the array of keys of the new hash map.
        v - the array of corresponding values in the new hash map.
        Throws:
        IllegalArgumentException - if k and v have different lengths.