annotate lib/gl_linkedhash_map.c @ 40186:8964917f9574

autoupdate
author Karl Berry <karl@freefriends.org>
date Mon, 18 Feb 2019 08:02:49 -0800
parents b06060465f09
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
40019
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
1 /* Map data type implemented by a hash table with a linked list.
40057
b06060465f09 maint: Run 'make update-copyright'
Paul Eggert <eggert@cs.ucla.edu>
parents: 40019
diff changeset
2 Copyright (C) 2006, 2008-2019 Free Software Foundation, Inc.
40019
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
3 Written by Bruno Haible <bruno@clisp.org>, 2018.
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
4
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
5 This program is free software: you can redistribute it and/or modify
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
6 it under the terms of the GNU General Public License as published by
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
7 the Free Software Foundation; either version 3 of the License, or
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
8 (at your option) any later version.
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
9
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
10 This program is distributed in the hope that it will be useful,
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
13 GNU General Public License for more details.
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
14
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
15 You should have received a copy of the GNU General Public License
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
16 along with this program. If not, see <https://www.gnu.org/licenses/>. */
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
17
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
18 #include <config.h>
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
19
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
20 /* Specification. */
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
21 #include "gl_linkedhash_map.h"
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
22
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
23 #include <stdint.h> /* for SIZE_MAX */
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
24 #include <stdlib.h>
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
25
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
26 #include "xsize.h"
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
27
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
28 #ifndef uintptr_t
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
29 # define uintptr_t unsigned long
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
30 #endif
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
31
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
32 /* --------------------------- gl_map_t Data Type --------------------------- */
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
33
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
34 #include "gl_anyhash1.h"
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
35
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
36 /* Concrete list node implementation, valid for this file only. */
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
37 struct gl_list_node_impl
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
38 {
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
39 struct gl_hash_entry h; /* hash table entry fields; must be first */
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
40 struct gl_list_node_impl *next;
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
41 struct gl_list_node_impl *prev;
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
42 const void *key;
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
43 const void *value;
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
44 };
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
45 typedef struct gl_list_node_impl * gl_list_node_t;
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
46
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
47 /* Concrete gl_map_impl type, valid for this file only. */
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
48 struct gl_map_impl
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
49 {
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
50 struct gl_map_impl_base base;
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
51 gl_mapkey_hashcode_fn hashcode_fn;
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
52 /* A hash table: managed as an array of collision lists. */
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
53 struct gl_hash_entry **table;
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
54 size_t table_size;
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
55 /* A circular list anchored at root.
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
56 The first node is = root.next, the last node is = root.prev.
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
57 The root's value is unused. */
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
58 struct gl_list_node_impl root;
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
59 /* Number of list nodes, excluding the root. */
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
60 size_t count;
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
61 };
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
62
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
63 #define CONTAINER_T gl_map_t
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
64 #define CONTAINER_COUNT(map) (map)->count
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
65 #include "gl_anyhash2.h"
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
66
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
67 /* If the symbol SIGNAL_SAFE_MAP is defined, the code is compiled in such
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
68 a way that a gl_map_t data structure may be used from within a signal
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
69 handler. The operations allowed in the signal handler are:
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
70 gl_map_iterator, gl_map_iterator_next, gl_map_iterator_free.
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
71 The map and node fields that are therefore accessed from the signal handler
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
72 are:
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
73 map->root, node->next, node->value.
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
74 We are careful to make modifications to these fields only in an order
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
75 that maintains the consistency of the list data structure at any moment,
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
76 and we use 'volatile' assignments to prevent the compiler from reordering
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
77 such assignments. */
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
78 #ifdef SIGNAL_SAFE_MAP
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
79 # define ASYNCSAFE(type) *(type volatile *)&
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
80 #else
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
81 # define ASYNCSAFE(type)
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
82 #endif
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
83
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
84 /* --------------------------- gl_map_t Data Type --------------------------- */
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
85
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
86 static gl_map_t
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
87 gl_linkedhash_nx_create_empty (gl_map_implementation_t implementation,
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
88 gl_mapkey_equals_fn equals_fn,
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
89 gl_mapkey_hashcode_fn hashcode_fn,
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
90 gl_mapkey_dispose_fn kdispose_fn,
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
91 gl_mapvalue_dispose_fn vdispose_fn)
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
92 {
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
93 struct gl_map_impl *map =
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
94 (struct gl_map_impl *) malloc (sizeof (struct gl_map_impl));
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
95
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
96 if (map == NULL)
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
97 return NULL;
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
98
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
99 map->base.vtable = implementation;
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
100 map->base.equals_fn = equals_fn;
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
101 map->base.kdispose_fn = kdispose_fn;
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
102 map->base.vdispose_fn = vdispose_fn;
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
103 map->hashcode_fn = hashcode_fn;
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
104 map->table_size = 11;
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
105 map->table =
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
106 (gl_hash_entry_t *) calloc (map->table_size, sizeof (gl_hash_entry_t));
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
107 if (map->table == NULL)
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
108 goto fail;
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
109 map->root.next = &map->root;
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
110 map->root.prev = &map->root;
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
111 map->count = 0;
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
112
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
113 return map;
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
114
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
115 fail:
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
116 free (map);
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
117 return NULL;
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
118 }
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
119
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
120 static size_t _GL_ATTRIBUTE_PURE
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
121 gl_linkedhash_size (gl_map_t map)
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
122 {
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
123 return map->count;
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
124 }
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
125
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
126 static bool _GL_ATTRIBUTE_PURE
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
127 gl_linkedhash_search (gl_map_t map, const void *key, const void **valuep)
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
128 {
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
129 size_t hashcode =
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
130 (map->hashcode_fn != NULL
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
131 ? map->hashcode_fn (key)
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
132 : (size_t)(uintptr_t) key);
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
133 size_t bucket = hashcode % map->table_size;
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
134 gl_mapkey_equals_fn equals = map->base.equals_fn;
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
135
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
136 /* Look for a match in the hash bucket. */
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
137 gl_list_node_t node;
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
138
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
139 for (node = (gl_list_node_t) map->table[bucket];
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
140 node != NULL;
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
141 node = (gl_list_node_t) node->h.hash_next)
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
142 if (node->h.hashcode == hashcode
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
143 && (equals != NULL
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
144 ? equals (key, node->key)
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
145 : key == node->key))
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
146 {
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
147 *valuep = node->value;
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
148 return true;
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
149 }
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
150 return false;
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
151 }
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
152
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
153 static int
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
154 gl_linkedhash_nx_getput (gl_map_t map, const void *key, const void *value,
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
155 const void **oldvaluep)
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
156 {
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
157 size_t hashcode =
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
158 (map->hashcode_fn != NULL
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
159 ? map->hashcode_fn (key)
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
160 : (size_t)(uintptr_t) key);
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
161 size_t bucket = hashcode % map->table_size;
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
162 gl_mapkey_equals_fn equals = map->base.equals_fn;
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
163
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
164 /* Look for a match in the hash bucket. */
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
165 {
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
166 gl_list_node_t node;
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
167
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
168 for (node = (gl_list_node_t) map->table[bucket];
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
169 node != NULL;
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
170 node = (gl_list_node_t) node->h.hash_next)
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
171 if (node->h.hashcode == hashcode
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
172 && (equals != NULL
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
173 ? equals (key, node->key)
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
174 : key == node->key))
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
175 {
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
176 *oldvaluep = node->value;
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
177 node->value = value;
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
178 return 0;
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
179 }
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
180 }
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
181
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
182 /* Allocate a new node. */
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
183 gl_list_node_t node =
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
184 (struct gl_list_node_impl *) malloc (sizeof (struct gl_list_node_impl));
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
185
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
186 if (node == NULL)
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
187 return -1;
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
188
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
189 ASYNCSAFE(const void *) node->key = key;
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
190 ASYNCSAFE(const void *) node->value = value;
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
191 node->h.hashcode = hashcode;
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
192
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
193 /* Add node to the hash table. */
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
194 node->h.hash_next = map->table[bucket];
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
195 map->table[bucket] = &node->h;
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
196
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
197 /* Add node to the map. */
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
198 ASYNCSAFE(gl_list_node_t) node->next = &map->root;
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
199 node->prev = map->root.prev;
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
200 ASYNCSAFE(gl_list_node_t) node->prev->next = node;
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
201 map->root.prev = node;
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
202 map->count++;
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
203
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
204 hash_resize_after_add (map);
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
205
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
206 return 1;
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
207 }
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
208
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
209 static bool
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
210 gl_linkedhash_getremove (gl_map_t map, const void *key, const void **oldvaluep)
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
211 {
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
212 size_t hashcode =
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
213 (map->hashcode_fn != NULL
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
214 ? map->hashcode_fn (key)
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
215 : (size_t)(uintptr_t) key);
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
216 size_t bucket = hashcode % map->table_size;
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
217 gl_mapkey_equals_fn equals = map->base.equals_fn;
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
218
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
219 /* Look for the first match in the hash bucket. */
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
220 gl_list_node_t *nodep;
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
221
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
222 for (nodep = (gl_list_node_t *) &map->table[bucket];
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
223 *nodep != NULL;
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
224 nodep = (gl_list_node_t *) &(*nodep)->h.hash_next)
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
225 {
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
226 gl_list_node_t node = *nodep;
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
227 if (node->h.hashcode == hashcode
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
228 && (equals != NULL
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
229 ? equals (key, node->key)
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
230 : key == node->key))
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
231 {
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
232 *oldvaluep = node->value;
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
233
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
234 /* Remove node from the hash table. */
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
235 *nodep = (gl_list_node_t) node->h.hash_next;
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
236
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
237 /* Remove node from the list. */
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
238 {
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
239 gl_list_node_t prev = node->prev;
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
240 gl_list_node_t next = node->next;
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
241
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
242 ASYNCSAFE(gl_list_node_t) prev->next = next;
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
243 next->prev = prev;
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
244 }
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
245 map->count--;
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
246
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
247 if (map->base.kdispose_fn != NULL)
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
248 map->base.kdispose_fn (node->key);
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
249 free (node);
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
250 return true;
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
251 }
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
252 }
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
253
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
254 return false;
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
255 }
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
256
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
257 static void
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
258 gl_linkedhash_free (gl_map_t map)
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
259 {
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
260 gl_mapkey_dispose_fn kdispose = map->base.kdispose_fn;
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
261 gl_mapvalue_dispose_fn vdispose = map->base.vdispose_fn;
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
262 gl_list_node_t node;
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
263
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
264 for (node = map->root.next; node != &map->root; )
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
265 {
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
266 gl_list_node_t next = node->next;
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
267 if (vdispose != NULL)
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
268 vdispose (node->value);
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
269 if (kdispose != NULL)
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
270 kdispose (node->key);
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
271 free (node);
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
272 node = next;
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
273 }
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
274 free (map->table);
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
275 free (map);
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
276 }
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
277
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
278 /* ---------------------- gl_map_iterator_t Data Type ---------------------- */
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
279
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
280 /* Iterate through the list, not through the hash buckets, so that the order
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
281 in which the pairs are returned is predictable. */
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
282
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
283 static gl_map_iterator_t
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
284 gl_linkedhash_iterator (gl_map_t map)
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
285 {
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
286 gl_map_iterator_t result;
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
287
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
288 result.vtable = map->base.vtable;
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
289 result.map = map;
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
290 result.p = map->root.next;
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
291 result.q = &map->root;
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
292 #if defined GCC_LINT || defined lint
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
293 result.i = 0;
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
294 result.j = 0;
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
295 result.count = 0;
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
296 #endif
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
297
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
298 return result;
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
299 }
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
300
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
301 static bool
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
302 gl_linkedhash_iterator_next (gl_map_iterator_t *iterator,
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
303 const void **keyp, const void **valuep)
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
304 {
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
305 if (iterator->p != iterator->q)
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
306 {
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
307 gl_list_node_t node = (gl_list_node_t) iterator->p;
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
308 *keyp = node->key;
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
309 *valuep = node->value;
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
310 iterator->p = node->next;
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
311 return true;
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
312 }
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
313 else
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
314 return false;
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
315 }
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
316
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
317 static void
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
318 gl_linkedhash_iterator_free (gl_map_iterator_t *iterator)
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
319 {
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
320 }
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
321
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
322
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
323 const struct gl_map_implementation gl_linkedhash_map_implementation =
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
324 {
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
325 gl_linkedhash_nx_create_empty,
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
326 gl_linkedhash_size,
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
327 gl_linkedhash_search,
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
328 gl_linkedhash_nx_getput,
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
329 gl_linkedhash_getremove,
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
330 gl_linkedhash_free,
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
331 gl_linkedhash_iterator,
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
332 gl_linkedhash_iterator_next,
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
333 gl_linkedhash_iterator_free
9e8db1cdf8c1 linkedhash-map: New module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
334 };