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., 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.
| Modifier and Type | Field and Description |
|---|---|
| private final boolean | |
| private static final int | |
| private transient int | firstEntry
Pointer to the first node in the linked list, or |
| private transient int | lastEntry
Pointer to the last node in the linked list, or |
| pack-priv transient long[] | links
Contains the link pointers corresponding with the entries, in the range of [0, size()). |
| Access | Constructor and Description |
|---|---|
| pack-priv | |
| pack-priv | |
| pack-priv |
| Modifier and Type | Method and Description |
|---|---|
| pack-priv void | accessEntry(int index)
Overrides com. |
| pack-priv int | adjustAfterRemove(int indexBeforeRemove, int indexRemoved)
Overrides com. |
| pack-priv int | allocArrays()
Overrides com. |
| public void | clear()
Overrides com. Implements java. |
| pack-priv Map | |
| public static <K extends @Nullable Object, V extends @Nullable Object> CompactLinkedHashMap | create()
Hides com. CompactLinkedHashMap instance.
|
| pack-priv Set | |
| pack-priv Map | |
| pack-priv Set | |
| pack-priv Collection | |
| public static <K extends @Nullable Object, V extends @Nullable Object> CompactLinkedHashMap | Returns: a new, emptyCompactLinkedHashMap with enough capacity to hold expectedSize elements without resizingthe number of elements you expect to add to the returned set expectedSize)Hides com. CompactLinkedHashMap instance, with a high enough "initial capacity" that it
should hold expectedSize elements without rebuilding internal data structures.
|
| pack-priv int | |
| private int | |
| pack-priv int | |
| pack-priv void | init(int expectedSize)
Pseudoconstructor for serialization support.
|
| pack-priv void | insertEntry(int entryIndex, K key, V value, int hash, int mask)
Overrides com. |
| private long | |
| pack-priv void | moveLastEntry(int dstIndex, int mask)
Overrides com. dstIndex, and nulls out its old position.
|
| private long[] | |
| pack-priv void | resizeEntries(int newCapacity)
Overrides com. |
| private void | |
| private void | |
| private void | |
| private void |
| accessOrder | back to summary |
|---|---|
| private final boolean accessOrder | |
| ENDPOINT | back to summary |
|---|---|
| private static final int ENDPOINT | |
| firstEntry | back to summary |
|---|---|
| private transient int firstEntry Pointer to the first node in the linked list, or | |
| lastEntry | back to summary |
|---|---|
| private transient int lastEntry Pointer to the last node in the linked list, or | |
| links | back to summary |
|---|---|
| pack-priv transient long[] links Contains the link pointers corresponding with the entries, in the range of [0, size()). The high 32 bits of each long is the "prev" pointer, whereas the low 32 bits is the "succ" pointer (pointing to the next entry in the linked list). The pointers in [size(), entries.length) are all "null" (UNSET). A node with "prev" pointer equal to | |
| CompactLinkedHashMap | back to summary |
|---|---|
| pack-priv CompactLinkedHashMap() | |
| CompactLinkedHashMap | back to summary |
|---|---|
| pack-priv CompactLinkedHashMap(int expectedSize) | |
| CompactLinkedHashMap | back to summary |
|---|---|
| pack-priv CompactLinkedHashMap(int expectedSize, boolean accessOrder) | |
| accessEntry | back to summary |
|---|---|
| pack-priv void accessEntry(int index) Overrides com. Doc from com. Mark an access of the specified entry. Used only in
| |
| adjustAfterRemove | back to summary |
|---|---|
| pack-priv int adjustAfterRemove(int indexBeforeRemove, int indexRemoved) Overrides com. Doc from com. 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.
| |
| allocArrays | back to summary |
|---|---|
| pack-priv int allocArrays() Overrides com. Doc from com. Handle lazy allocation of arrays.
| |
| clear | back to summary |
|---|---|
| public void clear() Overrides com. Implements java. Doc from java. Removes all of the mappings from this map (optional operation). The map will be empty after this call returns.
| |
| convertToHashFloodingResistantImplementation | back to summary |
|---|---|
| pack-priv Map Overrides com.
| |
| create | back to summary |
|---|---|
| public static <K extends @Nullable Object, V extends @Nullable Object> CompactLinkedHashMap Hides com. Creates an empty | |
| createEntrySet | back to summary |
|---|---|
| pack-priv Set Overrides com.
| |
| createHashFloodingResistantDelegate | back to summary |
|---|---|
| pack-priv Map Overrides com.
| |
| createKeySet | back to summary |
|---|---|
| pack-priv Set Overrides com.
| |
| createValues | back to summary |
|---|---|
| pack-priv Collection Overrides com.
| |
| createWithExpectedSize | back to summary |
|---|---|
| public static <K extends @Nullable Object, V extends @Nullable Object> CompactLinkedHashMap Hides com. Creates a
| |
| firstEntryIndex | back to summary |
|---|---|
| pack-priv int firstEntryIndex() Overrides com.
| |
| getPredecessor | back to summary |
|---|---|
| private int getPredecessor(int entry) | |
| getSuccessor | back to summary |
|---|---|
| pack-priv int getSuccessor(int entry) Overrides com.
| |
| init | back to summary |
|---|---|
| pack-priv void init(int expectedSize) Overrides com. Doc from com. Pseudoconstructor for serialization support.
| |
| insertEntry | back to summary |
|---|---|
| pack-priv void insertEntry(int entryIndex, K key, V value, int hash, int mask) Overrides com. Doc from com. Creates a fresh entry with the specified object at the specified position in the entry arrays.
| |
| link | back to summary |
|---|---|
| private long link(int i) | |
| moveLastEntry | back to summary |
|---|---|
| pack-priv void moveLastEntry(int dstIndex, int mask) Overrides com. Doc from com. Moves the last entry in the entry array into
| |
| requireLinks | back to summary |
|---|---|
| private long[] requireLinks() | |
| resizeEntries | back to summary |
|---|---|
| pack-priv void resizeEntries(int newCapacity) Overrides com. Doc from com. Resizes the internal entries array to the specified capacity, which may be greater or less than the current capacity.
| |
| setLink | back to summary |
|---|---|
| private void setLink(int i, long value) | |
| setPredecessor | back to summary |
|---|---|
| private void setPredecessor(int entry, int pred) | |
| setSucceeds | back to summary |
|---|---|
| private void setSucceeds(int pred, int succ) | |
| setSuccessor | back to summary |
|---|---|
| private void setSuccessor(int entry, int succ) | |