New to Telerik UI for WinFormsStart a free 30-day trial

Base class for the tree. Based on the Damian Ivereigh implementation Support for the multi-trees has been added. Do not use this class directly. Use RBTree, RBMultiTree, RBOrderedTree and RBOrderedMultiTree classes

Definition

Namespace:Telerik.Collections.Generic

Assembly:Telerik.WinControls.dll

Type Parameters:

T

Key type

N

Node type

P

Node parameter type

Syntax:

C#
public abstract class RBTreeBase<T, N, P> : ISortedTree<T>, ITree<T>, IEnumerable where N : RBTreeNodeBase<T, P>, new()

Inheritance: objectRBTreeBase<T, N, P>

Derived Classes: RBMultiTree<T>RBOrderedTreeBase<T>RBTree<T>

Implements: IEnumerableISortedTree<T>ITree<T>

Constructors

Tree constructor

C#
public RBTreeBase(bool unique)
Parameters:uniquebool

Tree constructor with comparer

C#
public RBTreeBase(IComparer<T> aComparer, bool unique)
Parameters:aComparerIComparer<T>uniquebool

Fields

C#
protected int mCount
C#
protected RBTreeNodeBase<T, P> mRoot
C#
protected object mSyncRoot

Properties

Collection

IList<T>

Get collection object for this

C#
public IList<T> Collection { get; }

Number of nodes in the tree

C#
public int Count { get; }

Implements: ISortedTree<T>.Count

Root of the tree

C#
public N Root { get; }

Object can be used for synchronization

C#
public object SyncRoot { get; }

Implements: ITree<T>.SyncRoot

Is tree unique

C#
public bool Unique { get; }

Methods

Add new key into the tree

This operation is O(logN) operation

C#
public N Add(T aKey)
Parameters:aKeyTReturns:

N

Exceptions:

ArgumentException

In case the key is already in the tree

Add new key into the tree or get existing node This operation is O(logN) operation

C#
public N AddOrGet(T aKey)
Parameters:aKeyTReturns:

N

Balance tree past inserting

C#
protected void Balance(RBTreeNodeBase<T, P> z)
Parameters:zRBTreeNodeBase<T, P>

Remove all items

C#
public void Clear()

Delete the node z, and free up the space

C#
protected virtual void Delete(RBTreeNodeBase<T, P> z)
Parameters:zRBTreeNodeBase<T, P>

Restore the reb-black properties after a delete

C#
protected void DeleteFix(RBTreeNodeBase<T, P> x)
Parameters:xRBTreeNodeBase<T, P>

Find key in the dictionary This operation is O(logN) operation

C#
public N Find(T aKey)
Parameters:aKeyTReturns:

N

Get first node This operation is O(logN) operation

C#
public N First()
Returns:

N

Get last node This operation is O(logN) operation

C#
public N Last()
Returns:

N

Rotate our tree Left

        X        rb_left_rotate(X)--->            Y
      /   \                                     /   \
     A     Y                                   X     C
         /   \                               /   \
        B     C                             A     B

N.B. This does not change the ordering.

We assume that neither X or Y is NULL

C#
protected void LeftRotate(RBTreeNodeBase<T, P> x)
Parameters:xRBTreeNodeBase<T, P>

Create new node

C#
protected abstract RBTreeNodeBase<T, P> NewNode()
Returns:

RBTreeNodeBase<T, P>

Get next node This operation is O(logN) operation

C#
public N Next(N aNode)
Parameters:aNodeNReturns:

N

Return a pointer to the largest key smaller than x

C#
protected RBTreeNodeBase<T, P> Predecessor(RBTreeNodeBase<T, P> x)
Parameters:xRBTreeNodeBase<T, P>Returns:

RBTreeNodeBase<T, P>

Get previous node This operation is O(logN) operation

C#
public N Previous(N aNode)
Parameters:aNodeNReturns:

N

Remove node from the dictionary This operation is O(1) operation

C#
public bool Remove(N aNode)
Parameters:aNodeNReturns:

bool

Remove key from the dictionary This operation is O(logN) operation

C#
public bool Remove(T aKey)
Parameters:aKeyTReturns:

bool

Rotate our tree Right

        X                                         Y
      /   \                                     /   \
     A     Y     leftArrow--rb_right_rotate(Y)        X     C
         /   \                               /   \
        B     C                             A     B

N.B. This does not change the ordering.

We assume that neither X or Y is NULL

C#
protected void RightRotate(RBTreeNodeBase<T, P> y)
Parameters:yRBTreeNodeBase<T, P>

Return a pointer to the smallest key greater than x

C#
protected RBTreeNodeBase<T, P> Successor(RBTreeNodeBase<T, P> x)
Parameters:xRBTreeNodeBase<T, P>Returns:

RBTreeNodeBase<T, P>