Class RegularImmutableMap<K,​V>

  • All Implemented Interfaces:
    java.io.Serializable, java.util.Map<K,​V>

    final class RegularImmutableMap<K,​V>
    extends ImmutableMap<K,​V>
    Implementation of ImmutableMap with two or more entries.
    • Field Detail

      • EMPTY

        static final ImmutableMap<java.lang.Object,​java.lang.Object> EMPTY
      • MAX_LOAD_FACTOR

        static final double MAX_LOAD_FACTOR
        Closed addressing tends to perform well even with high load factors. Being conservative here ensures that the table is still likely to be relatively sparse (hence it misses fast) while saving space.
        See Also:
        Constant Field Values
      • HASH_FLOODING_FPP

        static final double HASH_FLOODING_FPP
        Maximum allowed false positive probability of detecting a hash flooding attack given random input.
        See Also:
        Constant Field Values
      • MAX_HASH_BUCKET_LENGTH

        static final int MAX_HASH_BUCKET_LENGTH
        Maximum allowed length of a hash table bucket before falling back to a j.u.HashMap based implementation. Experimentally determined.
        See Also:
        Constant Field Values
      • entries

        final transient java.util.Map.Entry<K,​V>[] entries
      • mask

        private final transient int mask
    • Constructor Detail

      • RegularImmutableMap

        private RegularImmutableMap​(java.util.Map.Entry<K,​V>[] entries,
                                    @CheckForNull
                                    ImmutableMapEntry<K,​V>[] table,
                                    int mask)
    • Method Detail

      • fromEntries

        static <K,​V> ImmutableMap<K,​V> fromEntries​(java.util.Map.Entry<K,​V>... entries)
      • fromEntryArray

        static <K,​V> ImmutableMap<K,​V> fromEntryArray​(int n,
                                                                  java.util.Map.Entry<K,​V>[] entryArray)
        Creates an ImmutableMap from the first n entries in entryArray. This implementation may replace the entries in entryArray with its own entry objects (though they will have the same key/value contents), and may take ownership of entryArray.
      • makeImmutable

        static <K,​V> ImmutableMapEntry<K,​V> makeImmutable​(java.util.Map.Entry<K,​V> entry,
                                                                      K key,
                                                                      V value)
        Makes an entry usable internally by a new ImmutableMap without rereading its contents.
      • makeImmutable

        static <K,​V> ImmutableMapEntry<K,​V> makeImmutable​(java.util.Map.Entry<K,​V> entry)
        Makes an entry usable internally by a new ImmutableMap.
      • checkNoConflictInKeyBucket

        static int checkNoConflictInKeyBucket​(java.lang.Object key,
                                              java.util.Map.Entry<?,​?> entry,
                                              @CheckForNull
                                              ImmutableMapEntry<?,​?> keyBucketHead)
        Returns:
        number of entries in this bucket
        Throws:
        java.lang.IllegalArgumentException - if another entry in the bucket has the same key
      • get

        @CheckForNull
        public V get​(@CheckForNull
                     java.lang.Object key)
        Specified by:
        get in interface java.util.Map<K,​V>
        Specified by:
        get in class ImmutableMap<K,​V>
      • get

        @CheckForNull
        static <V> V get​(@CheckForNull
                         java.lang.Object key,
                         @CheckForNull
                         ImmutableMapEntry<?,​V>[] keyTable,
                         int mask)
      • forEach

        public void forEach​(java.util.function.BiConsumer<? super K,​? super V> action)
      • size

        public int size()