1 /* Sequential list data type implemented by a hash table with a binary tree.
2 Copyright (C) 2006 Free Software Foundation, Inc.
3 Written by Bruno Haible <bruno@clisp.org>, 2006.
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2, or (at your option)
10 This program 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 General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software Foundation,
17 Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
24 #include "gl_rbtreehash_list.h"
28 #include "gl_rbtree_oset.h"
34 # define uintptr_t unsigned long
37 #define WITH_HASHTABLE 1
39 /* Which kind of binary trees to use for ordered sets. Quite arbitrary. */
40 #define OSET_TREE_FLAVOR GL_RBTREE_OSET
42 /* -------------------------- gl_list_t Data Type -------------------------- */
44 /* Generic hash-table code: Type definitions. */
45 #include "gl_anyhash_list1.h"
47 /* Generic red-black tree code: Type definitions. */
48 #include "gl_anyrbtree_list1.h"
50 /* Generic hash-table code: Low-level code. */
51 #include "gl_anyhash_list2.h"
53 /* Generic binary tree code: Type definitions. */
54 #include "gl_anytree_list1.h"
56 /* Hash-table with binary tree code: Handling of hash buckets. */
57 #include "gl_anytreehash_list1.h"
59 /* Generic red-black tree code: Insertion/deletion algorithms. */
60 #include "gl_anyrbtree_list2.h"
62 /* Generic binary tree code: Functions taking advantage of the hash table. */
63 #include "gl_anytreehash_list2.h"
65 /* Generic binary tree code: All other functions. */
66 #include "gl_anytree_list2.h"
70 check_invariants (gl_list_node_t node, gl_list_node_t parent)
72 unsigned int left_blackheight =
73 (node->left != NULL ? check_invariants (node->left, node) : 0);
74 unsigned int right_blackheight =
75 (node->right != NULL ? check_invariants (node->right, node) : 0);
77 if (!(node->parent == parent))
79 if (!(node->branch_size
80 == (node->left != NULL ? node->left->branch_size : 0)
81 + 1 + (node->right != NULL ? node->right->branch_size : 0)))
83 if (!(node->color == BLACK || node->color == RED))
85 if (parent == NULL && !(node->color == BLACK))
87 if (!(left_blackheight == right_blackheight))
90 return left_blackheight + (node->color == BLACK ? 1 : 0);
93 gl_rbtreehash_list_check_invariants (gl_list_t list)
95 if (list->root != NULL)
96 check_invariants (list->root, NULL);
100 const struct gl_list_implementation gl_avltreehash_list_implementation =
102 gl_tree_create_empty,
107 gl_tree_previous_node,
122 gl_tree_iterator_from_to,
123 gl_tree_iterator_next,
124 gl_tree_iterator_free,
125 gl_tree_sortedlist_search,
126 gl_tree_sortedlist_indexof,
127 gl_tree_sortedlist_add,
128 gl_tree_sortedlist_remove