V - Type of the values.public class CompactStringMap<V>
extends Object
implements Map<String,V>
Map from String keys to values, intended
for the very large name-keyed maps of a netlist or design (such as the instances and nets of an
EDIFCell, or the cells and nets of a Design).
Unlike HashMap, no per-entry Node or Entry object is allocated. The map runs in
one of two modes:
Map semantics. A value's derived key must not change while the value
is in a derived-key map: remove it under its old key before renaming it, then put it back.
Each slot has a one-byte tag: empty, removed (a tombstone), or seven bits of the key's hash. Probing
scans the tags and only reads a value (and its key) when the tag matches, so a lookup reads about as
many objects as a HashMap lookup, and an absent key usually reads none. Lookups use the cached
String.hashCode() of the keys. Null keys and null values are supported. Removal leaves a
tombstone (or an empty slot when possible), so that entries never move except when the table is
rebuilt on growth. Iteration order is the table order, which, as for HashMap, depends on the keys
and on the history of insertions; it is not the insertion order. Iterators are fail-fast on a
best-effort basis and support Iterator.remove().
Like HashMap, this class is not thread-safe: concurrent reads are safe as long as no thread modifies the map concurrently (lookups do not modify any state).
| Constructor and Description |
|---|
CompactStringMap()
Creates an empty map in keyed mode (parallel key and value arrays).
|
CompactStringMap(Function<? super V,String> keyFn)
Creates an empty map in derived-key mode.
|
CompactStringMap(Function<? super V,String> keyFn,
int expectedSize)
Creates an empty map in derived-key mode with room for the expected number of entries.
|
| Modifier and Type | Method and Description |
|---|---|
void |
clear() |
boolean |
containsKey(Object key) |
boolean |
containsValue(Object value) |
Set<Map.Entry<String,V>> |
entrySet() |
boolean |
equals(Object o) |
void |
forEach(BiConsumer<? super String,? super V> action) |
V |
get(Object key) |
V |
getOrDefault(Object key,
V defaultValue) |
int |
hashCode() |
boolean |
isEmpty() |
boolean |
isKeyed() |
Set<String> |
keySet() |
V |
put(String key,
V value) |
void |
putAll(Map<? extends String,? extends V> m) |
V |
putIfAbsent(String key,
V value) |
V |
remove(Object key) |
boolean |
remove(Object key,
Object value) |
int |
size() |
String |
toString() |
Collection<V> |
values() |
public CompactStringMap()
public CompactStringMap(Function<? super V,String> keyFn)
keyFn - Gets the key of a value. It must accept any value put in the map and must not
return a different key for a value while the value is in the map.public CompactStringMap(Function<? super V,String> keyFn, int expectedSize)
keyFn - See CompactStringMap.CompactStringMap(Function).expectedSize - Number of entries the map can hold without growing.public boolean isKeyed()
public int size()
size in interface Map<String,V>public boolean isEmpty()
isEmpty in interface Map<String,V>public boolean containsKey(Object key)
containsKey in interface Map<String,V>public V getOrDefault(Object key, V defaultValue)
getOrDefault in interface Map<String,V>public boolean containsValue(Object value)
containsValue in interface Map<String,V>public V putIfAbsent(String key, V value)
putIfAbsent in interface Map<String,V>public boolean remove(Object key,
Object value)
remove in interface Map<String,V>public void putAll(Map<? extends String,? extends V> m)
putAll in interface Map<String,V>public void clear()
clear in interface Map<String,V>public void forEach(BiConsumer<? super String,? super V> action)
forEach in interface Map<String,V>public Set<String> keySet()
keySet in interface Map<String,V>public Set<Map.Entry<String,V>> entrySet()
entrySet in interface Map<String,V>public boolean equals(Object o)
equals in interface Map<String,V>equals in class Objectpublic int hashCode()
hashCode in interface Map<String,V>hashCode in class Objectpublic String toString()
toString in class Object