Remove rbtree_prefix from Red Black Tree.

(See commit on shared-pointer).

Rename rbntree_name_it_t into name_it_t.

Update tests, documentation, bench in accordance.
This commit is contained in:
Patrick Pelissier committed 2017-07-26 22:56:25 +02:00
1 parent 8f33273d7e
commit 7d2848e16a
5 files changed
+235 -226

No files matched your search

+44 -40
View File
@@ -1453,7 +1453,7 @@ for this function to be defined.
#### RBTREE\_DEF(name, type[, oplist])
Define the binary ordered tree 'rbtree\_##name##\_t' and its associated methods as "static inline" functions.
Define the binary ordered tree 'name##\_t' and its associated methods as "static inline" functions.
A binary tree is a tree data structure in which each node has at most two children, which are referred to as the left child and the right child.
In this kind of tree, all elements of the tree are totally ordered.
The current implementation is [RED-BLACK TREE](https://en.wikipedia.org/wiki/Red%E2%80%93black_tree).
@@ -1467,13 +1467,13 @@ pushed item already exist in the container. The default behavior
will overwrite the recorded value with the new one.
It shall be done once per type and per compilation unit.
It also define the iterator rbtree\_it\_##name##\_t and its associated methods as "static inline" functions.
It also define the iterator name##\_it\_t and its associated methods as "static inline" functions.
The object oplist is expected to have the following operators (INIT, INIT_SET, SET, CMP and CLEAR), otherwise default operators are used. If there is no given oplist, the default operators are also used. The created methods will use the operators to init, set and clear the contained object.
Example:
RBTREE_DEF(uint, unsigned int)
RBTREE_DEF(rbtree_uint, unsigned int)
void f(unsigned int num) {
rbtree_uint_t tree;
rbtree_uint_init(tree);
@@ -1482,161 +1482,165 @@ Example:
rbtree_uint_clear(tree);
}
#### RBTREE\_OPLIST(name [, oplist])
Return the oplist of the Red-Black defined by calling RBTREE\_DEF with name & oplist.
#### Created methods
The following methods are automatically and properly created by the previous macros.
In the following methods, name stands for the name given to the macro which is used to identify the type.
##### rbtree\_name\_t
##### name\_t
Type of the Red Black Tree of 'type'.
##### rbtree\_it\_name\_t
##### name\it_\_t
Type of an iterator over this Red Black Tree.
##### void rbtree\_name\_init(rbtree\_name\_t rbtree)
##### void name\_init(name\_t rbtree)
Initialize the Red Black Tree 'rbtree' to be empty.
##### void rbtree\_name\_clear(rbtree\_name\_t rbtree)
##### void name\_clear(name\_t rbtree)
Clear the Red Black Tree 'rbtree'.
##### void rbtree\_name\_init\_set(rbtree\_name\_t rbtree, const rbtree\_name\_t ref)
##### void name\_init\_set(name\_t rbtree, const name\_t ref)
Initialize the Red Black Tree 'rbtree' to be the same as 'ref'.
##### void rbtree\_name\_set(rbtree\_name\_t rbtree, const rbtree\_name\_t ref)
##### void name\_set(name\_t rbtree, const name\_t ref)
Set the Red Black Tree 'rbtree' to be the same as 'ref'.
##### void rbtree\_name\_init\_move(rbtree\_name\_t rbtree, rbtree\_name\_t ref)
##### void name\_init\_move(name\_t rbtree, name\_t ref)
Initialize the Red Black Tree 'rbtree' by stealing as resource as possible
from 'ref' and clear 'ref'.
##### void rbtree\_name\_move(rbtree\_name\_t rbtree, rbtree\_name\_t ref)
##### void name\_move(name\_t rbtree, name\_t ref)
Set the Red Black Tree 'rbtree' by stealing as resource as possible
from 'ref' and clear 'ref'.
##### void rbtree\_name\_clean(rbtree\_name\_t rbtree)
##### void name\_clean(name\_t rbtree)
Clean the Red Black Tree 'rbtree'. 'rbtree' remains initialized but empty.
##### size\_t rbtree\_name\_size(const rbtree\_name\_t rbtree)
##### size\_t name\_size(const name\_t rbtree)
Return the number of elements of the Red Black Tree.
##### void rbtree\_name\_push(rbtree\_name\_t rbtree, const type data)
##### void name\_push(name\_t rbtree, const type data)
Push 'data' into the Red Black Tree 'rbtree' at its ordered place
while keeping the tree balanced.
##### void rbtree\_name\_pop(type *dest, rbtree\_name\_t rbtree, const type data)
##### void name\_pop(type *dest, name\_t rbtree, const type data)
Pop 'data' from the Red Black Tree 'rbtree'
and save the poped value into 'dest' if the pointer is not null
while keeping the tree balanced.
Do nothing if 'data' is no present in the Red Black Tree.
##### type * rbtree\_name\_min(const rbtree\_name\_t rbtree)
##### const type * rbtree\_name\_cmin(const rbtree\_name\_t rbtree)
##### type * name\_min(const name\_t rbtree)
##### const type * name\_cmin(const name\_t rbtree)
Return a pointer to the minimum element of the tree
or NULL if there is no element.
##### type * rbtree\_name\_max(const rbtree\_name\_t rbtree)
##### const type * rbtree\_name\_cmax(const rbtree\_name\_t rbtree)
##### type * name\_max(const name\_t rbtree)
##### const type * name\_cmax(const name\_t rbtree)
Return a pointer to the maximum element of the tree
or NULL if there is no element.
##### type * rbtree\_name\_get(const rbtree\_name\_t rbtree, const type *data)
##### const type * rbtree\_name\_cget(const rbtree\_name\_t rbtree, const type *data)
##### type * name\_get(const name\_t rbtree, const type *data)
##### const type * name\_cget(const name\_t rbtree, const type *data)
Return a pointer to the element of the tree 'rbtree' which is equal to 'data',
or NULL if there is no match.
##### void rbtree\_name\_swap(rbtree\_name\_t rbtree1, rbtree\_name\_t rbtree2)
##### void name\_swap(name\_t rbtree1, name\_t rbtree2)
Swap both trees.
##### bool rbtree\_name\_empty\_p(const rbtree\_name\_t rbtree)
##### bool name\_empty\_p(const name\_t rbtree)
Return true if the tree is empty, false otherwise.
##### void rbtree\_name\_it(rbtree\_it\_name\_t it, rbtree\_name\_t rbtree)
##### void name\_it(name\it_\_t it, name\_t rbtree)
Set the iterator 'it' to the first element of 'rbtree'.
##### void rbtree\_name\_it\_set(rbtree\_it\_name\_t it, const rbtree\_it\_name\_t ref)
##### void name\_it\_set(name\it_\_t it, const name\it_\_t ref)
Set the iterator 'it' to the same element than 'ref'.
##### void rbtree\_name\_it\_last(rbtree\_it\_name\_t it, rbtree\_name\_t rbtree)
##### void name\_it\_last(name\it_\_t it, name\_t rbtree)
Set the iterator 'it' to the last element of 'rbtree'.
##### void rbtree\_name\_it\_end(rbtree\_it\_name\_t it, rbtree\_name\_t rbtree)
##### void name\_it\_end(name\it_\_t it, name\_t rbtree)
Set the iterator 'it' to no element of 'rbtree'.
##### void rbtree\_name\_it\_from(rbtree\_it\_name\_t it, const rbtree\_name\_t rbtree, const type data)
##### void name\_it\_from(name\it_\_t it, const name\_t rbtree, const type data)
Set the iterator 'it' to the greatest element of 'rbtree'
lower of equal than 'data' or the first element is there is none.
##### bool rbtree\_name\_end\_p(const rbtree\_it\_name\_t it)
##### bool name\_end\_p(const name\it_\_t it)
Return true if 'it' references no longer a valid element.
##### bool rbtree\_name\_last\_p(const rbtree\_it\_name\_t it)
##### bool name\_last\_p(const name\it_\_t it)
Return true if 'it' references the last element or is no longer valid.
##### bool rbtree\_name\_to\_p(const rbtree\_it\_name\_t it, const type data)
##### bool name\_to\_p(const name\it_\_t it, const type data)
Return true if 'it' references an element which is greater or equal than 'data'.
##### void rbtree\_name\_next(rbtree\_it\_name\_t it)
##### void name\_next(name\it_\_t it)
Update the iterator 'it' to the next element.
##### void rbtree\_name\_previous(rbtree\_it\_name\_t it)
##### void name\_previous(name\it_\_t it)
Update the iterator 'it' to the previous element.
##### type *rbtree\_name\_ref(rbtree\_it\_name\_t it)
##### const type *rbtree\_name\_ref(rbtree\_it\_name\_t it)
##### type *name\_ref(name\it_\_t it)
##### const type *name\_ref(name\it_\_t it)
Return a pointer to the element pointer by the iterator 'it'.
This pointer remains valid until the Red Black Tree is modified by another method.
##### void rbtree\_name\_get\_str(string\_t str, const rbtree\_name\_t rbtree, bool append)
##### void name\_get\_str(string\_t str, const name\_t rbtree, bool append)
Generate a string representation of the rbtree 'rbtree' and set 'str' to this representation
(if 'append' is false) or append 'str' with this representation (if 'append' is true).
This method is only defined if the type of the element defines a GET\_STR method itself.
##### void rbtree\_name\_out\_str(FILE *file, const rbtree\_name\_t rbtree)
##### void name\_out\_str(FILE *file, const name\_t rbtree)
Generate a string representation of the rbtree 'rbtree' and outputs it into the FILE 'file'.
This method is only defined if the type of the element defines a OUT\_STR method itself.
##### void rbtree\_name\_in\_str(FILE *file, const rbtree\_name\_t rbtree)
##### void name\_in\_str(FILE *file, const name\_t rbtree)
Read from the file 'file' a string representation of a rbtree and set 'rbtree' to this representation.
This method is only defined if the type of the element defines a IN\_STR method itself.
##### bool rbtree\_name\_equal\_p(const rbtree\_name\_t rbtree1, const rbtree\_name\_t rbtree2)
##### bool name\_equal\_p(const name\_t rbtree1, const name\_t rbtree2)
Return true if both rbtrees 'rbtree1' and 'rbtree2' are equal.
This method is only defined if the type of the element defines a EQUAL method itself.
##### size\_t rbtree\_name\_hash\_p(const rbtree\_name\_t rbtree)
##### size\_t name\_hash\_p(const name\_t rbtree)
Return the hash of the tree.
This method is only defined if the type of the element defines a HASH method itself.