summaryrefslogtreecommitdiff
path: root/ace/RB_Tree.i
blob: 3ddfee0f07904eb0c7305df3c0aaffcc117d86bd (plain)
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
/* -*- C++ -*- */
// $Id$

/////////////////////////////////////////////
// template class ACE_RB_Tree_Node<KEY, T> //
/////////////////////////////////////////////

// Key accessor.

template <class KEY, class T> ACE_INLINE KEY &
ACE_RB_Tree_Node<KEY, T>::key ()
{
  return k_;
}


// Item accessor.

template <class KEY, class T> ACE_INLINE T &
ACE_RB_Tree_Node<KEY, T>::item ()
{
  return t_;
}


// Set color of the node.

template <class KEY, class T> ACE_INLINE void
ACE_RB_Tree_Node<KEY, T>::color (ACE_RB_Tree_Node_Base::RB_Tree_Node_Color c)
{
  color_ = c;
}


// Get color of the node.

template <class KEY, class T>
ACE_INLINE ACE_RB_Tree_Node_Base::RB_Tree_Node_Color
ACE_RB_Tree_Node<KEY, T>::color ()
{
  return color_;
}


// Accessor for node's parent pointer.

template <class KEY, class T> ACE_INLINE ACE_RB_Tree_Node<KEY, T> *
ACE_RB_Tree_Node<KEY, T>::parent ()
{
  return parent_;
}


// Mutator for node's parent pointer.

template <class KEY, class T> ACE_INLINE void
ACE_RB_Tree_Node<KEY, T>::parent (ACE_RB_Tree_Node<KEY, T> * p)
{
  parent_ = p;
}
  


// Accessor for node's left child pointer.

template <class KEY, class T> ACE_INLINE ACE_RB_Tree_Node<KEY, T> *
ACE_RB_Tree_Node<KEY, T>::left ()
{
  return left_;
}


// Mutator for node's left child pointer.

template <class KEY, class T> ACE_INLINE void
ACE_RB_Tree_Node<KEY, T>::left (ACE_RB_Tree_Node<KEY, T> * l)
{
  left_ = l;
}


// Accessor for node's right child pointer.

template <class KEY, class T> ACE_INLINE ACE_RB_Tree_Node<KEY, T> *
ACE_RB_Tree_Node<KEY, T>::right ()
{
  return right_;
}


// Mutator for node's right child pointer.

template <class KEY, class T> ACE_INLINE void
ACE_RB_Tree_Node<KEY, T>::right (ACE_RB_Tree_Node<KEY, T> * r)
{
  right_ = r;
}



////////////////////////////////////////////////////////////////
// template class ACE_RB_Tree<KEY, T, COMPARE_KEYS, ACE_LOCK> //
////////////////////////////////////////////////////////////////


// Destroys all nodes and sets the root pointer null.

template <class KEY, class T, class COMPARE_KEYS, class ACE_LOCK> ACE_INLINE void
ACE_RB_Tree<KEY, T, COMPARE_KEYS, ACE_LOCK>::clear ()
{
  delete root_;
  root_ = 0;
}



//////////////////////////////////////////////////////////
// template class ACE_RB_Tree_Iterator<KEY, T, COMPARE_KEYS, ACE_LOCK> //
//////////////////////////////////////////////////////////


// Accessor for key of node under iterator (if any).

template <class KEY, class T, class COMPARE_KEYS, class ACE_LOCK> ACE_INLINE KEY *
ACE_RB_Tree_Iterator<KEY, T, COMPARE_KEYS, ACE_LOCK>::key ()
{
  return node_ ? (&(node_->key ())) : 0;
}


// Accessor for item of node under iterator (if any).

template <class KEY, class T, class COMPARE_KEYS, class ACE_LOCK> ACE_INLINE T *
ACE_RB_Tree_Iterator<KEY, T, COMPARE_KEYS, ACE_LOCK>::item ()
{
  return node_ ? (&(node_->item ())) : 0;
}


// Move to the first item in the tree.

template <class KEY, class T, class COMPARE_KEYS, class ACE_LOCK> ACE_INLINE int
ACE_RB_Tree_Iterator<KEY, T, COMPARE_KEYS, ACE_LOCK>::first ()
{
  node_ = tree_.RB_tree_minimum (tree_.root_);
  return node_ ? 1 : 0;
}


// Move to the last item in the tree.

template <class KEY, class T, class COMPARE_KEYS, class ACE_LOCK> ACE_INLINE int
ACE_RB_Tree_Iterator<KEY, T, COMPARE_KEYS, ACE_LOCK>::last ()
{
  node_ = tree_.RB_tree_maximum (tree_.root_);
  return node_ ? 1 : 0;
}


// Moves to the next item in the tree,
// returns 1 if there is a next item, 0 otherwise.

template <class KEY, class T, class COMPARE_KEYS, class ACE_LOCK> ACE_INLINE int
ACE_RB_Tree_Iterator<KEY, T, COMPARE_KEYS, ACE_LOCK>::next ()
{
  node_ = tree_.RB_tree_successor (node_);
  return node_ ? 1 : 0;
}


// Moves to the previous item in the tree,
// returns 1 if there is a previous item, 0 otherwise.

template <class KEY, class T, class COMPARE_KEYS, class ACE_LOCK> ACE_INLINE int
ACE_RB_Tree_Iterator<KEY, T, COMPARE_KEYS, ACE_LOCK>::previous ()
{
  node_ = tree_.RB_tree_predecessor (node_);
  return node_ ? 1 : 0;
}

template <class KEY, class T, class COMPARE_KEYS, class ACE_LOCK> ACE_INLINE int
ACE_RB_Tree_Iterator<KEY, T, COMPARE_KEYS, ACE_LOCK>::is_done ()
{
  return node_ ? 0 : 1;
}