exp2l: Work around a NetBSD 10.0/i386 bug.
[gnulib.git] / lib / gl_rbtree_omap.c
blob32e4bc62686289393373db45269c5caddaf1d61c
1 /* Ordered map 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>, 2018.
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_omap.h"
23 #include <stdlib.h>
25 /* -------------------------- gl_omap_t Data Type -------------------------- */
27 /* Parameterization of gl_rbtree_ordered.h. */
28 #define CONTAINER_T gl_omap_t
29 #define CONTAINER_IMPL gl_omap_impl
30 #define CONTAINER_IMPL_BASE gl_omap_impl_base
31 #define NODE_IMPL gl_omap_node_impl
32 #define NODE_T gl_omap_node_t
33 #define NODE_PAYLOAD_FIELDS \
34 const void *key; \
35 const void *value;
36 #define NODE_PAYLOAD_PARAMS \
37 const void *key, const void *value
38 #define NODE_PAYLOAD_ASSIGN(node) \
39 node->key = key; \
40 node->value = value;
41 #define NODE_PAYLOAD_DISPOSE(container, node) \
42 if (container->base.kdispose_fn != NULL) \
43 container->base.kdispose_fn (node->key);
45 #include "gl_rbtree_ordered.h"
47 /* Generic binary tree code. */
48 #include "gl_anytree_omap.h"
50 /* For debugging. */
51 extern void gl_rbtree_omap_check_invariants (gl_omap_t);
52 void
53 gl_rbtree_omap_check_invariants (gl_omap_t map)
55 size_t counter = 0;
56 if (map->root != NULL)
57 check_invariants (map->root, NULL, &counter);
58 if (!(map->count == counter))
59 abort ();
62 const struct gl_omap_implementation gl_rbtree_omap_implementation =
64 gl_tree_nx_create_empty,
65 gl_tree_size,
66 gl_tree_search,
67 gl_tree_search_atleast,
68 gl_tree_nx_getput,
69 gl_tree_getremove,
70 gl_tree_omap_free,
71 gl_tree_iterator,
72 gl_tree_iterator_next,
73 gl_tree_iterator_free