Package com.tangosol.util
Class OpenHashMap<K,V>
- java.lang.Object
-
- com.tangosol.util.Base
-
- com.tangosol.util.AbstractKeyBasedMap<K,V>
-
- com.tangosol.util.OpenHashMap<K,V>
-
- All Implemented Interfaces:
Map<K,V>
public class OpenHashMap<K,V> extends AbstractKeyBasedMap<K,V>
An implementation ofMap
that is optimized for memory footprint. Specifically, instead of instantiating an "Entry" object for each element (as theHashMap
does, which references those entries in a linked list fashion with the head of the linked list stored in the hash bucket array, this implementation stores its elements using an open hashing algorithm, i.e. the keys are stored directly in the hash bucket array and the values are stored in a corresponding values array.This implementation is explicitly NOT thread-safe.
- Since:
- 12.2.1
- Author:
- cp 2013.01.30
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description class
OpenHashMap.EntrySet
A set of entries backed by this map.protected class
OpenHashMap.KeySet
A set of keys backed by this map.-
Nested classes/interfaces inherited from class com.tangosol.util.AbstractKeyBasedMap
AbstractKeyBasedMap.DeferredCacheEvent<K,V>, AbstractKeyBasedMap.ValuesCollection
-
Nested classes/interfaces inherited from class com.tangosol.util.Base
Base.LoggingWriter
-
-
Constructor Summary
Constructors Constructor Description OpenHashMap()
Default constructor.OpenHashMap(int initialCapacity)
Create a OpenHashMap pre-sized to hold the specified number of entries.OpenHashMap(Map map)
Create a OpenHashMap that will initially contain the contents of the passed Map.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
clear()
Clear all key/value mappings.boolean
containsKey(Object oKey)
Returns true if this map contains a mapping for the specified key.V
get(Object oKey)
Returns the value to which this map maps the specified key.protected Set
instantiateEntrySet()
Factory pattern: Create a Set that represents the entries in the Map.protected Set
instantiateKeySet()
Factory pattern: Create a Set that represents the keys in the Mapprotected Iterator
iterateKeys()
Create an iterator over the keys in this Map.Object
put(Object oKey, Object oValue)
Associates the specified value with the specified key in this map.V
remove(Object oKey)
Removes the mapping for this key from this map if present.int
size()
Returns the number of key-value mappings in this map.-
Methods inherited from class com.tangosol.util.AbstractKeyBasedMap
clone, containsValue, entrySet, equals, getAll, hashCode, instantiateValues, isEmpty, keySet, putAll, removeBlind, toString, values
-
Methods inherited from class com.tangosol.util.Base
azzert, azzert, azzert, azzertFailed, breakLines, breakLines, capitalize, checkNotEmpty, checkNotNull, checkRange, computeSafeWaitTime, decimalValue, dup, dup, ensureBigDecimal, ensureClassLoader, ensureRuntimeException, ensureRuntimeException, equals, equalsDeep, err, err, err, err, err, escape, formatDateTime, getCallerStackFrame, getCommonMonitor, getCommonMonitor, getCommonMonitor, getContextClassLoader, getContextClassLoader, getDeepMessage, getErr, getLastSafeTimeMillis, getLog, getMaxDecDigits, getMaxHexDigits, getOriginalException, getOut, getProcessRandom, getRandom, getRandomBinary, getRandomBinary, getRandomString, getSafeTimeMillis, getStackFrame, getStackFrames, getStackTrace, getStackTrace, getStackTrace, getThreadFactory, getTimeZone, getUpTimeMillis, hashCode, hexValue, indentString, indentString, isDecimal, isHex, isLogEcho, isOctal, log, log, log, log, log, makeInteger, makeLong, makeThread, mergeArray, mergeBooleanArray, mergeByteArray, mergeCharArray, mergeDoubleArray, mergeFloatArray, mergeIntArray, mergeLongArray, mod, mod, octalValue, out, out, out, out, out, pad, parseBandwidth, parseBandwidth, parseDelimitedString, parseHex, parseHex, parseMemorySize, parseMemorySize, parsePercentage, parseTime, parseTime, parseTimeNanos, parseTimeNanos, printStackTrace, randomize, randomize, randomize, randomize, read, read, read, read, read, read, read, replace, setErr, setLog, setLogEcho, setOut, sleep, toBandwidthString, toBandwidthString, toCharEscape, toCrc, toCrc, toCrc, toCrc, toCrc, toDecString, toDelimitedString, toDelimitedString, toDelimitedString, toDelimitedString, toHex, toHex, toHexDump, toHexEscape, toHexEscape, toHexEscape, toHexEscape, toHexString, toMemorySizeString, toMemorySizeString, toQuotedCharEscape, toQuotedStringEscape, toSqlString, toString, toString, toStringEscape, toUnicodeEscape, trace, trace, trace, trace, trace, trace, trace, trace, trace, truncateString, truncateString, wait
-
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface java.util.Map
compute, computeIfAbsent, computeIfPresent, forEach, getOrDefault, merge, putIfAbsent, remove, replace, replace, replaceAll
-
-
-
-
Constructor Detail
-
OpenHashMap
public OpenHashMap()
Default constructor.
-
OpenHashMap
public OpenHashMap(int initialCapacity)
Create a OpenHashMap pre-sized to hold the specified number of entries.- Parameters:
initialCapacity
- the initial capacity requirement for the hash map
-
OpenHashMap
public OpenHashMap(Map map)
Create a OpenHashMap that will initially contain the contents of the passed Map. In other words, this is a "copy constructor".- Parameters:
map
- the Collection whose contents this
-
-
Method Detail
-
size
public int size()
Returns the number of key-value mappings in this map.
-
containsKey
public boolean containsKey(Object oKey)
Returns true if this map contains a mapping for the specified key.- Specified by:
containsKey
in interfaceMap<K,V>
- Overrides:
containsKey
in classAbstractKeyBasedMap<K,V>
- Returns:
- true if this map contains a mapping for the specified key, false otherwise.
-
put
public Object put(Object oKey, Object oValue)
Associates the specified value with the specified key in this map.- Specified by:
put
in interfaceMap<K,V>
- Overrides:
put
in classAbstractKeyBasedMap<K,V>
- Parameters:
oKey
- key with which the specified value is to be associatedoValue
- value to be associated with the specified key- Returns:
- previous value associated with specified key, or null if there was no mapping for key
-
remove
public V remove(Object oKey)
Removes the mapping for this key from this map if present. Expensive: updates both the underlying cache and the local cache.- Specified by:
remove
in interfaceMap<K,V>
- Overrides:
remove
in classAbstractKeyBasedMap<K,V>
- Parameters:
oKey
- key whose mapping is to be removed from the map- Returns:
- previous value associated with specified key, or null if there was no mapping for key. A null return can also indicate that the map previously associated null with the specified key, if the implementation supports null values.
-
clear
public void clear()
Clear all key/value mappings.
-
instantiateKeySet
protected Set instantiateKeySet()
Factory pattern: Create a Set that represents the keys in the Map- Overrides:
instantiateKeySet
in classAbstractKeyBasedMap<K,V>
- Returns:
- a new instance of Set that represents the keys in the Map
-
instantiateEntrySet
protected Set instantiateEntrySet()
Factory pattern: Create a Set that represents the entries in the Map.- Overrides:
instantiateEntrySet
in classAbstractKeyBasedMap<K,V>
- Returns:
- a new instance of Set that represents the entries in the Map
-
iterateKeys
protected Iterator iterateKeys()
Create an iterator over the keys in this Map. The Iterator must support remove() if the Map supports removal.- Specified by:
iterateKeys
in classAbstractKeyBasedMap<K,V>
- Returns:
- a new instance of an Iterator over the keys in this Map
-
-