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
Modifier and TypeFieldDescriptionprotected int
static final int
protected int
protected int
Fields inherited from interface org.apache.orc.impl.Dictionary
INITIAL_DICTIONARY_SIZE
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprotected boolean
add()
Add the new key to the tree.int
add
(byte[] bytes, int offset, int length) int
int
void
clear()
Reset the table to empty.protected int
compareValue
(int position) Compare the value at the given position to the new value.int
Get the size of the character data in the table.protected int
getLeft
(int position) Get the left field of the given position.protected int
getRight
(int position) Get the right field of the given position.long
Calculate the approximate size in memory.getText
(int positionInKeyOffset) void
Given the position index, return the original string before being encoded.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.int
size()
Get the number of elements in the set.void
visit
(Dictionary.Visitor visitor) Visit all of the nodes in the tree in sorted order.int
writeTo
(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, wait
Methods 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:
add
in 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:
visit
in interfaceDictionary
- Parameters:
visitor
- the action to be applied to each node- Throws:
IOException
-
clear
public void clear()Reset the table to empty.- Specified by:
clear
in interfaceDictionary
-
getText
Description copied from interface:Dictionary
Given the position index, return the original string before being encoded. The value of the Text in the Dictionary is copied intoresult
.- Specified by:
getText
in interfaceDictionary
- Parameters:
result
- the holder to copy the dictionary text intooriginalPosition
- the position where the key was added
-
getText
- Specified by:
getText
in interfaceDictionary
-
writeTo
Description copied from interface:Dictionary
Given the position index, write the original string, before being encoded, to the OutputStream.- Specified by:
writeTo
in 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:
getSizeInBytes
in 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.
-