Low-level binary search tree manipulation module


Typedefs

typedef _gdsl_bintree_t _gdsl_bstree_t
 GDSL low-level binary search tree type.
typedef int(* _gdsl_bstree_map_func_t )(_gdsl_bstree_t TREE, void *USER_DATA)
 GDSL low-level binary search tree map function type.
typedef void(* _gdsl_bstree_write_func_t )(_gdsl_bstree_t TREE, FILE *OUTPUT_FILE, void *USER_DATA)
 GDSL low-level binary search tree write function type.

Functions

_gdsl_bstree_t _gdsl_bstree_alloc (const gdsl_element_t E)
 Create a new low-level binary search tree.
void _gdsl_bstree_free (_gdsl_bstree_t T, const gdsl_free_func_t FREE_F)
 Destroy a low-level binary search tree.
_gdsl_bstree_t _gdsl_bstree_copy (const _gdsl_bstree_t T, const gdsl_copy_func_t COPY_F)
 Copy a low-level binary search tree.
bool _gdsl_bstree_is_empty (const _gdsl_bstree_t T)
 Check if a low-level binary search tree is empty.
bool _gdsl_bstree_is_leaf (const _gdsl_bstree_t T)
 Check if a low-level binary search tree is reduced to a leaf.
gdsl_element_t _gdsl_bstree_get_content (const _gdsl_bstree_t T)
 Get the root content of a low-level binary search tree.
bool _gdsl_bstree_is_root (const _gdsl_bstree_t T)
 Check if a low-level binary search tree is a root.
_gdsl_bstree_t _gdsl_bstree_get_parent (const _gdsl_bstree_t T)
 Get the parent tree of a low-level binary search tree.
_gdsl_bstree_t _gdsl_bstree_get_left (const _gdsl_bstree_t T)
 Get the left sub-tree of a low-level binary search tree.
_gdsl_bstree_t _gdsl_bstree_get_right (const _gdsl_bstree_t T)
 Get the right sub-tree of a low-level binary search tree.
ulong _gdsl_bstree_get_size (const _gdsl_bstree_t T)
 Get the size of a low-level binary search tree.
ulong _gdsl_bstree_get_height (const _gdsl_bstree_t T)
 Get the height of a low-level binary search tree.
_gdsl_bstree_t _gdsl_bstree_insert (_gdsl_bstree_t *T, const gdsl_compare_func_t COMP_F, const gdsl_element_t VALUE, int *RESULT)
 Insert an element into a low-level binary search tree if it's not found or return it.
gdsl_element_t _gdsl_bstree_remove (_gdsl_bstree_t *T, const gdsl_compare_func_t COMP_F, const gdsl_element_t VALUE)
 Remove an element from a low-level binary search tree.
_gdsl_bstree_t _gdsl_bstree_search (const _gdsl_bstree_t T, const gdsl_compare_func_t COMP_F, const gdsl_element_t VALUE)
 Search for a particular element into a low-level binary search tree.
_gdsl_bstree_t _gdsl_bstree_search_next (const _gdsl_bstree_t T, const gdsl_compare_func_t COMP_F, const gdsl_element_t VALUE)
 Search for the next element of a particular element into a low-level binary search tree, according to the binary search tree order.
_gdsl_bstree_t _gdsl_bstree_map_prefix (const _gdsl_bstree_t T, const _gdsl_bstree_map_func_t MAP_F, void *USER_DATA)
 Parse a low-level binary search tree in prefixed order.
_gdsl_bstree_t _gdsl_bstree_map_infix (const _gdsl_bstree_t T, const _gdsl_bstree_map_func_t MAP_F, void *USER_DATA)
 Parse a low-level binary search tree in infixed order.
_gdsl_bstree_t _gdsl_bstree_map_postfix (const _gdsl_bstree_t T, const _gdsl_bstree_map_func_t MAP_F, void *USER_DATA)
 Parse a low-level binary search tree in postfixed order.
void _gdsl_bstree_write (const _gdsl_bstree_t T, const _gdsl_bstree_write_func_t WRITE_F, FILE *OUTPUT_FILE, void *USER_DATA)
 Write the content of all nodes of a low-level binary search tree to a file.
