Package org.apache.orc.impl
Class StringRedBlackTree
java.lang.Object
org.apache.orc.impl.StringRedBlackTree
- All Implemented Interfaces:
Dictionary
A red-black tree that stores strings. The strings are stored as UTF-8 bytes
and an offset for each entry.
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.apache.orc.impl.Dictionary
Dictionary.IMPL, Dictionary.Visitor, Dictionary.VisitorContext -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected intstatic final intprotected intprotected intFields inherited from interface org.apache.orc.impl.Dictionary
INITIAL_DICTIONARY_SIZE -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected booleanadd()Add the new key to the tree.intadd(byte[] bytes, int offset, int length) intintvoidclear()Reset the table to empty.protected intcompareValue(int position) Compare the value at the given position to the new value.intGet the size of the character data in the table.protected intgetLeft(int position) Get the left field of the given position.protected intgetRight(int position) Get the right field of the given position.longCalculate the approximate size in memory.getText(int positionInKeyOffset) voidGiven the position index, return the original string before being encoded.protected booleanisRed(int position) Is the given node red as opposed to black? To prevent having an extra word in the data array, we just the low bit on the left child index.intsize()Get the number of elements in the set.voidvisit(Dictionary.Visitor visitor) Visit all of the nodes in the tree in sorted order.intwriteTo(OutputStream out, int position) Given the position index, write the original string, before being encoded, to the OutputStream.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.apache.orc.impl.Dictionary
size
-
Field Details
-
NULL
public static final int NULL- See Also:
-
size
protected int size -
root
protected int root -
lastAdd
protected int lastAdd
-
-
Constructor Details
-
StringRedBlackTree
public StringRedBlackTree(int initialCapacity)
-
-
Method Details
-
add
-
add
-
add
public int add(byte[] bytes, int offset, int length) - Specified by:
addin interfaceDictionary
-
compareValue
protected int compareValue(int position) Compare the value at the given position to the new value.- Returns:
- 0 if the values are the same, -1 if the new value is smaller and 1 if the new value is larger.
-
visit
Visit all of the nodes in the tree in sorted order.- Specified by:
visitin interfaceDictionary- Parameters:
visitor- the action to be applied to each node- Throws:
IOException
-
clear
public void clear()Reset the table to empty.- Specified by:
clearin interfaceDictionary
-
getText
Description copied from interface:DictionaryGiven the position index, return the original string before being encoded. The value of the Text in the Dictionary is copied intoresult.- Specified by:
getTextin interfaceDictionary- Parameters:
result- the holder to copy the dictionary text intooriginalPosition- the position where the key was added
-
getText
- Specified by:
getTextin interfaceDictionary
-
writeTo
Description copied from interface:DictionaryGiven the position index, write the original string, before being encoded, to the OutputStream.- Specified by:
writeToin interfaceDictionary- Parameters:
out- the output stream to which to write the dataposition- the position where the key was originally added- Returns:
- the number of byte written to the stream
- Throws:
IOException- if an I/O error occurs
-
getCharacterSize
public int getCharacterSize()Get the size of the character data in the table.- Returns:
- the bytes used by the table
-
getSizeInBytes
public long getSizeInBytes()Calculate the approximate size in memory.- Specified by:
getSizeInBytesin interfaceDictionary- Returns:
- the number of bytes used in storing the tree.
-
isRed
protected boolean isRed(int position) Is the given node red as opposed to black? To prevent having an extra word in the data array, we just the low bit on the left child index. -
getLeft
protected int getLeft(int position) Get the left field of the given position. -
getRight
protected int getRight(int position) Get the right field of the given position. -
add
protected boolean add()Add the new key to the tree.- Returns:
- true if the element is a new one.
-
size
public int size()Get the number of elements in the set.
-