cxtree.h
/*
* This file is part of the ESO C Extension Library
* Copyright (C) 2001-2026 European Southern Observatory
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, see <https://www.gnu.org/licenses/>.
*/
#ifndef CX_TREE_H
#define CX_TREE_H
#include "cxtypes.h"
CX_BEGIN_DECLS
typedef struct _cx_tnode_ *cx_tree_iterator;
typedef const struct _cx_tnode_ *cx_tree_const_iterator;
typedef struct _cx_tree_ cx_tree;
typedef cxbool (*cx_tree_compare_func)(cxcptr, cxcptr);
/*
* Create, copy and destroy operations
*/
cx_tree *cx_tree_new(cx_tree_compare_func, cx_free_func, cx_free_func);
void cx_tree_delete(cx_tree *);
/*
* Nonmodifying operations
*/
cxsize cx_tree_size(const cx_tree *);
cxbool cx_tree_empty(const cx_tree *);
cxsize cx_tree_max_size(const cx_tree *);
cx_tree_compare_func cx_tree_key_comp(const cx_tree *);
/*
* Special search operations
*/
cxsize cx_tree_count(const cx_tree *, cxcptr);
cx_tree_iterator cx_tree_find(const cx_tree *, cxcptr);
cx_tree_iterator cx_tree_lower_bound(const cx_tree *, cxcptr);
cx_tree_iterator cx_tree_upper_bound(const cx_tree *, cxcptr);
void cx_tree_equal_range(const cx_tree *, cxcptr, cx_tree_iterator *,
cx_tree_iterator *);
/*
* Assignment operations
*/
void cx_tree_swap(cx_tree *, cx_tree *);
cxptr cx_tree_assign(cx_tree *, cx_tree_iterator, cxcptr);
/*
* Element access
*/
cxptr cx_tree_get_key(const cx_tree *, cx_tree_const_iterator);
cxptr cx_tree_get_value(const cx_tree *, cx_tree_const_iterator);
/*
* Iterator functions
*/
cx_tree_iterator cx_tree_begin(const cx_tree *);
cx_tree_iterator cx_tree_end(const cx_tree *);
cx_tree_iterator cx_tree_next(const cx_tree *, cx_tree_const_iterator);
cx_tree_iterator cx_tree_previous(const cx_tree *, cx_tree_const_iterator);
/*
* Inserting and removing elements
*/
cx_tree_iterator cx_tree_insert_unique(cx_tree *, cxcptr, cxcptr);
cx_tree_iterator cx_tree_insert_equal(cx_tree *, cxcptr, cxcptr);
void cx_tree_erase_position(cx_tree *, cx_tree_iterator);
void cx_tree_erase_range(cx_tree *, cx_tree_iterator, cx_tree_iterator);
cxsize cx_tree_erase(cx_tree *, cxcptr);
void cx_tree_clear(cx_tree *);
/*
* Debugging
*/
cxbool cx_tree_verify(const cx_tree *);
CX_END_DECLS
#endif /* CX_TREE_H */
cx_tree_insert_equal
cx_tree_iterator cx_tree_insert_equal(cx_tree *, cxcptr, cxcptr)
Insert data into a tree.
Definition cxtree.c:1600
cx_tree_compare_func
cxbool(* cx_tree_compare_func)(cxcptr, cxcptr)
The tree's key comparison operator function.
Definition cxtree.h:72
cx_tree_erase
cxsize cx_tree_erase(cx_tree *, cxcptr)
Erase all elements from a tree matching the provided key.
Definition cxtree.c:1690
cx_tree_empty
cxbool cx_tree_empty(const cx_tree *)
Check whether a tree is empty.
Definition cxtree.c:1119
cx_tree_insert_unique
cx_tree_iterator cx_tree_insert_unique(cx_tree *, cxcptr, cxcptr)
Attempt to insert data into a tree.
Definition cxtree.c:1575
cx_tree_lower_bound
cx_tree_iterator cx_tree_lower_bound(const cx_tree *, cxcptr)
Find the beginning of a subsequence.
Definition cxtree.c:1449
cx_tree_max_size
cxsize cx_tree_max_size(const cx_tree *)
Get the maximum number of pairs possible.
Definition cxtree.c:1234
cx_tree_clear
void cx_tree_clear(cx_tree *)
Remove all pairs from a tree.
Definition cxtree.c:1093
cx_tree_size
cxsize cx_tree_size(const cx_tree *)
Get the actual number of pairs in the tree.
Definition cxtree.c:1213
cx_tree_key_comp
cx_tree_compare_func cx_tree_key_comp(const cx_tree *)
Get the key comparison function.
Definition cxtree.c:1259
cx_tree_upper_bound
cx_tree_iterator cx_tree_upper_bound(const cx_tree *, cxcptr)
Find the end of a subsequence.
Definition cxtree.c:1476
cx_tree_get_value
cxptr cx_tree_get_value(const cx_tree *, cx_tree_const_iterator)
Get the data from a given iterator position.
Definition cxtree.c:1393
cx_tree_get_key
cxptr cx_tree_get_key(const cx_tree *, cx_tree_const_iterator)
Get the key from a given iterator position.
Definition cxtree.c:1368
cx_tree_delete
void cx_tree_delete(cx_tree *)
Destroy a tree and all its elements.
Definition cxtree.c:1189
cx_tree_assign
cxptr cx_tree_assign(cx_tree *, cx_tree_iterator, cxcptr)
Assign data to an iterator position.
Definition cxtree.c:1333
cx_tree_begin
cx_tree_iterator cx_tree_begin(const cx_tree *)
Get an iterator to the first pair in the tree.
Definition cxtree.c:983
cx_tree_new
cx_tree * cx_tree_new(cx_tree_compare_func, cx_free_func, cx_free_func)
Create a new tree without any elements.
Definition cxtree.c:1153
cx_tree_previous
cx_tree_iterator cx_tree_previous(const cx_tree *, cx_tree_const_iterator)
Get an iterator for the previous pair in the tree.
Definition cxtree.c:1064
cx_tree_next
cx_tree_iterator cx_tree_next(const cx_tree *, cx_tree_const_iterator)
Get an iterator for the next pair in the tree.
Definition cxtree.c:1032
cx_tree_equal_range
void cx_tree_equal_range(const cx_tree *, cxcptr, cx_tree_iterator *, cx_tree_iterator *)
Find a subsequence matching a given key.
Definition cxtree.c:1506
cx_tree_find
cx_tree_iterator cx_tree_find(const cx_tree *, cxcptr)
Locate an element in the tree.
Definition cxtree.c:1422
cx_tree_verify
cxbool cx_tree_verify(const cx_tree *)
Validate a tree.
Definition cxtree.c:1728
cx_tree_end
cx_tree_iterator cx_tree_end(const cx_tree *)
Get an iterator for the position after the last pair in the tree.
Definition cxtree.c:1007
cx_tree_erase_range
void cx_tree_erase_range(cx_tree *, cx_tree_iterator, cx_tree_iterator)
Erase a range of elements from a tree.
Definition cxtree.c:1657
cx_tree_erase_position
void cx_tree_erase_position(cx_tree *, cx_tree_iterator)
Erase an element from a tree.
Definition cxtree.c:1625
cx_tree_count
cxsize cx_tree_count(const cx_tree *, cxcptr)
Get the number of elements matching a key.
Definition cxtree.c:1532
cx_tree_swap
void cx_tree_swap(cx_tree *, cx_tree *)
Swap the contents of two trees.
Definition cxtree.c:1283