Class UnifiedMapWithHashingStrategy<K,V>
java.lang.Object
org.eclipse.collections.impl.AbstractRichIterable<V>
org.eclipse.collections.impl.map.AbstractMapIterable<K,V>
org.eclipse.collections.impl.map.mutable.AbstractMutableMapIterable<K,V>
org.eclipse.collections.impl.map.mutable.AbstractMutableMap<K,V>
org.eclipse.collections.impl.map.strategy.mutable.UnifiedMapWithHashingStrategy<K,V>
- All Implemented Interfaces:
Externalizable,Serializable,Cloneable,Iterable<V>,Map<K,,V> InternalIterable<V>,MapIterable<K,,V> MutableMap<K,,V> MutableMapIterable<K,,V> UnsortedMapIterable<K,,V> RichIterable<V>,BatchIterable<V>
public class UnifiedMapWithHashingStrategy<K,V>
extends AbstractMutableMap<K,V>
implements Externalizable, BatchIterable<V>
UnifiedMapWithHashingStrategy stores key/value pairs in a single array, where alternate slots are keys and values.
This is nicer to CPU caches as consecutive memory addresses are very cheap to access. Entry objects are not stored in the
table like in java.util.HashMap. Instead of trying to deal with collisions in the main array using Entry objects,
we put a special object in the key slot and put a regular Object[] in the value slot. The array contains the key value
pairs in consecutive slots, just like the main array, but it's a linear list with no hashing.
The difference between UnifiedMap and UnifiedMapWithHashingStrategy is that a HashingStrategy based UnifiedMap does not rely on the hashCode or equality of the object at the key, but instead relies on a HashingStrategy implementation provided by a developer to compute the hashCode and equals for the objects stored in the map.
- See Also:
-
Nested Class Summary
-
Constructor Summary
ConstructorsConstructorDescriptionDeprecated.No argument default constructor used for serialization.UnifiedMapWithHashingStrategy(HashingStrategy<? super K> hashingStrategy) UnifiedMapWithHashingStrategy(HashingStrategy<? super K> hashingStrategy, int initialCapacity) UnifiedMapWithHashingStrategy(HashingStrategy<? super K> hashingStrategy, int initialCapacity, float loadFactor) UnifiedMapWithHashingStrategy(HashingStrategy<? super K> hashingStrategy, Map<? extends K, ? extends V> map) UnifiedMapWithHashingStrategy(HashingStrategy<? super K> hashingStrategy, Pair<K, V>... pairs) -
Method Summary
Modifier and TypeMethodDescriptionbooleanallSatisfy(Predicate<? super V> predicate) <P> booleanallSatisfyWith(Predicate2<? super V, ? super P> predicate, P parameter) booleananySatisfy(Predicate<? super V> predicate) <P> booleananySatisfyWith(Predicate2<? super V, ? super P> predicate, P parameter) voidbatchForEach(Procedure<? super V> procedure, int sectionIndex, int sectionCount) voidclear()clone()<E> MutableMap<K,V> collectKeysAndValues(Iterable<E> iterable, Function<? super E, ? extends K> keyFunction, Function<? super E, ? extends V> valueFunction) <R> MutableMap<K,R> collectValues(Function2<? super K, ? super V, ? extends R> function) booleancontainsKey(Object key) booleancontainsValue(Object value) detect(Predicate2<? super K, ? super V> predicate) detectIfNone(Predicate<? super V> predicate, Function0<? extends V> function) detectOptional(Predicate<? super V> predicate) detectOptional(Predicate2<? super K, ? super V> predicate) <P> VdetectWith(Predicate2<? super V, ? super P> predicate, P parameter) <P> VdetectWithIfNone(Predicate2<? super V, ? super P> predicate, P parameter, Function0<? extends V> function) detectWithOptional(Predicate2<? super V, ? super P> predicate, P parameter) entrySet()booleanvoidforEachKey(Procedure<? super K> procedure) voidforEachKeyValue(Procedure2<? super K, ? super V> procedure) voidforEachValue(Procedure<? super V> procedure) <P> voidforEachWith(Procedure2<? super V, ? super P> procedure, P parameter) voidforEachWithIndex(ObjectIntProcedure<? super V> objectIntProcedure) intgetBatchCount(int batchSize) intgetFirst()getIfAbsentPut(K key, Function0<? extends V> function) getIfAbsentPut(K key, V value) <P> VgetIfAbsentPutWith(K key, Function<? super P, ? extends V> function, P parameter) intReturns the number of JVM words that is used by this map.inthashCode()HashingStrategy<? super K>booleanisEmpty()keySet()MutableMap<K,V> newEmpty()MutableMap<K,V> newEmpty(int capacity) Creates a new instance of the same type, using the given capacity and the default growth parameters.static <K,V> UnifiedMapWithHashingStrategy<K, V> newMap(HashingStrategy<? super K> hashingStrategy) static <K,V> UnifiedMapWithHashingStrategy<K, V> newMap(HashingStrategy<? super K> hashingStrategy, int size) static <K,V> UnifiedMapWithHashingStrategy<K, V> newMap(HashingStrategy<? super K> hashingStrategy, int size, float loadFactor) static <K,V> UnifiedMapWithHashingStrategy<K, V> newMap(HashingStrategy<? super K> hashingStrategy, Map<? extends K, ? extends V> map) static <K,V> UnifiedMapWithHashingStrategy<K, V> newMap(UnifiedMapWithHashingStrategy<K, V> map) static <K,V> UnifiedMapWithHashingStrategy<K, V> newMapWith(HashingStrategy<? super K> hashingStrategy, Iterable<Pair<K, V>> inputIterable) static <K,V> UnifiedMapWithHashingStrategy<K, V> newMapWith(HashingStrategy<? super K> hashingStrategy, Pair<K, V>... pairs) static <K,V> UnifiedMapWithHashingStrategy<K, V> newWithKeysValues(HashingStrategy<? super K> hashingStrategy, K key, V value) static <K,V> UnifiedMapWithHashingStrategy<K, V> newWithKeysValues(HashingStrategy<? super K> hashingStrategy, K key1, V value1, K key2, V value2) static <K,V> UnifiedMapWithHashingStrategy<K, V> newWithKeysValues(HashingStrategy<? super K> hashingStrategy, K key1, V value1, K key2, V value2, K key3, V value3) static <K,V> UnifiedMapWithHashingStrategy<K, V> newWithKeysValues(HashingStrategy<? super K> hashingStrategy, K key1, V value1, K key2, V value2, K key3, V value3, K key4, V value4) booleannoneSatisfy(Predicate<? super V> predicate) <P> booleannoneSatisfyWith(Predicate2<? super V, ? super P> predicate, P parameter) voidvoidbooleanremoveIf(Predicate2<? super K, ? super V> predicate) intsize()toString()Returns a string with the elements of the iterable separated by commas with spaces and enclosed in square brackets.boolean<P> VupdateValueWith(K key, Function0<? extends V> factory, Function2<? super V, ? super P, ? extends V> function, P parameter) values()withKeysValues(K key, V value) withKeysValues(K key1, V value1, K key2, V value2) voidMethods inherited from class org.eclipse.collections.impl.map.mutable.AbstractMutableMap
asSynchronized, asUnmodifiable, collect, collectBoolean, collectByte, collectChar, collectDouble, collectFloat, collectIf, collectInt, collectKeysUnique, collectLong, collectShort, collectWith, flatCollect, flip, groupBy, groupByEach, groupByUniqueKey, partition, partitionWith, reject, reject, rejectWith, replaceAll, select, select, selectInstancesOf, selectWith, tap, withAllKeyValueArguments, withAllKeyValues, withKeyValue, withoutAllKeys, withoutKey, zip, zipWithIndexMethods inherited from class org.eclipse.collections.impl.map.mutable.AbstractMutableMapIterable
aggregateBy, collect, countBy, countByEach, countByWith, flipUniqueValues, getIfAbsentPutWithKey, iterator, keysView, keyValuesView, reduceBy, sumByDouble, sumByFloat, sumByInt, sumByLong, valuesViewMethods inherited from class org.eclipse.collections.impl.map.AbstractMapIterable
asLazy, chunk, contains, each, getIfAbsent, getIfAbsentValue, getIfAbsentWith, getLast, getOnly, getOrDefault, ifPresentApply, toArray, toArrayMethods inherited from class org.eclipse.collections.impl.AbstractRichIterable
appendString, appendString, collect, collectIf, collectWith, containsAll, containsAllArguments, containsAllIterable, count, countWith, flatCollect, forEach, groupBy, groupByEach, groupByUniqueKey, injectInto, injectInto, injectInto, injectInto, injectInto, into, max, max, maxBy, min, min, minBy, reject, rejectWith, select, selectWith, sumOfDouble, sumOfFloat, sumOfInt, sumOfLong, toBag, toBiMap, toList, toMap, toSet, toSortedBag, toSortedBag, toSortedBagBy, toSortedListBy, toSortedMap, toSortedMap, toSortedMapBy, toSortedSet, toSortedSet, toSortedSetBy, zip, zipWithIndexMethods inherited from interface org.eclipse.collections.impl.parallel.BatchIterable
forEachMethods inherited from interface org.eclipse.collections.api.InternalIterable
forEachMethods inherited from interface java.util.Map
compute, computeIfAbsent, computeIfPresent, putIfAbsent, remove, replace, replaceMethods inherited from interface org.eclipse.collections.api.map.MapIterable
getIfAbsent, getIfAbsentValue, getIfAbsentWith, ifPresentApply, injectIntoKeyValue, keysView, keyValuesView, parallelStream, spliterator, stream, valuesViewMethods inherited from interface org.eclipse.collections.api.map.MutableMap
aggregateBy, aggregateBy, aggregateInPlaceBy, collect, flatCollectWith, flipUniqueValues, reduceBy, withMap, withMapIterableMethods inherited from interface org.eclipse.collections.api.map.MutableMapIterable
add, countBy, countByEach, countByWith, forEach, getIfAbsentPutWithKey, getOrDefault, putAllMapIterable, putPair, removeAllKeys, sumByDouble, sumByFloat, sumByInt, sumByLongMethods inherited from interface org.eclipse.collections.api.RichIterable
aggregateBy, appendString, appendString, appendString, asLazy, chunk, collect, collectBoolean, collectByte, collectChar, collectDouble, collectFloat, collectIf, collectInt, collectLong, collectShort, collectWith, contains, containsAll, containsAllArguments, containsAllIterable, containsAny, containsAnyIterable, containsBy, containsNone, containsNoneIterable, count, countBy, countByEach, countByWith, countWith, each, flatCollect, flatCollectBoolean, flatCollectByte, flatCollectChar, flatCollectDouble, flatCollectFloat, flatCollectInt, flatCollectLong, flatCollectShort, flatCollectWith, forEach, getAny, getLast, getOnly, groupBy, groupByAndCollect, groupByEach, groupByUniqueKey, injectInto, injectInto, injectInto, injectInto, injectInto, injectIntoDouble, injectIntoFloat, injectIntoInt, injectIntoLong, into, makeString, makeString, makeString, makeString, max, max, maxBy, maxByOptional, maxOptional, maxOptional, min, min, minBy, minByOptional, minOptional, minOptional, notEmpty, reduce, reduceBy, reduceInPlace, reduceInPlace, reject, rejectWith, select, selectWith, summarizeDouble, summarizeFloat, summarizeInt, summarizeLong, sumOfDouble, sumOfFloat, sumOfInt, sumOfLong, toArray, toArray, toBag, toBiMap, toImmutableBag, toImmutableBiMap, toImmutableList, toImmutableMap, toImmutableSet, toImmutableSortedBag, toImmutableSortedBag, toImmutableSortedBagBy, toImmutableSortedList, toImmutableSortedList, toImmutableSortedListBy, toImmutableSortedSet, toImmutableSortedSet, toImmutableSortedSetBy, toList, toMap, toMap, toSet, toSortedBag, toSortedBag, toSortedBagBy, toSortedList, toSortedList, toSortedListBy, toSortedMap, toSortedMap, toSortedMapBy, toSortedSet, toSortedSet, toSortedSetBy, zip, zipWithIndex
-
Constructor Details
-
UnifiedMapWithHashingStrategy
Deprecated.No argument default constructor used for serialization. Instantiating an UnifiedMapWithHashingStrategyMultimap with this constructor will have a null hashingStrategy and throw NullPointerException when used. -
UnifiedMapWithHashingStrategy
-
UnifiedMapWithHashingStrategy
public UnifiedMapWithHashingStrategy(HashingStrategy<? super K> hashingStrategy, int initialCapacity) -
UnifiedMapWithHashingStrategy
public UnifiedMapWithHashingStrategy(HashingStrategy<? super K> hashingStrategy, int initialCapacity, float loadFactor) -
UnifiedMapWithHashingStrategy
public UnifiedMapWithHashingStrategy(HashingStrategy<? super K> hashingStrategy, Map<? extends K, ? extends V> map) -
UnifiedMapWithHashingStrategy
public UnifiedMapWithHashingStrategy(HashingStrategy<? super K> hashingStrategy, Pair<K, V>... pairs)
-
-
Method Details
-
newMap
public static <K,V> UnifiedMapWithHashingStrategy<K,V> newMap(HashingStrategy<? super K> hashingStrategy) -
newMap
public static <K,V> UnifiedMapWithHashingStrategy<K,V> newMap(HashingStrategy<? super K> hashingStrategy, int size) -
newMap
public static <K,V> UnifiedMapWithHashingStrategy<K,V> newMap(HashingStrategy<? super K> hashingStrategy, int size, float loadFactor) -
newMap
public static <K,V> UnifiedMapWithHashingStrategy<K,V> newMap(HashingStrategy<? super K> hashingStrategy, Map<? extends K, ? extends V> map) -
newMapWith
public static <K,V> UnifiedMapWithHashingStrategy<K,V> newMapWith(HashingStrategy<? super K> hashingStrategy, Iterable<Pair<K, V>> inputIterable) -
newMap
public static <K,V> UnifiedMapWithHashingStrategy<K,V> newMap(UnifiedMapWithHashingStrategy<K, V> map) -
newMapWith
public static <K,V> UnifiedMapWithHashingStrategy<K,V> newMapWith(HashingStrategy<? super K> hashingStrategy, Pair<K, V>... pairs) -
newWithKeysValues
public static <K,V> UnifiedMapWithHashingStrategy<K,V> newWithKeysValues(HashingStrategy<? super K> hashingStrategy, K key, V value) -
newWithKeysValues
public static <K,V> UnifiedMapWithHashingStrategy<K,V> newWithKeysValues(HashingStrategy<? super K> hashingStrategy, K key1, V value1, K key2, V value2) -
newWithKeysValues
public static <K,V> UnifiedMapWithHashingStrategy<K,V> newWithKeysValues(HashingStrategy<? super K> hashingStrategy, K key1, V value1, K key2, V value2, K key3, V value3) -
newWithKeysValues
public static <K,V> UnifiedMapWithHashingStrategy<K,V> newWithKeysValues(HashingStrategy<? super K> hashingStrategy, K key1, V value1, K key2, V value2, K key3, V value3, K key4, V value4) -
withKeysValues
-
withKeysValues
-
withKeysValues
-
withKeysValues
-
hashingStrategy
-
clone
- Specified by:
clonein interfaceMutableMap<K,V> - Specified by:
clonein classAbstractMutableMap<K,V>
-
newEmpty
- Specified by:
newEmptyin interfaceMutableMap<K,V> - Specified by:
newEmptyin interfaceMutableMapIterable<K,V>
-
newEmpty
Description copied from class:AbstractMutableMapCreates a new instance of the same type, using the given capacity and the default growth parameters.- Specified by:
newEmptyin classAbstractMutableMap<K,V>
-
clear
public void clear() -
put
-
updateValue
public V updateValue(K key, Function0<? extends V> factory, Function<? super V, ? extends V> function) - Specified by:
updateValuein interfaceMutableMapIterable<K,V> - Overrides:
updateValuein classAbstractMutableMapIterable<K,V>
-
updateValueWith
public <P> V updateValueWith(K key, Function0<? extends V> factory, Function2<? super V, ? super P, ? extends V> function, P parameter) - Specified by:
updateValueWithin interfaceMutableMapIterable<K,V> - Overrides:
updateValueWithin classAbstractMutableMapIterable<K,V>
-
merge
-
getIfAbsentPut
- Specified by:
getIfAbsentPutin interfaceMutableMapIterable<K,V> - Overrides:
getIfAbsentPutin classAbstractMutableMapIterable<K,V>
-
getIfAbsentPut
- Specified by:
getIfAbsentPutin interfaceMutableMapIterable<K,V> - Overrides:
getIfAbsentPutin classAbstractMutableMapIterable<K,V>
-
getIfAbsentPutWith
- Specified by:
getIfAbsentPutWithin interfaceMutableMapIterable<K,V> - Overrides:
getIfAbsentPutWithin classAbstractMutableMapIterable<K,V>
-
getCollidingBuckets
public int getCollidingBuckets() -
getMapMemoryUsedInWords
public int getMapMemoryUsedInWords()Returns the number of JVM words that is used by this map. A word is 4 bytes in a 32bit VM and 8 bytes in a 64bit VM. Each array has a 2 word header, thus the formula is: words = (internal table length + 2) + sum (for all chains (chain length + 2))- Returns:
- the number of JVM words that is used by this map.
-
get
-
containsKey
- Specified by:
containsKeyin interfaceMap<K,V> - Specified by:
containsKeyin interfaceMapIterable<K,V>
-
containsValue
- Specified by:
containsValuein interfaceMap<K,V> - Specified by:
containsValuein interfaceMapIterable<K,V>
-
forEachKeyValue
- Specified by:
forEachKeyValuein interfaceMapIterable<K,V>
-
getFirst
- Specified by:
getFirstin interfaceRichIterable<K>- Overrides:
getFirstin classAbstractMapIterable<K,V>
-
collectKeysAndValues
public <E> MutableMap<K,V> collectKeysAndValues(Iterable<E> iterable, Function<? super E, ? extends K> keyFunction, Function<? super E, ? extends V> valueFunction) - Specified by:
collectKeysAndValuesin interfaceMutableMap<K,V>
-
removeKey
- Specified by:
removeKeyin interfaceMutableMapIterable<K,V>
-
removeIf
- Specified by:
removeIfin interfaceMutableMapIterable<K,V>
-
getBatchCount
public int getBatchCount(int batchSize) - Specified by:
getBatchCountin interfaceBatchIterable<K>
-
batchForEach
- Specified by:
batchForEachin interfaceBatchIterable<K>
-
forEachKey
- Specified by:
forEachKeyin interfaceMapIterable<K,V> - Overrides:
forEachKeyin classAbstractMapIterable<K,V>
-
forEachValue
- Specified by:
forEachValuein interfaceMapIterable<K,V> - Overrides:
forEachValuein classAbstractMapIterable<K,V>
-
isEmpty
public boolean isEmpty()- Specified by:
isEmptyin interfaceMap<K,V> - Specified by:
isEmptyin interfaceRichIterable<K>- Overrides:
isEmptyin classAbstractRichIterable<V>
-
putAll
-
remove
-
size
public int size()- Specified by:
sizein interfaceBatchIterable<K>- Specified by:
sizein interfaceMap<K,V> - Specified by:
sizein interfaceRichIterable<K>
-
entrySet
-
keySet
-
values
-
equals
-
hashCode
public int hashCode() -
toString
Description copied from class:AbstractRichIterableReturns a string with the elements of the iterable separated by commas with spaces and enclosed in square brackets.Assert.assertEquals("[]", Lists.mutable.empty().toString()); Assert.assertEquals("[1]", Lists.mutable.with(1).toString()); Assert.assertEquals("[1, 2, 3]", Lists.mutable.with(1, 2, 3).toString());- Specified by:
toStringin interfaceMapIterable<K,V> - Specified by:
toStringin interfaceRichIterable<K>- Overrides:
toStringin classAbstractRichIterable<V>- Returns:
- a string representation of this collection.
- See Also:
-
trimToSize
public boolean trimToSize() -
readExternal
- Specified by:
readExternalin interfaceExternalizable- Throws:
IOExceptionClassNotFoundException
-
writeExternal
- Specified by:
writeExternalin interfaceExternalizable- Throws:
IOException
-
forEachWithIndex
- Specified by:
forEachWithIndexin interfaceInternalIterable<K>- Overrides:
forEachWithIndexin classAbstractMapIterable<K,V>
-
forEachWith
- Specified by:
forEachWithin interfaceInternalIterable<K>- Overrides:
forEachWithin classAbstractMapIterable<K,V>
-
collectValues
- Specified by:
collectValuesin interfaceMapIterable<K,V> - Specified by:
collectValuesin interfaceMutableMap<K,V> - Specified by:
collectValuesin interfaceMutableMapIterable<K,V> - Specified by:
collectValuesin interfaceUnsortedMapIterable<K,V> - Overrides:
collectValuesin classAbstractMutableMap<K,V>
-
detect
- Specified by:
detectin interfaceMapIterable<K,V> - Overrides:
detectin classAbstractMutableMapIterable<K,V>
-
detect
- Specified by:
detectin interfaceRichIterable<K>- Overrides:
detectin classAbstractMapIterable<K,V>
-
detectWith
- Specified by:
detectWithin interfaceRichIterable<K>- Overrides:
detectWithin classAbstractMapIterable<K,V>
-
detectOptional
- Specified by:
detectOptionalin interfaceMapIterable<K,V> - Overrides:
detectOptionalin classAbstractMutableMapIterable<K,V>
-
detectOptional
- Specified by:
detectOptionalin interfaceRichIterable<K>- Overrides:
detectOptionalin classAbstractMapIterable<K,V>
-
detectWithOptional
- Specified by:
detectWithOptionalin interfaceRichIterable<K>- Overrides:
detectWithOptionalin classAbstractMapIterable<K,V>
-
detectIfNone
- Specified by:
detectIfNonein interfaceRichIterable<K>- Overrides:
detectIfNonein classAbstractMapIterable<K,V>
-
detectWithIfNone
public <P> V detectWithIfNone(Predicate2<? super V, ? super P> predicate, P parameter, Function0<? extends V> function) - Specified by:
detectWithIfNonein interfaceRichIterable<K>- Overrides:
detectWithIfNonein classAbstractMapIterable<K,V>
-
anySatisfy
- Specified by:
anySatisfyin interfaceRichIterable<K>- Overrides:
anySatisfyin classAbstractMapIterable<K,V>
-
anySatisfyWith
- Specified by:
anySatisfyWithin interfaceRichIterable<K>- Overrides:
anySatisfyWithin classAbstractMapIterable<K,V>
-
allSatisfy
- Specified by:
allSatisfyin interfaceRichIterable<K>- Overrides:
allSatisfyin classAbstractMapIterable<K,V>
-
allSatisfyWith
- Specified by:
allSatisfyWithin interfaceRichIterable<K>- Overrides:
allSatisfyWithin classAbstractMapIterable<K,V>
-
noneSatisfy
- Specified by:
noneSatisfyin interfaceRichIterable<K>- Overrides:
noneSatisfyin classAbstractMapIterable<K,V>
-
noneSatisfyWith
- Specified by:
noneSatisfyWithin interfaceRichIterable<K>- Overrides:
noneSatisfyWithin classAbstractMapIterable<K,V>
-
toImmutable
- Specified by:
toImmutablein interfaceMapIterable<K,V> - Specified by:
toImmutablein interfaceMutableMapIterable<K,V> - Specified by:
toImmutablein interfaceUnsortedMapIterable<K,V> - Overrides:
toImmutablein classAbstractMutableMap<K,V>
-