sys_stat: Fix 'implicit declaration of function' warning on OS/2 kLIBC.
[gnulib.git] / lib / gl_linkedhash_list.c
blobefe4996b2b82a076d739545019f0032e46d677e4
1 /* Sequential list data type implemented by a hash table with a linked list.
2 Copyright (C) 2006, 2008-2019 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 3 of the License, or
8 (at your option) any later version.
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, see <https://www.gnu.org/licenses/>. */
18 #include <config.h>
20 /* Specification. */
21 #include "gl_linkedhash_list.h"
23 #include <stdint.h> /* for SIZE_MAX */
24 #include <stdlib.h>
26 #include "xsize.h"
28 #ifndef uintptr_t
29 # define uintptr_t unsigned long
30 #endif
32 #define WITH_HASHTABLE 1
34 /* -------------------------- gl_list_t Data Type -------------------------- */
36 /* Generic hash-table code. */
37 #include "gl_anyhash1.h"
39 /* Generic linked list code. */
40 #include "gl_anylinked_list1.h"
42 /* Generic hash-table code. */
43 #define CONTAINER_T gl_list_t
44 #define CONTAINER_COUNT(list) (list)->count
45 #include "gl_anyhash2.h"
47 /* Add a node to the hash table structure. */
48 static void
49 add_to_bucket (gl_list_t list, gl_list_node_t node)
51 size_t bucket = node->h.hashcode % list->table_size;
53 node->h.hash_next = list->table[bucket];
54 list->table[bucket] = &node->h;
56 /* Tell all compilers that the return value is 0. */
57 #define add_to_bucket(list,node) ((add_to_bucket) (list, node), 0)
59 /* Remove a node from the hash table structure. */
60 static void
61 remove_from_bucket (gl_list_t list, gl_list_node_t node)
63 size_t bucket = node->h.hashcode % list->table_size;
64 gl_hash_entry_t *p;
66 for (p = &list->table[bucket]; ; p = &(*p)->hash_next)
68 if (*p == &node->h)
70 *p = node->h.hash_next;
71 break;
73 if (*p == NULL)
74 /* node is not in the right bucket. Did the hash codes
75 change inadvertently? */
76 abort ();
80 /* Generic linked list code. */
81 #include "gl_anylinked_list2.h"
84 const struct gl_list_implementation gl_linkedhash_list_implementation =
86 gl_linked_nx_create_empty,
87 gl_linked_nx_create,
88 gl_linked_size,
89 gl_linked_node_value,
90 gl_linked_node_nx_set_value,
91 gl_linked_next_node,
92 gl_linked_previous_node,
93 gl_linked_get_at,
94 gl_linked_nx_set_at,
95 gl_linked_search_from_to,
96 gl_linked_indexof_from_to,
97 gl_linked_nx_add_first,
98 gl_linked_nx_add_last,
99 gl_linked_nx_add_before,
100 gl_linked_nx_add_after,
101 gl_linked_nx_add_at,
102 gl_linked_remove_node,
103 gl_linked_remove_at,
104 gl_linked_remove,
105 gl_linked_list_free,
106 gl_linked_iterator,
107 gl_linked_iterator_from_to,
108 gl_linked_iterator_next,
109 gl_linked_iterator_free,
110 gl_linked_sortedlist_search,
111 gl_linked_sortedlist_search_from_to,
112 gl_linked_sortedlist_indexof,
113 gl_linked_sortedlist_indexof_from_to,
114 gl_linked_sortedlist_nx_add,
115 gl_linked_sortedlist_remove