2 Copyright 2011-2016 David Robillard <http://drobilla.net>
4 Permission to use, copy, modify, and/or distribute this software for any
5 purpose with or without fee is hereby granted, provided that the above
6 copyright notice and this permission notice appear in all copies.
8 THIS SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
22 #include "zix/common.h"
40 typedef struct ZixBTreeImpl ZixBTree
;
43 A B-Tree node (opaque).
45 typedef struct ZixBTreeNodeImpl ZixBTreeNode
;
48 An iterator over a B-Tree.
50 Note that modifying the trees invalidates all iterators, so all iterators
53 typedef struct ZixBTreeIterImpl ZixBTreeIter
;
56 Create a new (empty) B-Tree.
59 zix_btree_new(ZixComparator cmp
,
61 ZixDestroyFunc destroy
);
67 zix_btree_free(ZixBTree
* t
);
70 Return the number of elements in `t`.
73 zix_btree_size(const ZixBTree
* t
);
76 Insert the element `e` into `t`.
79 zix_btree_insert(ZixBTree
* t
, void* e
);
82 Remove the value `e` from `t`.
84 @param t Tree to remove from.
86 @param e Value to remove.
88 @param out Set to point to the removed pointer (which may not equal `e`).
90 @param next If non-NULL, pointed to the value following `e`. If *next is
91 also non-NULL, the iterator is reused, otherwise a new one is allocated. To
92 reuse an iterator, no items may have been added since its creation.
95 zix_btree_remove(ZixBTree
* t
, const void* e
, void** out
, ZixBTreeIter
** next
);
98 Set `ti` to an element equal to `e` in `t`.
99 If no such item exists, `ti` is set to NULL.
102 zix_btree_find(const ZixBTree
* t
, const void* e
, ZixBTreeIter
** ti
);
105 Set `ti` to the smallest element in `t` that is not less than `e`.
107 Wildcards are supported, so if the search key `e` compares equal to many
108 values in the tree, `ti` will be set to the least such element. The search
109 key `e` is always passed as the second argument to the comparator.
112 zix_btree_lower_bound(const ZixBTree
* t
, const void* e
, ZixBTreeIter
** ti
);
115 Return the data associated with the given tree item.
118 zix_btree_get(const ZixBTreeIter
* ti
);
121 Return an iterator to the first (smallest) element in `t`.
123 The returned iterator must be freed with zix_btree_iter_free().
125 ZIX_API ZixBTreeIter
*
126 zix_btree_begin(const ZixBTree
* t
);
129 Return true iff `i` is an iterator to the end of its tree.
132 zix_btree_iter_is_end(const ZixBTreeIter
* i
);
135 Increment `i` to point to the next element in the tree.
138 zix_btree_iter_increment(ZixBTreeIter
* i
);
144 zix_btree_iter_free(ZixBTreeIter
* i
);
155 #endif /* ZIX_BTREE_H */