@StoreNotUseStandardSerialization @StorableClass public class RedBlackTree<E> extends Object implements IRBTVisitable<E>, Iterable<IRBTNode<E>>, Serializable
Modifier and Type | Field and Description |
---|---|
static boolean |
BLACK |
static boolean |
RED |
Constructor and Description |
---|
RedBlackTree(IInstanceFactory instanceFactory,
IRBTNodeManager<E> nodeManager,
boolean manageNodeIndex,
boolean uniqueValue) |
RedBlackTree(IRBTNodeManager<E> nodeManager,
boolean manageNodeIndex,
boolean uniqueValue)
construct the red black tree using a node manager
|
Modifier and Type | Method and Description |
---|---|
void |
accept(IRBTVisitor<E> visitor)
accept red black tree visitor
|
void |
append(IRBTNode<E> nodeToAppend)
append a node in the tree
if same value exist node is add at end of the existing value(s) set the node to append must be detached to the tree |
void |
appendAfterLast(IRBTNode<E> nodeToAppend)
append node after last node
|
void |
appendBeforeFirst(IRBTNode<E> nodeToInsert)
insert node before first node
|
boolean |
appendIfNotexist(IRBTNode<E> nodeToAppend)
append a node in the tree if value not already store in it
the node to append must be detached to the tree |
IRBTNode<E> |
appendOrReplace(IRBTNode<E> nodeToAppendOrSubstitute)
append or replace node if exist
the replaced node is detached from the tree |
IRBTNode<E> |
closestGreaterOrEqual(E referenceElement)
search node by reference element or closest greater if not exist
closest is the smaller greater than reference element the found node is attached to the tree |
IRBTNode<E> |
closestLessOrEqual(E referenceElement)
search for node by reference element or closest less if not exist
closest is the greater smaller than reference element the found node is attached to the tree |
boolean |
delete(E referenceElement)
delete record if found it, returning deletion operation status
delete the first value of group of same value |
IRBTNode<E> |
deleteByIndex(int index)
delete a node at position
after deletion the node to delete is in detached to the tree state |
void |
deleteExistingNode(IRBTNode<E> nodeToDelete)
delete a node attached to the tree
the node to delete must be attached to the tree after deletion the node to delete is in detached to the tree state |
IRBTNode<E> |
deleteGetRemoved(E referenceElement)
delete record if found it, returning deleted node if any
delete the first value of group of same value after deletion the node to delete returned is in detached to the tree state |
boolean |
deleteLast(E referenceElement)
delete record if found it, returning deletion operation status
delete the last value of group of same value |
IRBTNode<E> |
deleteLastGetRemoved(E referenceElement)
delete record if found it, returning deleted node if any
delete the last value of group of same value after deletion the node to delete returned is in detached to the tree state |
IRBTNode<E> |
first()
get the first node ( smallest value )
the found node is attached to the tree |
int |
getNumberOfElement()
to obtains number of elements of this tree
|
int |
index(IRBTNode<E> node)
obtains the position of the node in list view of this tree
|
void |
insertAfter(IRBTNode<E> nodeToInsert,
int index)
insert a node after the node at position, the inserted node index will be
the insert position + 1
|
void |
insertBefore(IRBTNode<E> nodeToInsert,
int index)
insert a node before the node at position, the inserted node index will
be the insert position
|
boolean |
isManageNodeIndex() |
boolean |
isNodeAttachedToTree(IRBTNode<E> node)
to know if a node is attached to the tree
|
boolean |
isUniqueValue() |
Iterator<IRBTNode<E>> |
iterator() |
IRBTNode<E> |
last()
get the last node ( greater value )
the found node is attached to the tree |
ListIterator<IRBTNode<E>> |
listIterator() |
ListIterator<IRBTNode<E>> |
listIterator(int index) |
static RedBlackTree |
newInstance(IInstanceFactory instanceFactory,
IRBTNodeManager nodeManager,
boolean manageNodeIndex,
boolean uniqueValue) |
IRBTNode<E> |
next(IRBTNode<E> node)
to obtains the next node of a node
the reference node must be attached to the tree |
IRBTNode<E> |
nodeAtIndex(int index)
to obtains node at position in the sorted list view of this tree
|
IRBTNode<E> |
pollFirst()
Retrieves and removes the first (lowest) element, or returns
null
if the tree is empty. |
IRBTNode<E> |
pollLast()
Retrieves and removes the last (highest) element, or returns
null
if the tree is empty. |
IRBTNode<E> |
previous(IRBTNode<E> node)
to obtains the previous node of a node
the reference node must be attached to the tree |
IRBTNode<E> |
search(E referenceElement)
search for a node referencing element equals to reference element, return
the first of group of same value
the found node is attached to the tree |
IRBTNode<E> |
searchLast(E referenceElement)
search for a node referencing element equals to reference element, return
the last of group of same value
the found node is attached to the tree |
IRBTNode<E> |
strictlyGreater(E referenceElement)
search for node by reference element strictly greater
the found node is attached to the tree |
IRBTNode<E> |
strictlyLess(E referenceElement)
search for node by reference element strictly less
the found node is attached to the tree |
public static final boolean BLACK
public static final boolean RED
public RedBlackTree(IRBTNodeManager<E> nodeManager, boolean manageNodeIndex, boolean uniqueValue)
nodeManager
- the node access managerpublic RedBlackTree(IInstanceFactory instanceFactory, IRBTNodeManager<E> nodeManager, boolean manageNodeIndex, boolean uniqueValue)
public static RedBlackTree newInstance(IInstanceFactory instanceFactory, IRBTNodeManager nodeManager, boolean manageNodeIndex, boolean uniqueValue)
public void accept(IRBTVisitor<E> visitor) throws RBTException
IRBTVisitable
accept
in interface IRBTVisitable<E>
visitor
- the red black tree visitorRBTException
- node access errorpublic boolean isManageNodeIndex()
public boolean isUniqueValue()
public IRBTNode<E> search(E referenceElement) throws RBTException
referenceElement
- the reference element to searchRBTException
IllegalArgumentException
- reference element is nullpublic IRBTNode<E> searchLast(E referenceElement) throws RBTException
referenceElement
- the reference element to searchRBTException
IllegalArgumentException
- reference element is nullpublic IRBTNode<E> closestGreaterOrEqual(E referenceElement) throws RBTException
referenceElement
- reference element to search for closest greaterRBTException
public IRBTNode<E> strictlyGreater(E referenceElement) throws RBTException
referenceElement
- reference element to search for strictly greaterRBTException
public IRBTNode<E> last() throws RBTException
RBTException
public IRBTNode<E> pollLast() throws RBTException
null
if the tree is empty.null
if this tree is emptyRBTException
public IRBTNode<E> first() throws RBTException
RBTException
public IRBTNode<E> pollFirst() throws RBTException
null
if the tree is empty.null
if this tree is emptyRBTException
public IRBTNode<E> closestLessOrEqual(E referenceElement) throws RBTException
referenceElement
- reference element to search for closest lessRBTException
public IRBTNode<E> strictlyLess(E referenceElement) throws RBTException
referenceElement
- reference element to search for strictly lessRBTException
public void append(IRBTNode<E> nodeToAppend) throws RBTException
nodeToAppend
- the node to appendRBTException
- the node to append is attached to the tree, node access errorpublic IRBTNode<E> appendOrReplace(IRBTNode<E> nodeToAppendOrSubstitute) throws RBTException
nodeToAppendOrSubstitute
- the node to append or substitute if existRBTException
public boolean appendIfNotexist(IRBTNode<E> nodeToAppend) throws RBTException
nodeToAppend
- the node to appendRBTException
- the node to append is attached to the tree, node access errorpublic IRBTNode<E> deleteByIndex(int index) throws RBTException, RBTExceptionOutOfBound
index
- the position of the node to deleteRBTException
- node access errorRBTExceptionOutOfBound
- index out of boundpublic void insertBefore(IRBTNode<E> nodeToInsert, int index) throws RBTException, RBTExceptionOutOfBound
nodeToInsert
- the node to insertindex
- the position where insert beforeRBTException
- node access errorRBTExceptionOutOfBound
- index out of boundpublic void insertAfter(IRBTNode<E> nodeToInsert, int index) throws RBTException, RBTExceptionOutOfBound
nodeToInsert
- the node to insertindex
- the position where insert afterRBTException
- node access errorRBTExceptionOutOfBound
- index out of boundpublic void appendAfterLast(IRBTNode<E> nodeToAppend) throws RBTException
nodeToAppend
- the node to appendRBTException
public void appendBeforeFirst(IRBTNode<E> nodeToInsert) throws RBTException
nodeToInsert
- the node to insertRBTException
public boolean delete(E referenceElement) throws RBTException
referenceElement
- reference element to find the node to deleteRBTException
- node access errorpublic boolean deleteLast(E referenceElement) throws RBTException
referenceElement
- reference element to find the node to deleteRBTException
- node access errorpublic IRBTNode<E> deleteGetRemoved(E referenceElement) throws RBTException
referenceElement
- reference element to find the node to deleteRBTException
- node access errorpublic IRBTNode<E> deleteLastGetRemoved(E referenceElement) throws RBTException
referenceElement
- reference element to find the node to deleteRBTException
- node access errorpublic void deleteExistingNode(IRBTNode<E> nodeToDelete) throws RBTException
nodeToDelete
- node to deleteRBTException
- the node is attached to the tree, node access errorpublic IRBTNode<E> previous(IRBTNode<E> node) throws RBTException
node
- the node which for previous is to obtainsRBTException
- node access errorpublic IRBTNode<E> next(IRBTNode<E> node) throws RBTException
node
- the node which for next is to obtainsRBTException
- node access errorpublic ListIterator<IRBTNode<E>> listIterator()
public ListIterator<IRBTNode<E>> listIterator(int index)
public int getNumberOfElement() throws RBTException
RBTException
- node access errorpublic int index(IRBTNode<E> node) throws RBTException
node
- the node searching its index, must be attached to the treeRBTException
- node access errorpublic IRBTNode<E> nodeAtIndex(int index) throws RBTException, RBTExceptionOutOfBound
index
- the index of the nodeRBTException
- node access errorRBTExceptionOutOfBound
- index out of boundpublic boolean isNodeAttachedToTree(IRBTNode<E> node) throws RBTException
node
- node to check if attached to the treeRBTException
- node access errorCopyright © 2007-2012 Luc Peuvrier. All Rights Reserved.