MySQL 8.4.2
Source Code Documentation
|
Various utilities. More...
Go to the source code of this file.
Classes | |
struct | ib_rbt_node_t |
Red black tree node. More... | |
struct | ib_rbt_t |
Red black tree instance. More... | |
struct | ib_rbt_bound_t |
The result of searching for a key in the tree, this is useful for a speedy lookup and insert if key doesn't exist. More... | |
Macros | |
#define | rbt_size(t) (t->n_nodes) |
#define | rbt_empty(t) (rbt_size(t) == 0) |
#define | rbt_value(t, n) ((t *)&n->value[0]) |
#define | rbt_compare(t, k, n) (t->compare(k, n->value)) |
Typedefs | |
typedef void(* | ib_rbt_print_node) (const ib_rbt_node_t *node) |
typedef int(* | ib_rbt_compare) (const void *p1, const void *p2) |
typedef int(* | ib_rbt_arg_compare) (const void *, const void *p1, const void *p2) |
Enumerations | |
enum | ib_rbt_color_t { IB_RBT_RED , IB_RBT_BLACK } |
Red black tree color types. More... | |
Functions | |
void | rbt_free (ib_rbt_t *tree) |
Free an instance of a red black tree. More... | |
ib_rbt_t * | rbt_create (size_t sizeof_value, ib_rbt_compare compare) |
Create an instance of a red black tree. More... | |
ib_rbt_t * | rbt_create_arg_cmp (size_t sizeof_value, ib_rbt_arg_compare compare, void *cmp_arg) |
Create an instance of a red black tree, whose comparison function takes an argument. More... | |
bool | rbt_delete (ib_rbt_t *tree, const void *key) |
Delete a node from the red black tree, identified by key. More... | |
ib_rbt_node_t * | rbt_remove_node (ib_rbt_t *tree, const ib_rbt_node_t *node) |
Remove a node from the red black tree, NOTE: This function will not delete the node instance, THAT IS THE CALLERS RESPONSIBILITY. More... | |
const ib_rbt_node_t * | rbt_insert (ib_rbt_t *tree, const void *key, const void *value) |
Add data to the red black tree, identified by key (no dups yet!) More... | |
const ib_rbt_node_t * | rbt_add_node (ib_rbt_t *tree, ib_rbt_bound_t *parent, const void *value) |
Add a new node to the tree, useful for data that is pre-sorted. More... | |
const ib_rbt_node_t * | rbt_first (const ib_rbt_t *tree) |
Return the left most data node in the tree. More... | |
const ib_rbt_node_t * | rbt_last (const ib_rbt_t *tree) |
Return the right most data node in the tree. More... | |
const ib_rbt_node_t * | rbt_next (const ib_rbt_t *tree, const ib_rbt_node_t *current) |
Return the next node from current. More... | |
const ib_rbt_node_t * | rbt_prev (const ib_rbt_t *tree, const ib_rbt_node_t *current) |
Return the prev node from current. More... | |
int | rbt_search (const ib_rbt_t *tree, ib_rbt_bound_t *parent, const void *key) |
Search for the key, a node will be returned in parent.last, whether it was found or not. More... | |
int | rbt_search_cmp (const ib_rbt_t *tree, ib_rbt_bound_t *parent, const void *key, ib_rbt_compare compare, ib_rbt_arg_compare arg_compare) |
Search for the key, a node will be returned in parent.last, whether it was found or not. More... | |
ulint | rbt_merge_uniq (ib_rbt_t *dst, const ib_rbt_t *src) |
Merge the node from dst into src. More... | |
bool | rbt_validate (const ib_rbt_t *tree) |
Verify the integrity of the RB tree. More... | |
Various utilities.
Created 2007-03-20 Sunny Bains
#define rbt_empty | ( | t | ) | (rbt_size(t) == 0) |
#define rbt_size | ( | t | ) | (t->n_nodes) |
typedef int(* ib_rbt_arg_compare) (const void *, const void *p1, const void *p2) |
typedef int(* ib_rbt_compare) (const void *p1, const void *p2) |
typedef void(* ib_rbt_print_node) (const ib_rbt_node_t *node) |
enum ib_rbt_color_t |
const ib_rbt_node_t * rbt_add_node | ( | ib_rbt_t * | tree, |
ib_rbt_bound_t * | parent, | ||
const void * | value | ||
) |
Add a new node to the tree, useful for data that is pre-sorted.
tree | in: rb tree |
parent | in: bounds |
value | in: this value is copied to the node |
ib_rbt_t * rbt_create | ( | size_t | sizeof_value, |
ib_rbt_compare | compare | ||
) |
Create an instance of a red black tree.
sizeof_value | in: sizeof data item |
compare | in: fn to compare items |
ib_rbt_t * rbt_create_arg_cmp | ( | size_t | sizeof_value, |
ib_rbt_arg_compare | compare, | ||
void * | cmp_arg | ||
) |
Create an instance of a red black tree, whose comparison function takes an argument.
sizeof_value | in: sizeof data item |
compare | in: fn to compare items |
cmp_arg | in: compare fn arg |
bool rbt_delete | ( | ib_rbt_t * | tree, |
const void * | key | ||
) |
Delete a node from the red black tree, identified by key.
Delete a node from the red black tree, identified by key.
tree | in: rb tree |
key | in: key to delete |
const ib_rbt_node_t * rbt_first | ( | const ib_rbt_t * | tree | ) |
Return the left most data node in the tree.
Return the left most data node in the tree.
void rbt_free | ( | ib_rbt_t * | tree | ) |
Free an instance of a red black tree.
in: rb tree to free
Free an instance of a red black tree.
tree | in: rb tree to free |
const ib_rbt_node_t * rbt_insert | ( | ib_rbt_t * | tree, |
const void * | key, | ||
const void * | value | ||
) |
Add data to the red black tree, identified by key (no dups yet!)
Add data to the red black tree, identified by key (no dups yet!)
tree | in: rb tree |
key | in: key for ordering |
value | in: value of key, this value is copied to the node |
const ib_rbt_node_t * rbt_last | ( | const ib_rbt_t * | tree | ) |
Return the right most data node in the tree.
Return the right most data node in the tree.
tree | in: rb tree |
Merge the node from dst into src.
Return the number of nodes merged.
Return the number of nodes merged.
dst | in: dst rb tree |
src | in: src rb tree |
const ib_rbt_node_t * rbt_next | ( | const ib_rbt_t * | tree, |
const ib_rbt_node_t * | current | ||
) |
Return the next node from current.
Return the next node from current.
tree | in: rb tree |
current | in: current node |
const ib_rbt_node_t * rbt_prev | ( | const ib_rbt_t * | tree, |
const ib_rbt_node_t * | current | ||
) |
Return the prev node from current.
Return the prev node from current.
tree | in: rb tree |
current | in: current node |
ib_rbt_node_t * rbt_remove_node | ( | ib_rbt_t * | tree, |
const ib_rbt_node_t * | const_node | ||
) |
Remove a node from the red black tree, NOTE: This function will not delete the node instance, THAT IS THE CALLERS RESPONSIBILITY.
Remove a node from the red black tree, NOTE: This function will not delete the node instance, THAT IS THE CALLERS RESPONSIBILITY.
tree | in: rb tree |
const_node | in: node to delete, this is a fudge and declared const because the caller can access only const nodes |
int rbt_search | ( | const ib_rbt_t * | tree, |
ib_rbt_bound_t * | parent, | ||
const void * | key | ||
) |
Search for the key, a node will be returned in parent.last, whether it was found or not.
If not found then parent.last will contain the parent node for the possibly new key otherwise the matching node.
Search for the key, a node will be returned in parent.last, whether it was found or not.
tree | in: rb tree |
parent | in: search bounds |
key | in: key to search |
int rbt_search_cmp | ( | const ib_rbt_t * | tree, |
ib_rbt_bound_t * | parent, | ||
const void * | key, | ||
ib_rbt_compare | compare, | ||
ib_rbt_arg_compare | arg_compare | ||
) |
Search for the key, a node will be returned in parent.last, whether it was found or not.
If not found then parent.last will contain the parent node for the possibly new key otherwise the matching node.
Search for the key, a node will be returned in parent.last, whether it was found or not.
But use the supplied comparison function.
tree | in: rb tree |
parent | in: search bounds |
key | in: key to search |
compare | in: fn to compare items |
arg_compare | in: fn to compare items with argument |
bool rbt_validate | ( | const ib_rbt_t * | tree | ) |
Verify the integrity of the RB tree.
For debugging. 0 failure else height of tree (in count of black nodes).
Verify the integrity of the RB tree.
tree | in: RB tree to validate |