-
Notifications
You must be signed in to change notification settings - Fork 1.4k
/
Copy pathRedBlackTreeMapNode.cs
87 lines (73 loc) · 2.74 KB
/
RedBlackTreeMapNode.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
namespace DataStructures.Trees
{
/// <summary>
/// Red-Black Tree Map Node.
/// </summary>
public class RedBlackTreeMapNode<TKey, TValue> : BSTMapNode<TKey, TValue> where TKey : System.IComparable<TKey>
{
private RedBlackTreeColors _color;
/// <summary>
/// CONSTRUCTORS
/// </summary>
public RedBlackTreeMapNode(TKey key) : this(key, default(TValue), 0, null, null, null) { }
public RedBlackTreeMapNode(TKey key, TValue value) : this(key, value, 0, null, null, null) { }
public RedBlackTreeMapNode(TKey key, TValue value, int height, RedBlackTreeMapNode<TKey, TValue> parent, RedBlackTreeMapNode<TKey, TValue> left, RedBlackTreeMapNode<TKey, TValue> right)
{
Key = key;
Value = value;
Color = RedBlackTreeColors.Red;
Parent = parent;
LeftChild = left;
RightChild = right;
}
public virtual RedBlackTreeColors Color
{
get { return this._color; }
set { this._color = value; }
}
public new RedBlackTreeMapNode<TKey, TValue> Parent
{
get { return (RedBlackTreeMapNode<TKey, TValue>)base.Parent; }
set { base.Parent = value; }
}
public new RedBlackTreeMapNode<TKey, TValue> LeftChild
{
get { return (RedBlackTreeMapNode<TKey, TValue>)base.LeftChild; }
set { base.LeftChild = value; }
}
public new RedBlackTreeMapNode<TKey, TValue> RightChild
{
get { return (RedBlackTreeMapNode<TKey, TValue>)base.RightChild; }
set { base.RightChild = value; }
}
/******************************************************************************/
/// <summary>
/// Returns if this node is colored red.
/// </summary>
public virtual bool IsRed
{
get { return Color == RedBlackTreeColors.Red; }
}
/// <summary>
/// Checks whether this node is colored black.
/// </summary>
public virtual bool IsBlack
{
get { return Color == RedBlackTreeColors.Black; }
}
/// <summary>
/// Returns the sibling of this node.
/// </summary>
public virtual RedBlackTreeMapNode<TKey, TValue> Sibling
{
get { return (this.Parent == null ? null : (this.IsLeftChild ? this.Parent.RightChild : this.Parent.LeftChild)); }
}
/// <summary>
/// Returns the grandparent of this node.
/// </summary>
public virtual RedBlackTreeMapNode<TKey, TValue> GrandParent
{
get { return (this.Parent == null ? null : this.Parent.Parent); }
}
}
}