|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectcom.github.andrewoma.dexx.collection.internal.base.AbstractTraversable<E>
com.github.andrewoma.dexx.collection.internal.base.AbstractIterable<Pair<K,V>>
com.github.andrewoma.dexx.collection.internal.base.AbstractMap<K,V>
com.github.andrewoma.dexx.collection.DerivedKeyHashMap<K,V>
public class DerivedKeyHashMap<K,V>
DerivedKeyHashMap is a HashMap variant where the key for the Map is derived from the value stored.
By deriving the key it is possible to reduce the memory overhead per node in the map (assuming the key is a primitive field in the value object). e.g.
static class Value {
int key;
int value;
}
DerivedKeyHashMap<Integer, Value> map = new DerivedKeyHashMap<Integer, Value>(
new KeyFunction<Integer, Value>() {
public Integer key(Value value) {
return value.key;
}
});
Value value = new Value();
value.key = 1;
value.value = 100;
map = map.put(value.key, value);
The underlying implementation is a port of Scala's HashMap which is an implementation of a
hash array mapped trie.
It uses significantly less memory than Scala's implementation as the leaf nodes are the values themselves (not objects containing keys, values and hashes).
As the key is derived from the value, DerivedKeyHashMap does not support null values.
| Constructor Summary | |
|---|---|
DerivedKeyHashMap(KeyFunction<K,V> keyFunction)
|
|
| Method Summary | ||
|---|---|---|
boolean |
containsKey(K key)
Returns true if this map contains the specified key. |
|
static
|
factory(KeyFunction<K,V> keyFunction)
|
|
|
forEach(Function<Pair<K,V>,U> f)
All collection methods can be built upon this forEach definition. |
|
V |
get(K key)
Returns the value associated with the key or null if the no value exists with the key specified. |
|
Iterator<Pair<K,V>> |
iterator()
|
|
DerivedKeyHashMap<K,V> |
put(K key,
V value)
Returns a map with the value specified associated to the key specified. |
|
DerivedKeyHashMap<K,V> |
remove(K key)
Returns a map with the value associated with the key removed if it exists. |
|
int |
size()
Returns the size of the collection. |
|
| Methods inherited from class com.github.andrewoma.dexx.collection.internal.base.AbstractMap |
|---|
asMap, equals, hashCode, keys, values |
| Methods inherited from class com.github.andrewoma.dexx.collection.internal.base.AbstractTraversable |
|---|
isEmpty, makeString, makeString, to, toArray, toArray, toIndexedList, toSet, toSortedSet, toString |
| Methods inherited from class java.lang.Object |
|---|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
| Methods inherited from interface com.github.andrewoma.dexx.collection.Traversable |
|---|
isEmpty, makeString, makeString, to, toArray, toArray, toIndexedList, toSet, toSortedSet |
| Constructor Detail |
|---|
public DerivedKeyHashMap(@NotNull
KeyFunction<K,V> keyFunction)
| Method Detail |
|---|
@NotNull public static <K,V> BuilderFactory<Pair<K,V>,DerivedKeyHashMap<K,V>> factory(KeyFunction<K,V> keyFunction)
public boolean containsKey(@NotNull
K key)
Map
@NotNull
public DerivedKeyHashMap<K,V> put(@NotNull
K key,
V value)
MapIf value already exists for the key, it will be replaced.
@Nullable
public V get(@NotNull
K key)
Mapnull if the no value exists with the key specified.
@NotNull
public DerivedKeyHashMap<K,V> remove(@NotNull
K key)
Map
public int size()
TraversableWarning: infinite collections are possible, as are collections that require traversal to calculate the size.
size in interface Traversable<Pair<K,V>>size in class AbstractTraversable<Pair<K,V>>
public <U> void forEach(@NotNull
Function<Pair<K,V>,U> f)
TraversableforEach definition.
forEach in interface Traversable<Pair<K,V>>forEach in class AbstractIterable<Pair<K,V>>@NotNull public Iterator<Pair<K,V>> iterator()
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||