Top Description Fields Constructors Methods
com.google.common.collect

pack-priv Class CompactLinkedHashMap<K extends @Nullable Object, V extends @Nullable Object>

extends CompactHashMap<K extends @Nullable Object, V extends @Nullable Object>
Class Inheritance
Annotations
@J2ktIncompatible
@GwtIncompatible
@ElementTypesAreNonnullByDefault
Static Imports
java.util.Objects.requireNonNull

CompactLinkedHashMap is an implementation of a Map with insertion or LRU iteration order, maintained with a doubly linked list through the entries. All optional operations (put and remove) are supported. Null keys and values are supported.

containsKey(k), put(k, v) and remove(k) are all (expected and amortized) constant time operations. Expected in the hashtable sense (depends on the hash function doing a good job of distributing the elements to the buckets to a distribution not far from uniform), and amortized since some operations can trigger a hash table resize.

As compared with java.util.LinkedHashMap, this structure places significantly reduced load on the garbage collector by only using a constant number of internal objects.

This class should not be assumed to be universally superior to java.util.LinkedHashMap. Generally speaking, this class reduces object allocation and memory consumption at the price of moderately increased constant factors of CPU. Only use this class when there is a specific reason to prioritize memory over CPU.

Author
Louis Wasserman

Field Summary

Modifier and TypeField and Description
private final boolean
private static final int
private transient int
firstEntry

Pointer to the first node in the linked list, or ENDPOINT if there are no entries.

private transient int
lastEntry

Pointer to the last node in the linked list, or ENDPOINT if there are no entries.

pack-priv transient long[]
links

Contains the link pointers corresponding with the entries, in the range of [0, size()).

Inherited from com.google.common.collect.CompactHashMap:
entriesHASH_FLOODING_FPPkeysvalues

Constructor Summary

AccessConstructor and Description
pack-priv
pack-priv
CompactLinkedHashMap(int expectedSize)

pack-priv
CompactLinkedHashMap(int expectedSize, boolean accessOrder)

Method Summary

Modifier and TypeMethod and Description
pack-priv void
accessEntry(int index)

Overrides com.google.common.collect.CompactHashMap.accessEntry.

Mark an access of the specified entry.
pack-priv int
adjustAfterRemove(int indexBeforeRemove, int indexRemoved)

Overrides com.google.common.collect.CompactHashMap.adjustAfterRemove.

Updates the index an iterator is pointing to after a call to remove: returns the index of the entry that should be looked at after a removal on indexRemoved, with indexBeforeRemove as the index that *was* the next entry that would be looked at.
pack-priv int
allocArrays()

Overrides com.google.common.collect.CompactHashMap.allocArrays.

Handle lazy allocation of arrays.
public void
clear()

Overrides com.google.common.collect.CompactHashMap.clear.

Implements java.util.Map.clear.

Removes all of the mappings from this map (optional operation).
pack-priv Map<K, V>
public static <K extends @Nullable Object, V extends @Nullable Object> CompactLinkedHashMap<K, V>
create()

Hides com.google.common.collect.CompactHashMap.create.

Creates an empty CompactLinkedHashMap instance.
pack-priv Set<Map.Entry<K, V>>
pack-priv Map<K, V>
pack-priv Set<K>
pack-priv Collection<V>
public static <K extends @Nullable Object, V extends @Nullable Object> CompactLinkedHashMap<K, V>

Returns:

a new, empty CompactLinkedHashMap with enough capacity to hold expectedSize elements without resizing
createWithExpectedSize
(int
the number of elements you expect to add to the returned set
expectedSize
)

Hides com.google.common.collect.CompactHashMap.createWithExpectedSize.

Creates a CompactLinkedHashMap instance, with a high enough "initial capacity" that it should hold expectedSize elements without rebuilding internal data structures.
pack-priv int
private int
getPredecessor(int entry)

pack-priv int
pack-priv void
init(int expectedSize)

Overrides com.google.common.collect.CompactHashMap.init.

Pseudoconstructor for serialization support.
pack-priv void
insertEntry(int entryIndex, K key, V value, int hash, int mask)

Overrides com.google.common.collect.CompactHashMap.insertEntry.

Creates a fresh entry with the specified object at the specified position in the entry arrays.
pack-priv void
moveLastEntry(int dstIndex, int mask)

Overrides com.google.common.collect.CompactHashMap.moveLastEntry.

Moves the last entry in the entry array into dstIndex, and nulls out its old position.
pack-priv void
resizeEntries(int newCapacity)

Overrides com.google.common.collect.CompactHashMap.resizeEntries.

Resizes the internal entries array to the specified capacity, which may be greater or less than the current capacity.
private void
setPredecessor(int entry, int pred)

private void
setSucceeds(int pred, int succ)

private void
setSuccessor(int entry, int succ)

Inherited from com.google.common.collect.CompactHashMap:
containsKeycontainsValuedelegateOrNullentrySetentrySetIteratorforEachgetincrementModCountisEmptykeySetkeySetIteratorneedsAllocArraysputremovereplaceAllsizetrimToSizevaluesvaluesIterator

Field Detail

accessOrderback to summary
private final boolean accessOrder
ENDPOINTback to summary
private static final int ENDPOINT
firstEntryback to summary
private transient int firstEntry

Pointer to the first node in the linked list, or ENDPOINT if there are no entries.

lastEntryback to summary
private transient int lastEntry

Pointer to the last node in the linked list, or ENDPOINT if there are no entries.

Constructor Detail