void _gdsl_bstree_write_xml (const _gdsl_bstree_t T, const _gdsl_bstree_write_func_t WRITE_F, FILE *OUTPUT_FILE, void *USER_DATA)
 Write the content of a low-level binary search tree to a file into XML.
void _gdsl_bstree_dump (const _gdsl_bstree_t T, const _gdsl_bstree_write_func_t WRITE_F, FILE *OUTPUT_FILE, void *USER_DATA)
 Dump the internal structure of a low-level binary search tree to a file.


Typedef Documentation

typedef _gdsl_bintree_t _gdsl_bstree_t
 

GDSL low-level binary search tree type.

This type is voluntary opaque. Variables of this kind could'nt be directly used, but by the functions of this module.

Definition at line 52 of file _gdsl_bstree.h.

typedef int(* _gdsl_bstree_map_func_t)(_gdsl_bstree_t TREE, void *USER_DATA)
 

GDSL low-level binary search tree map function type.

Parameters:
TREE The low-level binary search tree to map.
USER_DATA The user datas to pass to this function.
Returns:
GDSL_MAP_STOP if the mapping must be stopped.

GDSL_MAP_CONT if the mapping must be continued.

Definition at line 61 of file _gdsl_bstree.h.

typedef void(* _gdsl_bstree_write_func_t)(_gdsl_bstree_t TREE, FILE *OUTPUT_FILE, void *USER_DATA)
 

GDSL low-level binary search tree write function type.

Parameters:
TREE The low-level binary search tree to write.
OUTPUT_FILE The file where to write TREE.
USER_DATA The user datas to pass to this function.

Definition at line 71 of file _gdsl_bstree.h.


Function Documentation

_gdsl_bstree_t _gdsl_bstree_alloc const gdsl_element_t  E  ) 
 

Create a new low-level binary search tree.

Allocate a new low-level binary search tree data structure. Its root content is sets to E and its left and right sons are set to NULL.

Note:
Complexity: O( 1 )
Precondition:
nothing.
Parameters:
E The root content of the new low-level binary search tree to create.
Returns:
the newly allocated low-level binary search tree in case of success.

NULL in case of insufficient memory.

See also:
_gdsl_bstree_free()

void _gdsl_bstree_free _gdsl_bstree_t  T,
const gdsl_free_func_t  FREE_F
 

Destroy a low-level binary search tree.

Flush and destroy the low-level binary search tree T. If FREE_F != NULL, FREE_F function is used to deallocate each T's element. Otherwise nothing is done with T's elements.

Note:
Complexity: O( |T| )
Precondition:
nothing.
Parameters:
T The low-level binary search tree to destroy.
FREE_F The function used to deallocate T's nodes contents.
See also:
_gdsl_bstree_alloc()

_gdsl_bstree_t _gdsl_bstree_copy const _gdsl_bstree_t  T,
const gdsl_copy_func_t  COPY_F
 

Copy a low-level binary search tree.

Create and return a copy of the low-level binary search tree T using COPY_F on each T's element to copy them.

Note:
Complexity: O( |T| )
Precondition:
COPY_F != NULL.
Parameters:
T The low-level binary search tree to copy.
COPY_F The function used to copy T's nodes contents.
Returns:
a copy of T in case of success.

NULL if _gdsl_bstree_is_empty (T) == TRUE or in case of insufficient memory.

See also:
_gdsl_bstree_alloc()

_gdsl_bstree_free()

_gdsl_bstree_is_empty()

bool _gdsl_bstree_is_empty const _gdsl_bstree_t  T  ) 
 

Check if a low-level binary search tree is empty.

Note:
Complexity: O( 1 )
Precondition:
nothing.
Parameters:
T The low-level binary search tree to check.
Returns:
TRUE if the low-level binary search tree T is empty.

FALSE if the low-level binary search tree T is not empty.

See also:
_gdsl_bstree_is_leaf()

_gdsl_bstree_is_root()

bool _gdsl_bstree_is_leaf const _gdsl_bstree_t  T  ) 
 

Check if a low-level binary search tree is reduced to a leaf.

Note:
Complexity: O( 1 )
Precondition:
T must be a non-empty _gdsl_bstree_t.
Parameters:
T The low-level binary search tree to check.
Returns:
TRUE if the low-level binary search tree T is a leaf.

