Lines Matching refs:table

3 /*--- A separately-chained hash table.               m_hashtable.c ---*/
49 Bool iterOK; // table safe to iterate over?
50 const HChar* name; // name of table (for debugging only)
72 VgHashTable table = VG_(calloc)("hashtable.Hc.1",
74 table->chains = VG_(calloc)("hashtable.Hc.2", 1, sz);
75 table->n_chains = n_chains;
76 table->n_elements = 0;
77 table->iterOK = True;
78 table->name = name;
80 return table;
83 Int VG_(HT_count_nodes) ( VgHashTable table )
85 return table->n_elements;
88 static void resize ( VgHashTable table )
92 SizeT old_chains = table->n_chains;
117 "resizing table `%s' from %lu to %lu (total elems %lu)\n",
118 table->name, (UWord)old_chains, (UWord)new_chains,
119 (UWord)table->n_elements );
121 table->n_chains = new_chains;
126 node = table->chains[i];
129 UWord chain = CHAIN_NO(node->key, table);
136 VG_(free)(table->chains);
137 table->chains = chains;
142 void VG_(HT_add_node) ( VgHashTable table, void* vnode )
145 UWord chain = CHAIN_NO(node->key, table);
146 node->next = table->chains[chain];
147 table->chains[chain] = node;
148 table->n_elements++;
149 if ( (1 * (ULong)table->n_elements) > (1 * (ULong)table->n_chains) ) {
150 resize(table);
154 table->iterOK = False;
157 /* Looks up a VgHashNode in the table. Returns NULL if not found. */
158 void* VG_(HT_lookup) ( VgHashTable table, UWord key )
160 VgHashNode* curr = table->chains[ CHAIN_NO(key, table) ];
171 /* Removes a VgHashNode from the table. Returns NULL if not found. */
172 void* VG_(HT_remove) ( VgHashTable table, UWord key )
174 UWord chain = CHAIN_NO(key, table);
175 VgHashNode* curr = table->chains[chain];
176 VgHashNode** prev_next_ptr = &(table->chains[chain]);
179 table->iterOK = False;
184 table->n_elements--;
197 VgHashNode** VG_(HT_to_array) ( VgHashTable table, /*OUT*/ UInt* n_elems )
203 *n_elems = table->n_elements;
210 for (i = 0; i < table->n_chains; i++) {
211 for (node = table->chains[i]; node != NULL; node = node->next) {
220 void VG_(HT_ResetIter)(VgHashTable table)
222 vg_assert(table);
223 table->iterNode = NULL;
224 table->iterChain = 0;
225 table->iterOK = True;
228 void* VG_(HT_Next)(VgHashTable table)
231 vg_assert(table);
234 table whilst iterating over it, which is a bug. */
235 vg_assert(table->iterOK);
237 if (table->iterNode && table->iterNode->next) {
238 table->iterNode = table->iterNode->next;
239 return table->iterNode;
242 for (i = table->iterChain; i < table->n_chains; i++) {
243 if (table->chains[i]) {
244 table->iterNode = table->chains[i];
245 table->iterChain = i + 1; // Next chain to be traversed
246 return table->iterNode;
252 void VG_(HT_destruct)(VgHashTable table, void(*freenode_fn)(void*))
257 for (i = 0; i < table->n_chains; i++) {
258 for (node = table->chains[i]; node != NULL; node = node_next) {
263 VG_(free)(table->chains);
264 VG_(free)(table);