CompactLinkedHashMapback to summary
pack-priv CompactLinkedHashMap()
CompactLinkedHashMapback to summary
pack-priv CompactLinkedHashMap(int expectedSize)
CompactLinkedHashMapback to summary
pack-priv CompactLinkedHashMap(int expectedSize, boolean accessOrder)

Method Detail

accessEntryback to summary
pack-priv void accessEntry(int index)

Overrides com.google.common.collect.CompactHashMap.accessEntry.

Doc from com.google.common.collect.CompactHashMap.accessEntry.

Mark an access of the specified entry. Used only in CompactLinkedHashMap for LRU ordering.

Annotations
@Override
adjustAfterRemoveback to summary
pack-priv int adjustAfterRemove(int indexBeforeRemove, int indexRemoved)

Overrides com.google.common.collect.CompactHashMap.adjustAfterRemove.

Doc from com.google.common.collect.CompactHashMap.adjustAfterRemove.

Updates the index an iterator is pointing to after a call to remove: returns the index of the entry that should be looked at after a removal on indexRemoved, with indexBeforeRemove as the index that *was* the next entry that would be looked at.

Annotations
@Override
allocArraysback to summary
pack-priv int allocArrays()

Overrides com.google.common.collect.CompactHashMap.allocArrays.

Doc from com.google.common.collect.CompactHashMap.allocArrays.

Handle lazy allocation of arrays.

Annotations
@Override
clearback to summary
public void clear()

Overrides com.google.common.collect.CompactHashMap.clear.

Implements java.util.Map.clear.

Doc from java.util.AbstractMap.clear.

Removes all of the mappings from this map (optional operation). The map will be empty after this call returns.

Annotations
@Override
convertToHashFloodingResistantImplementationback to summary
pack-priv Map<K, V> convertToHashFloodingResistantImplementation()

Overrides com.google.common.collect.CompactHashMap.convertToHashFloodingResistantImplementation.

Annotations
@Override
@CanIgnoreReturnValue
createback to summary
public static <K extends @Nullable Object, V extends @Nullable Object> CompactLinkedHashMap<K, V> create()

Hides com.google.common.collect.CompactHashMap.create.

Creates an empty CompactLinkedHashMap instance.

createEntrySetback to summary
pack-priv Set<Map.Entry<K, V>> createEntrySet()

Overrides com.google.common.collect.CompactHashMap.createEntrySet.

Annotations
@Override
createHashFloodingResistantDelegateback to summary
pack-priv Map<K, V> createHashFloodingResistantDelegate(int tableSize)

Overrides com.google.common.collect.CompactHashMap.createHashFloodingResistantDelegate.

Annotations
@Override
createKeySetback to summary
pack-priv Set<K> createKeySet()

Overrides com.google.common.collect.CompactHashMap.createKeySet.

Annotations
@Override
createValuesback to summary
pack-priv Collection<V> createValues()

Overrides com.google.common.collect.CompactHashMap.createValues.

Annotations
@Override
createWithExpectedSizeback to summary
public static <K extends @Nullable Object, V extends @Nullable Object> CompactLinkedHashMap<K, V> createWithExpectedSize(int expectedSize)

Hides com.google.common.collect.CompactHashMap.createWithExpectedSize.

Creates a CompactLinkedHashMap instance, with a high enough "initial capacity" that it should hold expectedSize elements without rebuilding internal data structures.

Parameters
expectedSize:int

the number of elements you expect to add to the returned set

Returns:CompactLinkedHashMap<K, V>

a new, empty CompactLinkedHashMap with enough capacity to hold expectedSize elements without resizing

Exceptions
IllegalArgumentException:
if expectedSize is negative
firstEntryIndexback to summary
pack-priv int firstEntryIndex()

Overrides com.google.common.collect.CompactHashMap.firstEntryIndex.

Annotations
@Override
getPredecessorback to summary
private int getPredecessor(int entry)
getSuccessorback to summary
pack-priv int getSuccessor(int entry)

Overrides com.google.common.collect.CompactHashMap.getSuccessor.

Annotations
@Override
initback to summary
pack-priv void init(int expectedSize)

Overrides com.google.common.collect.CompactHashMap.init.

Doc from com.google.common.collect.CompactHashMap.init.

Pseudoconstructor for serialization support.

Annotations
@Override
insertEntryback to summary
pack-priv void insertEntry(int entryIndex, K key, V value, int hash, int mask)

Overrides com.google.common.collect.CompactHashMap.insertEntry.

Doc from com.google.common.collect.CompactHashMap.insertEntry.

Creates a fresh entry with the specified object at the specified position in the entry arrays.

Annotations
@Override
moveLastEntryback to summary
pack-priv void moveLastEntry(int dstIndex, int mask)

Overrides com.google.common.collect.CompactHashMap.moveLastEntry.

Doc from com.google.common.collect.CompactHashMap.moveLastEntry.

Moves the last entry in the entry array into dstIndex, and nulls out its old position.

Annotations
@Override
resizeEntriesback to summary
pack-priv void resizeEntries(int newCapacity)

Overrides com.google.common.collect.CompactHashMap.resizeEntries.

Doc from com.google.common.collect.CompactHashMap.resizeEntries.

Resizes the internal entries array to the specified capacity, which may be greater or less than the current capacity.

Annotations
@Override
setPredecessorback to summary
private void setPredecessor(int entry, int pred)
setSucceedsback to summary
private void setSucceeds(int pred, int succ)
setSuccessorback to summary
private void setSuccessor(int entry, int succ)