java.lang.Object
org.apache.arrow.vector.util.MapWithOrdinalImpl<K,V>
- Type Parameters:
K- key typeV- value type
- All Implemented Interfaces:
MapWithOrdinal<K,V>
An implementation of map that supports constant time look-up by a generic key or an ordinal.
This class extends the functionality a regular Map with ordinal lookup support. Upon
insertion an unused ordinal is assigned to the inserted (key, value) tuple. Upon update the same
ordinal id is re-used while value is replaced. Upon deletion of an existing item, its
corresponding ordinal is recycled and could be used by another item.
For any instance with N items, this implementation guarantees that ordinals are in the range
of [0, N). However, the ordinal assignment is dynamic and may change after an insertion or
deletion. Consumers of this class are responsible for explicitly checking the ordinal
corresponding to a key via getOrdinal(Object) before attempting to
execute a lookup with an ordinal.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidclear()booleancontainsKey(Object key) getByOrdinal(int id) Returns the value corresponding to the given ordinal.intgetOrdinal(K key) Returns the ordinal corresponding to the given key.booleanisEmpty()keys()booleanInserts the tuple (key, value) into the map extending the semantics ofMap.put(K, V)with automatic ordinal assignment.booleanbooleanRemoves the element corresponding to the key if exists extending the semantics ofMap.remove(java.lang.Object)with ordinal re-cycling.intsize()values()
-
Constructor Details
-
MapWithOrdinalImpl
public MapWithOrdinalImpl()
-
-
Method Details
-
getByOrdinal
Returns the value corresponding to the given ordinal.- Specified by:
getByOrdinalin interfaceMapWithOrdinal<K,V> - Parameters:
id- ordinal value for lookup- Returns:
- an instance of V
-
getOrdinal
Returns the ordinal corresponding to the given key.- Specified by:
getOrdinalin interfaceMapWithOrdinal<K,V> - Parameters:
key- key for ordinal lookup- Returns:
- ordinal value corresponding to key if it exists or -1
-
size
public int size()- Specified by:
sizein interfaceMapWithOrdinal<K,V>
-
isEmpty
public boolean isEmpty()- Specified by:
isEmptyin interfaceMapWithOrdinal<K,V>
-
getAll
- Specified by:
getAllin interfaceMapWithOrdinal<K,V>
-
get
- Specified by:
getin interfaceMapWithOrdinal<K,V>
-
put
Inserts the tuple (key, value) into the map extending the semantics ofMap.put(K, V)with automatic ordinal assignment. A new ordinal is assigned if key does not exists. Otherwise the same ordinal is re-used but the value is replaced.- Specified by:
putin interfaceMapWithOrdinal<K,V> - See Also:
-
values
- Specified by:
valuesin interfaceMapWithOrdinal<K,V>
-
remove
- Specified by:
removein interfaceMapWithOrdinal<K,V>
-
containsKey
- Specified by:
containsKeyin interfaceMapWithOrdinal<K,V>
-
removeAll
Removes the element corresponding to the key if exists extending the semantics ofMap.remove(java.lang.Object)with ordinal re-cycling. The ordinal corresponding to the given key may be re-assigned to another tuple. It is important that consumer checks the ordinal value viagetOrdinal(Object)before attempting to look-up by ordinal.- Specified by:
removeAllin interfaceMapWithOrdinal<K,V> - See Also:
-
clear
public void clear()- Specified by:
clearin interfaceMapWithOrdinal<K,V>
-
keys
- Specified by:
keysin interfaceMapWithOrdinal<K,V>
-