110
116
/* Compare a key with the node value (t is tree, k is key, n is node)*/
111
117
#define rbt_compare(t, k, n) (t->compare(k, n->value))
113
/****************************************************************//**
119
/**********************************************************************//**
114
120
Free an instance of a red black tree */
119
ib_rbt_t* tree); /*!< in: rb tree to free */
120
/****************************************************************//**
125
ib_rbt_t* tree); /*!< in: rb tree to free */
126
/**********************************************************************//**
121
127
Create an instance of a red black tree
122
128
@return rb tree instance */
127
size_t sizeof_value, /*!< in: size in bytes */
128
ib_rbt_compare compare); /*!< in: comparator */
129
/****************************************************************//**
130
Delete a node from the red black tree, identified by key.
131
@return TRUE if success FALSE if not found */
133
size_t sizeof_value, /*!< in: size in bytes */
134
ib_rbt_compare compare); /*!< in: comparator */
135
/**********************************************************************//**
136
Delete a node from the red black tree, identified by key */
136
ib_rbt_t* tree, /*!< in: rb tree */
137
const void* key); /*!< in: key to delete */
138
/****************************************************************//**
139
Remove a node from the rb tree, the node is not free'd, that is the
140
callers responsibility.
141
/* in: TRUE on success */
142
ib_rbt_t* tree, /* in: rb tree */
143
const void* key); /* in: key to delete */
144
/**********************************************************************//**
145
Remove a node from the red black tree, NOTE: This function will not delete
146
the node instance, THAT IS THE CALLERS RESPONSIBILITY.
141
147
@return the deleted node with the const. */
146
ib_rbt_t* tree, /*!< in: rb tree */
152
ib_rbt_t* tree, /*!< in: rb tree */
147
153
const ib_rbt_node_t*
148
node); /*!< in: node to delete, this
149
is a fudge and declared const
150
because the caller has access
151
only to const nodes.*/
152
/****************************************************************//**
153
Find a matching node in the rb tree.
154
node); /*!< in: node to delete, this
155
is a fudge and declared const
156
because the caller has access
157
only to const nodes.*/
158
/**********************************************************************//**
159
Return a node from the red black tree, identified by
160
key, NULL if not found
154
161
@return node if found else return NULL */
156
163
const ib_rbt_node_t*
159
const ib_rbt_t* tree, /*!< in: rb tree to search */
160
const void* key); /*!< in: key to lookup */
161
/****************************************************************//**
162
Generic insert of a value in the rb tree.
166
const ib_rbt_t* tree, /*!< in: rb tree to search */
167
const void* key); /*!< in: key to lookup */
168
/**********************************************************************//**
169
Add data to the red black tree, identified by key (no dups yet!)
163
170
@return inserted node */
165
172
const ib_rbt_node_t*
168
ib_rbt_t* tree, /*!< in: rb tree */
169
const void* key, /*!< in: key for ordering */
170
const void* value); /*!< in: data that will be
171
copied to the node.*/
172
/****************************************************************//**
175
ib_rbt_t* tree, /*!< in: rb tree */
176
const void* key, /*!< in: key for ordering */
177
const void* value); /*!< in: data that will be
178
copied to the node.*/
179
/**********************************************************************//**
173
180
Add a new node to the tree, useful for data that is pre-sorted.
174
181
@return appended node */
176
183
const ib_rbt_node_t*
179
ib_rbt_t* tree, /*!< in: rb tree */
180
ib_rbt_bound_t* parent, /*!< in: parent */
181
const void* value); /*!< in: this value is copied
183
/****************************************************************//**
186
ib_rbt_t* tree, /*!< in: rb tree */
187
ib_rbt_bound_t* parent, /*!< in: parent */
188
const void* value); /*!< in: this value is copied
190
/**********************************************************************//**
184
191
Return the left most data node in the tree
185
192
@return left most node */
187
194
const ib_rbt_node_t*
190
const ib_rbt_t* tree); /*!< in: rb tree */
191
/****************************************************************//**
197
const ib_rbt_t* tree); /*!< in: rb tree */
198
/**********************************************************************//**
192
199
Return the right most data node in the tree
193
200
@return right most node */
195
202
const ib_rbt_node_t*
198
const ib_rbt_t* tree); /*!< in: rb tree */
199
/****************************************************************//**
205
const ib_rbt_t* tree); /*!< in: rb tree */
206
/**********************************************************************//**
200
207
Return the next node from current.
201
208
@return successor node to current that is passed in. */
203
210
const ib_rbt_node_t*
206
const ib_rbt_t* tree, /*!< in: rb tree */
207
const ib_rbt_node_t* /*!< in: current node */
213
const ib_rbt_t* tree, /*!< in: rb tree */
214
const ib_rbt_node_t* /* in: current node */
209
/****************************************************************//**
216
/**********************************************************************//**
210
217
Return the prev node from current.
211
218
@return precedessor node to current that is passed in */
213
220
const ib_rbt_node_t*
216
const ib_rbt_t* tree, /*!< in: rb tree */
217
const ib_rbt_node_t* /*!< in: current node */
223
const ib_rbt_t* tree, /*!< in: rb tree */
224
const ib_rbt_node_t* /* in: current node */
219
/****************************************************************//**
226
/**********************************************************************//**
220
227
Find the node that has the lowest key that is >= key.
221
228
@return node that satisfies the lower bound constraint or NULL */
223
230
const ib_rbt_node_t*
226
const ib_rbt_t* tree, /*!< in: rb tree */
227
const void* key); /*!< in: key to search */
228
/****************************************************************//**
233
const ib_rbt_t* tree, /*!< in: rb tree */
234
const void* key); /*!< in: key to search */
235
/**********************************************************************//**
229
236
Find the node that has the greatest key that is <= key.
230
237
@return node that satisifies the upper bound constraint or NULL */
232
239
const ib_rbt_node_t*
235
const ib_rbt_t* tree, /*!< in: rb tree */
236
const void* key); /*!< in: key to search */
237
/****************************************************************//**
242
const ib_rbt_t* tree, /*!< in: rb tree */
243
const void* key); /*!< in: key to search */
244
/**********************************************************************//**
238
245
Search for the key, a node will be retuned in parent.last, whether it
239
246
was found or not. If not found then parent.last will contain the
240
247
parent node for the possibly new key otherwise the matching node.
258
const ib_rbt_t* tree, /*!< in: rb tree */
259
ib_rbt_bound_t* parent, /*!< in: search bounds */
260
const void* key, /*!< in: key to search */
261
ib_rbt_compare compare); /*!< in: comparator */
262
/****************************************************************//**
265
const ib_rbt_t* tree, /*!< in: rb tree */
266
ib_rbt_bound_t* parent, /*!< in: search bounds */
267
const void* key, /*!< in: key to search */
268
ib_rbt_compare compare); /*!< in: comparator */
269
/**********************************************************************//**
263
270
Clear the tree, deletes (and free's) all the nodes. */
268
ib_rbt_t* tree); /*!< in: rb tree */
269
/****************************************************************//**
275
ib_rbt_t* tree); /*!< in: rb tree */
276
/**********************************************************************//**
270
277
Merge the node from dst into src. Return the number of nodes merged.
271
278
@return no. of recs merged */
276
ib_rbt_t* dst, /*!< in: dst rb tree */
277
const ib_rbt_t* src); /*!< in: src rb tree */
278
/****************************************************************//**
283
ib_rbt_t* dst, /*!< in: dst rb tree */
284
const ib_rbt_t* src); /*!< in: src rb tree */
285
/**********************************************************************//**
279
286
Merge the node from dst into src. Return the number of nodes merged.
280
287
Delete the nodes from src after copying node to dst. As a side effect
281
288
the duplicates will be left untouched in the src, since we don't support