FALSE if the low-level binary search tree T is not a leaf.

See also:
_gdsl_bstree_is_empty()

_gdsl_bstree_is_root()

gdsl_element_t _gdsl_bstree_get_content const _gdsl_bstree_t  T  ) 
 

Get the root content of a low-level binary search tree.

Note:
Complexity: O( 1 )
Precondition:
T must be a non-empty _gdsl_bstree_t.
Parameters:
T The low-level binary search tree to use.
Returns:
the root's content of the low-level binary search tree T.

bool _gdsl_bstree_is_root const _gdsl_bstree_t  T  ) 
 

Check if a low-level binary search tree is a root.

Note:
Complexity: O( 1 )
Precondition:
T must be a non-empty _gdsl_bstree_t.
Parameters:
T The low-level binary search tree to check.
Returns:
TRUE if the low-level binary search tree T is a root.

FALSE if the low-level binary search tree T is not a root.

See also:
_gdsl_bstree_is_empty()

_gdsl_bstree_is_leaf()

_gdsl_bstree_t _gdsl_bstree_get_parent const _gdsl_bstree_t  T  ) 
 

Get the parent tree of a low-level binary search tree.

Note:
Complexity: O( 1 )
Precondition:
T must be a non-empty _gdsl_bstree_t.
Parameters:
T The low-level binary search tree to use.
Returns:
the parent of the low-level binary search tree T if T isn't a root.

NULL if the low-level binary search tree T is a root (ie. T has no parent).

See also:
_gdsl_bstree_is_root()

_gdsl_bstree_t _gdsl_bstree_get_left const _gdsl_bstree_t  T  ) 
 

Get the left sub-tree of a low-level binary search tree.

Note:
Complexity: O( 1 )
Precondition:
T must be a non-empty _gdsl_bstree_t.
Parameters:
T The low-level binary search tree to use.
Returns:
the left sub-tree of the low-level binary search tree T if T has a left sub-tree.

NULL if the low-level binary search tree T has no left sub-tree.

See also:
_gdsl_bstree_get_right()

_gdsl_bstree_t _gdsl_bstree_get_right const _gdsl_bstree_t  T  ) 
 

Get the right sub-tree of a low-level binary search tree.

Note:
Complexity: O( 1 )
Precondition:
T must be a non-empty _gdsl_bstree_t.
Parameters:
T The low-level binary search tree to use.
Returns:
the right sub-tree of the low-level binary search tree T if T has a right sub-tree.

NULL if the low-level binary search tree T has no right sub-tree.

See also:
_gdsl_bstree_get_left()

ulong _gdsl_bstree_get_size const _gdsl_bstree_t  T  ) 
 

Get the size of a low-level binary search tree.

Note:
Complexity: O( |T| )
Precondition:
nothing.
Parameters:
T The low-level binary search tree to compute the size from.
Returns:
the number of elements of T (noted |T|).
See also:
_gdsl_bstree_get_height()

ulong _gdsl_bstree_get_height const _gdsl_bstree_t  T  ) 
 

Get the height of a low-level binary search tree.

Compute the height of the low-level binary search tree T (noted h(T)).

Note:
Complexity: O( |T| )
Precondition:
nothing.
Parameters:
T The low-level binary search tree to compute the height from.
Returns:
the height of T.
See also:
_gdsl_bstree_get_size()

_gdsl_bstree_t _gdsl_bstree_insert _gdsl_bstree_t T,
const gdsl_compare_func_t  COMP_F,
const gdsl_element_t  VALUE,
int *  RESULT
 

Insert an element into a low-level binary search tree if it's not found or return it.

Search for the first element E equal to VALUE into the low-level binary search tree T, by using COMP_F function to find it. If an element E equal to VALUE is found, then it's returned. If no element equal to VALUE is found, then E is inserted and its root returned.

Note:
Complexity: O( h(T) ), where log2(|T|) <= h(T) <= |T|-1
Precondition:
COMP_F != NULL & RESULT != NULL.
Parameters:
T The reference of the low-level binary search tree to use.
COMP_F The comparison function to use to compare T's elements with VALUE to find E.
VALUE The value used to search for the element E.
RESULT The address where the result code will be stored.
Returns:
the root containing E and RESULT = GDSL_INSERTED if E is inserted.

