annotate lib/gl_avltree_list.c @ 7139:adb21c293305

Add copyright notices to long-enough files that lack them, since otherwise the files aren't clearly free. Use the same notice that getdate.texi already uses. * doc/alloca-opt.texi: Add copyright notice. * doc/alloca.texi: Likewise. * doc/ctime.texi: Likewise. * doc/functions.texi: Likewise. * doc/gcd.texi: Likewise. * doc/gnulib-tool.texi: Likewise. * doc/inet_ntoa.texi: Likewise. * doc/visibility.texi: Likewise. Change copyright notice from LGPL 2 to GPL 2, since that's the standard form used in the gnulib repository. * lib/lock.c: LGPL -> GPL. * lib/lock.h: Likewise. * lib/strnlen1.c: Likewise. * lib/strnlen1.h: Likewise. * lib/tls.c: Likewise. * lib/tls.h: Likewise. * lib/tmpdir.c: Likewise. * tests/test-lock.c: Likewise. * tests/test-stdint.c: Likewise. * tests/test-tls.c: Likewise.
author Paul Eggert <eggert@cs.ucla.edu>
date Mon, 14 Aug 2006 22:19:54 +0000
parents 9ccb96800d02
children 1c4ed7637c24
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
6980
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
1 /* Sequential list data type implemented by a binary tree.
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
2 Copyright (C) 2006 Free Software Foundation, Inc.
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
3 Written by Bruno Haible <bruno@clisp.org>, 2006.
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
4
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
5 This program is free software; you can redistribute it and/or modify
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
6 it under the terms of the GNU General Public License as published by
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
7 the Free Software Foundation; either version 2, or (at your option)
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
8 any later version.
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
9
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
10 This program is distributed in the hope that it will be useful,
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
13 GNU General Public License for more details.
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
14
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
15 You should have received a copy of the GNU General Public License
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
16 along with this program; if not, write to the Free Software Foundation,
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
17 Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
18
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
19 #ifdef HAVE_CONFIG_H
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
20 # include <config.h>
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
21 #endif
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
22
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
23 /* Specification. */
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
24 #include "gl_avltree_list.h"
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
25
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
26 #include <stdlib.h>
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
27
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
28 #include "xalloc.h"
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
29
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
30 /* -------------------------- gl_list_t Data Type -------------------------- */
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
31
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
32 /* Generic AVL tree code. */
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
33 #include "gl_anyavltree_list1.h"
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
34 #include "gl_anyavltree_list2.h"
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
35
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
36 /* Generic binary tree code. */
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
37 #include "gl_anytree_list1.h"
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
38 #include "gl_anytree_list2.h"
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
39
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
40 /* For debugging. */
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
41 static unsigned int
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
42 check_invariants (gl_list_node_t node, gl_list_node_t parent)
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
43 {
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
44 unsigned int left_height =
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
45 (node->left != NULL ? check_invariants (node->left, node) : 0);
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
46 unsigned int right_height =
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
47 (node->right != NULL ? check_invariants (node->right, node) : 0);
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
48 int balance = (int)right_height - (int)left_height;
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
49
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
50 if (!(node->parent == parent))
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
51 abort ();
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
52 if (!(node->branch_size
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
53 == (node->left != NULL ? node->left->branch_size : 0)
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
54 + 1 + (node->right != NULL ? node->right->branch_size : 0)))
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
55 abort ();
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
56 if (!(balance >= -1 && balance <= 1))
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
57 abort ();
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
58 if (!(node->balance == balance))
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
59 abort ();
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
60
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
61 return 1 + (left_height > right_height ? left_height : right_height);
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
62 }
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
63 void
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
64 gl_avltree_list_check_invariants (gl_list_t list)
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
65 {
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
66 if (list->root != NULL)
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
67 check_invariants (list->root, NULL);
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
68 }
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
69
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
70 const struct gl_list_implementation gl_avltree_list_implementation =
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
71 {
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
72 gl_tree_create_empty,
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
73 gl_tree_create,
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
74 gl_tree_size,
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
75 gl_tree_node_value,
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
76 gl_tree_next_node,
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
77 gl_tree_previous_node,
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
78 gl_tree_get_at,
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
79 gl_tree_set_at,
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
80 gl_tree_search,
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
81 gl_tree_indexof,
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
82 gl_tree_add_first,
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
83 gl_tree_add_last,
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
84 gl_tree_add_before,
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
85 gl_tree_add_after,
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
86 gl_tree_add_at,
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
87 gl_tree_remove_node,
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
88 gl_tree_remove_at,
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
89 gl_tree_remove,
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
90 gl_tree_list_free,
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
91 gl_tree_iterator,
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
92 gl_tree_iterator_from_to,
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
93 gl_tree_iterator_next,
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
94 gl_tree_iterator_free,
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
95 gl_tree_sortedlist_search,
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
96 gl_tree_sortedlist_indexof,
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
97 gl_tree_sortedlist_add,
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
98 gl_tree_sortedlist_remove
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
99 };