openat: don’t close (-1)
[gnulib.git] / lib / gl_rbtree_oset.c
blobdcdfc966d4b96f5f51d52c97f1faf6a7310d8890
1 /* Ordered set data type implemented by a binary tree.
2 Copyright (C) 2006-2007, 2009-2024 Free Software Foundation, Inc.
3 Written by Bruno Haible <bruno@clisp.org>, 2006.
5 This file is free software: you can redistribute it and/or modify
6 it under the terms of the GNU Lesser General Public License as
7 published by the Free Software Foundation; either version 2.1 of the
8 License, or (at your option) any later version.
10 This file is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public License
16 along with this program. If not, see <https://www.gnu.org/licenses/>. */
18 #include <config.h>
20 /* Specification. */
21 #include "gl_rbtree_oset.h"
23 #include <stdlib.h>
25 /* -------------------------- gl_oset_t Data Type -------------------------- */
27 /* Parameterization of gl_rbtree_ordered.h. */
28 #define CONTAINER_T gl_oset_t
29 #define CONTAINER_IMPL gl_oset_impl
30 #define CONTAINER_IMPL_BASE gl_oset_impl_base
31 #define NODE_IMPL gl_oset_node_impl
32 #define NODE_T gl_oset_node_t
33 #define NODE_PAYLOAD_FIELDS \
34 const void *value;
35 #define NODE_PAYLOAD_PARAMS \
36 const void *elt
37 #define NODE_PAYLOAD_ASSIGN(node) \
38 node->value = elt;
39 #define NODE_PAYLOAD_DISPOSE(container, node) \
40 if (container->base.dispose_fn != NULL) \
41 container->base.dispose_fn (node->value);
43 #include "gl_rbtree_ordered.h"
45 /* Generic binary tree code. */
46 #include "gl_anytree_oset.h"
48 /* For debugging. */
49 extern void gl_rbtree_oset_check_invariants (gl_oset_t);
50 void
51 gl_rbtree_oset_check_invariants (gl_oset_t set)
53 size_t counter = 0;
54 if (set->root != NULL)
55 check_invariants (set->root, NULL, &counter);
56 if (!(set->count == counter))
57 abort ();
60 const struct gl_oset_implementation gl_rbtree_oset_implementation =
62 gl_tree_nx_create_empty,
63 gl_tree_size,
64 gl_tree_search,
65 gl_tree_search_atleast,
66 gl_tree_nx_add,
67 gl_tree_remove,
68 gl_tree_update,
69 gl_tree_oset_free,
70 gl_tree_iterator,
71 gl_tree_iterator_atleast,
72 gl_tree_iterator_next,
73 gl_tree_iterator_free