the root containing E and RESULT = GDSL_ERR_DUPLICATE_ENTRY if E is not inserted.

NULL and RESULT = GDSL_ERR_MEM_ALLOC in case of failure.

See also:
_gdsl_bstree_search()

_gdsl_bstree_remove()

gdsl_element_t _gdsl_bstree_remove _gdsl_bstree_t T,
const gdsl_compare_func_t  COMP_F,
const gdsl_element_t  VALUE
 

Remove an element from a low-level binary search tree.

Remove from the low-level binary search tree T the first founded element E equal to VALUE, by using COMP_F function to compare T's elements. If E is found, it is removed from T.

Note:
Complexity: O( h(T) ), where log2(|T|) <= h(T) <= |T|-1

The resulting T is modified by examinating the left sub-tree from the founded e.

Precondition:
COMP_F != NULL.
Parameters:
T The reference of the low-level binary search tree to modify.
COMP_F The comparison function to use to compare T's elements with VALUE to find the element e to remove.
VALUE The value that must be used by COMP_F to find the element e to remove.
Returns:
the fisrt founded element equal to VALUE in T.

NULL if no element equal to VALUE is found or if T is empty.

See also:
_gdsl_bstree_insert()

_gdsl_bstree_search()

_gdsl_bstree_t _gdsl_bstree_search const _gdsl_bstree_t  T,
const gdsl_compare_func_t  COMP_F,
const gdsl_element_t  VALUE
 

Search for a particular element into a low-level binary search tree.

Search the first element E equal to VALUE in the low-level binary search tree T, by using COMP_F function to find it.

Note:
Complexity: O( h(T) ), where log2(|T|) <= h(T) <= |T|-1
Precondition:
COMP_F != NULL.
Parameters:
T The low-level binary search tree to use.
COMP_F The comparison function to use to compare T's elements with VALUE to find the element E.
VALUE The value that must be used by COMP_F to find the element E.
Returns:
the root of the tree containing E if it's found.

NULL if VALUE is not found in T.

See also:
_gdsl_bstree_insert()

_gdsl_bstree_remove()

_gdsl_bstree_t _gdsl_bstree_search_next const _gdsl_bstree_t  T,
const gdsl_compare_func_t  COMP_F,
const gdsl_element_t  VALUE
 

Search for the next element of a particular element into a low-level binary search tree, according to the binary search tree order.

Search for an element E in the low-level binary search tree T, by using COMP_F function to find the first element E equal to VALUE.

Note:
Complexity: O( h(T) ), where log2(|T|) <= h(T) <= |T|-1
Precondition:
COMP_F != NULL.
Parameters:
T The low-level binary search tree to use.
COMP_F The comparison function to use to compare T's elements with VALUE to find the element E.
VALUE The value that must be used by COMP_F to find the element E.
Returns:
the root of the tree containing the successor of E if it's found.

NULL if VALUE is not found in T or if E has no sucessor.

_gdsl_bstree_t _gdsl_bstree_map_prefix const _gdsl_bstree_t  T,
const _gdsl_bstree_map_func_t  MAP_F,
void *  USER_DATA
 

Parse a low-level binary search tree in prefixed order.

Parse all nodes of the low-level binary search tree T in prefixed order. The MAP_F function is called on each node with the USER_DATA argument. If MAP_F returns GDSL_MAP_STOP, then _gdsl_bstree_map_prefix() stops and returns its last examinated node.

Note:
Complexity: O( |T| )
Precondition:
MAP_F != NULL.
Parameters:
T The low-level binary search tree to map.
MAP_F The map function.
USER_DATA User's datas passed to MAP_F.
Returns:
the first node for which MAP_F returns GDSL_MAP_STOP.

NULL when the parsing is done.

See also:
_gdsl_bstree_map_infix()

_gdsl_bstree_map_postfix()

_gdsl_bstree_t _gdsl_bstree_map_infix const _gdsl_bstree_t  T,
const _gdsl_bstree_map_func_t  MAP_F,
void *  USER_DATA
 

Parse a low-level binary search tree in infixed order.

