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
-
Method Summary
Modifier and TypeMethodDescriptionvoid
clear()
boolean
containsKey
(Object key) getByOrdinal
(int id) Returns the value corresponding to the given ordinal.int
getOrdinal
(K key) Returns the ordinal corresponding to the given key.boolean
isEmpty()
keys()
boolean
Inserts the tuple (key, value) into the map extending the semantics ofMap.put(K, V)
with automatic ordinal assignment.boolean
boolean
Removes the element corresponding to the key if exists extending the semantics ofMap.remove(java.lang.Object)
with ordinal re-cycling.int
size()
values()
-
Constructor Details
-
MapWithOrdinalImpl
public MapWithOrdinalImpl()
-
-
Method Details
-
getByOrdinal
Returns the value corresponding to the given ordinal.- Specified by:
getByOrdinal
in 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:
getOrdinal
in 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:
size
in interfaceMapWithOrdinal<K,
V>
-
isEmpty
public boolean isEmpty()- Specified by:
isEmpty
in interfaceMapWithOrdinal<K,
V>
-
getAll
- Specified by:
getAll
in interfaceMapWithOrdinal<K,
V>
-
get
- Specified by:
get
in 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:
put
in interfaceMapWithOrdinal<K,
V> - See Also:
-
values
- Specified by:
values
in interfaceMapWithOrdinal<K,
V>
-
remove
- Specified by:
remove
in interfaceMapWithOrdinal<K,
V>
-
containsKey
- Specified by:
containsKey
in 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:
removeAll
in interfaceMapWithOrdinal<K,
V> - See Also:
-
clear
public void clear()- Specified by:
clear
in interfaceMapWithOrdinal<K,
V>
-
keys
- Specified by:
keys
in interfaceMapWithOrdinal<K,
V>
-