Class SearchTreeBasedDictionaryBuilder<V extends ValueVector>
java.lang.Object
org.apache.arrow.algorithm.dictionary.SearchTreeBasedDictionaryBuilder<V>
- Type Parameters:
V
- the dictionary vector type.
- All Implemented Interfaces:
DictionaryBuilder<V>
public class SearchTreeBasedDictionaryBuilder<V extends ValueVector>
extends Object
implements DictionaryBuilder<V>
This class builds the dictionary based on a binary search tree. Each add operation can be
finished in O(log(n)) time, where n is the current dictionary size.
-
Field Summary
Modifier and TypeFieldDescriptionprotected final VectorValueComparator<V>
The criteria for sorting in the search tree. -
Constructor Summary
ConstructorDescriptionSearchTreeBasedDictionaryBuilder
(V dictionary, VectorValueComparator<V> comparator) Construct a search tree-based dictionary builder.SearchTreeBasedDictionaryBuilder
(V dictionary, VectorValueComparator<V> comparator, boolean encodeNull) Construct a search tree-based dictionary builder. -
Method Summary
Modifier and TypeMethodDescriptionint
Try to add an element from the target vector to the dictionary.int
Try to add all values from the target vector to the dictionary.Gets the dictionary built.void
populateSortedDictionary
(V sortedDictionary) Gets the sorted dictionary.
-
Field Details
-
comparator
The criteria for sorting in the search tree.
-
-
Constructor Details
-
SearchTreeBasedDictionaryBuilder
Construct a search tree-based dictionary builder.- Parameters:
dictionary
- the dictionary vector.comparator
- the criteria for value equality.
-
SearchTreeBasedDictionaryBuilder
public SearchTreeBasedDictionaryBuilder(V dictionary, VectorValueComparator<V> comparator, boolean encodeNull) Construct a search tree-based dictionary builder.- Parameters:
dictionary
- the dictionary vector.comparator
- the criteria for value equality.encodeNull
- if null values should be added to the dictionary.
-
-
Method Details
-
getDictionary
Gets the dictionary built. Please note that the dictionary is not in sorted order. Instead, its order is determined by the order of element insertion. To get the dictionary in sorted order, please usepopulateSortedDictionary(ValueVector)
.- Specified by:
getDictionary
in interfaceDictionaryBuilder<V extends ValueVector>
- Returns:
- the dictionary.
-
addValues
Try to add all values from the target vector to the dictionary.- Specified by:
addValues
in interfaceDictionaryBuilder<V extends ValueVector>
- Parameters:
targetVector
- the target vector containing values to probe.- Returns:
- the number of values actually added to the dictionary.
-
addValue
Try to add an element from the target vector to the dictionary.- Specified by:
addValue
in interfaceDictionaryBuilder<V extends ValueVector>
- Parameters:
targetVector
- the target vector containing new element.targetIndex
- the index of the new element in the target vector.- Returns:
- the index of the new element in the dictionary.
-
populateSortedDictionary
Gets the sorted dictionary. Note that given the binary search tree, the sort can finish in O(n).
-