Parse all nodes of the low-level binary search tree T in infixed order. The MAP_F function is called on each node with the USER_DATA argument. If MAP_F returns GDSL_MAP_STOP, then _gdsl_bstree_map_infix() stops and returns its last examinated node.

Note:
Complexity: O( |T| )
Precondition:
MAP_F != NULL.
Parameters:
T The low-level binary search tree to map.
MAP_F The map function.
USER_DATA User's datas passed to MAP_F.
Returns:
the first node for which MAP_F returns GDSL_MAP_STOP.

NULL when the parsing is done.

See also:
_gdsl_bstree_map_prefix()

_gdsl_bstree_map_postfix()

_gdsl_bstree_t _gdsl_bstree_map_postfix const _gdsl_bstree_t  T,
const _gdsl_bstree_map_func_t  MAP_F,
void *  USER_DATA
 

Parse a low-level binary search tree in postfixed order.

Parse all nodes of the low-level binary search tree T in postfixed order. The MAP_F function is called on each node with the USER_DATA argument. If MAP_F returns GDSL_MAP_STOP, then _gdsl_bstree_map_postfix() stops and returns its last examinated node.

Note:
Complexity: O( |T| )
Precondition:
MAP_F != NULL.
Parameters:
T The low-level binary search tree to map.
MAP_F The map function.
USER_DATA User's datas passed to MAP_F.
Returns:
the first node for which MAP_F returns GDSL_MAP_STOP.

NULL when the parsing is done.

See also:
_gdsl_bstree_map_prefix()

_gdsl_bstree_map_infix()

void _gdsl_bstree_write const _gdsl_bstree_t  T,
const _gdsl_bstree_write_func_t  WRITE_F,
FILE *  OUTPUT_FILE,
void *  USER_DATA
 

Write the content of all nodes of a low-level binary search tree to a file.

Write the nodes contents of the low-level binary search tree T to OUTPUT_FILE, using WRITE_F function. Additionnal USER_DATA argument could be passed to WRITE_F.

Note:
Complexity: O( |T| )
Precondition:
WRITE_F != NULL& OUTPUT_FILE != NULL.
Parameters:
T The low-level binary search tree to write.
WRITE_F The write function.
OUTPUT_FILE The file where to write T's nodes.
USER_DATA User's datas passed to WRITE_F.
See also:
_gdsl_bstree_write_xml()

_gdsl_bstree_dump()

void _gdsl_bstree_write_xml const _gdsl_bstree_t  T,
const _gdsl_bstree_write_func_t  WRITE_F,
FILE *  OUTPUT_FILE,
void *  USER_DATA
 

Write the content of a low-level binary search tree to a file into XML.

Write the nodes contents of the low-level binary search tree T to OUTPUT_FILE, into XML language. If WRITE_F != NULL, then use WRITE_F function to write T's nodes contents to OUTPUT_FILE. Additionnal USER_DATA argument could be passed to WRITE_F.

Note:
Complexity: O( |T| )
Precondition:
OUTPUT_FILE != NULL.
Parameters:
T The low-level binary search tree to write.
WRITE_F The write function.
OUTPUT_FILE The file where to write T's nodes.
USER_DATA User's datas passed to WRITE_F.
See also:
_gdsl_bstree_write()

_gdsl_bstree_dump()

void _gdsl_bstree_dump const _gdsl_bstree_t  T,
const _gdsl_bstree_write_func_t  WRITE_F,
FILE *  OUTPUT_FILE,
void *  USER_DATA
 

Dump the internal structure of a low-level binary search tree to a file.

Dump the structure of the low-level binary search tree T to OUTPUT_FILE. If WRITE_F != NULL, then use WRITE_F function to write T's nodes content to OUTPUT_FILE. Additionnal USER_DATA argument could be passed to WRITE_F.

Note:
Complexity: O( |T| )
Precondition:
OUTPUT_FILE != NULL.
Parameters:
T The low-level binary search tree to dump.
WRITE_F The write function.
OUTPUT_FILE The file where to write T's nodes.
USER_DATA User's datas passed to WRITE_F.
See also:
_gdsl_bstree_write()

_gdsl_bstree_write_xml()


Generated on Thu Jun 22 11:15:30 2006 for gdsl by  doxygen 1.4.6