Class IntArrayRBTcommon
- java.lang.Object
-
- org.apache.uima.internal.util.rb_trees.IntArrayRBTcommon
-
- Direct Known Subclasses:
Int2IntRBT,IntArrayRBT
public class IntArrayRBTcommon extends java.lang.ObjectCommon part of Red-black tree implementation based on integer arrays. Preliminary performance measurements on j2se 1.4 indicate that the performance improvement as opposed to an object-based implementation are miniscule. This seems to indicate a much improved object creation handling in this vm. However the space improvements are substantial.
-
-
Field Summary
Fields Modifier and Type Field Description protected static booleanblackprotected boolean[]colorprotected static intdefault_sizeintgreatestNodeprotected intgrowth_factorprotected intinitialSizeprotected int[]klrpprotected int[]klrp1protected int[]klrp2protected int[]klrp3protected static intMAXklrp0protected static intMAXklrpMaskprotected intmultiplication_limitprotected intnextstatic intNILprotected static booleanredprotected introotprotected intsize
-
Constructor Summary
Constructors Constructor Description IntArrayRBTcommon()Constructor for IntArrayRBT.IntArrayRBTcommon(int initialSize)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected intcompare(int v1, int v2)booleancontains(int k)booleancontainsKey(int k)protected voiddeleteFixup(int x)protected voiddeleteNode(int z)delete node z Step 1: locate a node to delete at the bottom of the tree.protected int[]ensureArrayCapacity(int[] array, int newSize)protected voidensureCapacityKlrp(int requiredSize)There are two strategies for storing data, controlled by useklrp.intfindInsertionPoint(int k)Find the node such that key[node] ≥ k and key[previous(node)] < k.intfindInsertionPointCmn(int k, boolean moveToLeftmost)intfindInsertionPointNoDups(int k)Find the node such that key[node] ≥ k and key[previous(node)] < k.intfindKey(int k)protected intfindKeyDown(int k, int node)voidflush()intgetFirstNode()protected intgetKeyForNode(int node)protected intgetLeft(int node)protected intgetParent(int node)protected intgetRight(int node)protected intgetXXX(int node, int offset)protected voidinitVars()protected voidleftRotate(int x)intmaxDepth()protected intmaxDepth(int node, int depth)intminDepth()protected intminDepth(int node, int depth)protected intnewNode(int k)intnextNode(int node)Method: if there's a right descendant, return the left-most chain down on that link Else, go up until parent has a right descendant not the previous, and return that.protected intnextPowerOf2(int v)intnodeDepth(int k)protected intnodeDepth(int node, int depth, int k)intpreviousNode(int node)Method: if there's a left descendant, go to the right-most bottom of that Otherwise, ascend up until the parent's left descendant isn't the previous linkvoidprintKeys()protected voidprintKeys(int node, int offset, java.lang.StringBuffer buf)protected voidrightRotate(int x)protected booleansatisfiesRBProps(int node, int blackDepth, int currentBlack)booleansatisfiesRedBlackProperties()protected voidsetAsRoot(int x)protected intsetLeft(int node, int value)protected intsetParent(int node, int value)protected intsetRight(int node, int value)protected voidsetupArrays()protected intsetXXX(int node, int offset, int value)intsize()
-
-
-
Field Detail
-
klrp
protected int[] klrp
-
klrp1
protected int[] klrp1
-
klrp2
protected int[] klrp2
-
klrp3
protected int[] klrp3
-
MAXklrp0
protected static final int MAXklrp0
- See Also:
- Constant Field Values
-
MAXklrpMask
protected static final int MAXklrpMask
- See Also:
- Constant Field Values
-
color
protected boolean[] color
-
next
protected int next
-
size
protected int size
-
root
protected int root
-
greatestNode
public int greatestNode
-
default_size
protected static final int default_size
- See Also:
- Constant Field Values
-
initialSize
protected final int initialSize
-
growth_factor
protected final int growth_factor
- See Also:
- Constant Field Values
-
multiplication_limit
protected final int multiplication_limit
- See Also:
- Constant Field Values
-
NIL
public static final int NIL
- See Also:
- Constant Field Values
-
red
protected static final boolean red
- See Also:
- Constant Field Values
-
black
protected static final boolean black
- See Also:
- Constant Field Values
-
-
Method Detail
-
getXXX
protected int getXXX(int node, int offset)
-
setXXX
protected int setXXX(int node, int offset, int value)
-
getLeft
protected int getLeft(int node)
-
setLeft
protected int setLeft(int node, int value)
-
getRight
protected int getRight(int node)
-
setRight
protected int setRight(int node, int value)
-
getParent
protected int getParent(int node)
-
setParent
protected int setParent(int node, int value)- Parameters:
node- -value- -- Returns:
- the value
-
getKeyForNode
protected int getKeyForNode(int node)
-
nextPowerOf2
protected int nextPowerOf2(int v)
-
setupArrays
protected void setupArrays()
-
initVars
protected void initVars()
-
flush
public void flush()
-
size
public final int size()
-
ensureCapacityKlrp
protected void ensureCapacityKlrp(int requiredSize)
There are two strategies for storing data, controlled by useklrp. If useklrp, then 4 elements are put together into one int vector, taking 4 words per element. Other elements are kept in their own vectors. The growth strategy for the 4-element one is to a) start at some minimum (a power of 2) b) grow by doubling up to 2 * 1024 *1024 c) grow by adding 2 *1024 * 1024, until d) reaching the maximum size (the max index will be 1 less) e) when that size is reached, the next int[] is set up with the minimum, and it grows as above. The test for growth and growing is made individually for the different parts. For color (a boolean), the size for stopping doubling is 32 * 2 * 1024 * 1024, so the # of words is the same.- Parameters:
requiredSize- -
-
newNode
protected int newNode(int k)
-
setAsRoot
protected final void setAsRoot(int x)
-
ensureArrayCapacity
protected final int[] ensureArrayCapacity(int[] array, int newSize)- Parameters:
array- - the array to expand - may be klrp0, 1, 2, 3, etc.newSize- = the total size - if in parts, the size of the part- Returns:
- expanded array
-
leftRotate
protected final void leftRotate(int x)
-
rightRotate
protected final void rightRotate(int x)
-
findKey
public int findKey(int k)
- Parameters:
k- -- Returns:
- the first node such that k = key[node].
-
findKeyDown
protected int findKeyDown(int k, int node)
-
findInsertionPoint
public int findInsertionPoint(int k)
Find the node such that key[node] ≥ k and key[previous(node)] < k. If k is less than all the nodes, then the first node is returned If k is greater than all the nodes, then NIL is returned (invalid signal)- Parameters:
k- the key- Returns:
- the index of the node, or NIL if k > all keys
-
findInsertionPointNoDups
public int findInsertionPointNoDups(int k)
Find the node such that key[node] ≥ k and key[previous(node)] < k.- Parameters:
k- -- Returns:
- the node such that key[node] ≥ k and key[previous(node)] < k.
-
findInsertionPointCmn
public int findInsertionPointCmn(int k, boolean moveToLeftmost)
-
containsKey
public final boolean containsKey(int k)
-
contains
public final boolean contains(int k)
-
getFirstNode
public final int getFirstNode()
-
nextNode
public final int nextNode(int node)
Method: if there's a right descendant, return the left-most chain down on that link Else, go up until parent has a right descendant not the previous, and return that.- Parameters:
node- starting point- Returns:
- the node logically following this one.
-
previousNode
public final int previousNode(int node)
Method: if there's a left descendant, go to the right-most bottom of that Otherwise, ascend up until the parent's left descendant isn't the previous link- Parameters:
node- the current node index- Returns:
- the previous node index or NIL
-
deleteNode
protected void deleteNode(int z)
delete node z Step 1: locate a node to delete at the bottom of the tree. Bottom means left or right (or both) descendant is NIL. There are 2 cases: either the node to delete is z, or the node is the nextNode. If z has one or both descendants NIL, then it's the one to delete. Otherwise, the next node which is found by descending right then left until reaching the bottom (left = 0) node. y is node to remove from the tree. x is the non-NIL descendant of y (if one exists). It will be reparented to y's parent, and y's parent's left or right will point to it, skipping over y.- Parameters:
z- node to be removed, logically
-
deleteFixup
protected void deleteFixup(int x)
-
compare
protected int compare(int v1, int v2)
-
satisfiesRedBlackProperties
public boolean satisfiesRedBlackProperties()
-
satisfiesRBProps
protected boolean satisfiesRBProps(int node, int blackDepth, int currentBlack)
-
maxDepth
public int maxDepth()
-
minDepth
public int minDepth()
-
nodeDepth
public int nodeDepth(int k)
-
nodeDepth
protected int nodeDepth(int node, int depth, int k)
-
maxDepth
protected int maxDepth(int node, int depth)
-
minDepth
protected int minDepth(int node, int depth)
-
printKeys
public final void printKeys()
-
printKeys
protected final void printKeys(int node, int offset, java.lang.StringBuffer buf)
-
-