1
--- hashtable.c 2011-03-12 10:12:12.000000000 +0800
2
+++ hashtable.c89.c 2011-03-12 10:39:28.000000000 +0800
4
pgm_return_val_if_fail (NULL != hash_func, NULL);
5
pgm_return_val_if_fail (NULL != key_equal_func, NULL);
8
pgm_hashtable_t *hash_table;
10
hash_table = pgm_new (pgm_hashtable_t, 1);
12
hash_table->nodes = pgm_new0 (pgm_hashnode_t*, hash_table->size);
21
pgm_return_if_fail (hash_table != NULL);
23
- for (unsigned i = 0; i < hash_table->size; i++)
26
+ for (i = 0;i < hash_table->size; i++)
27
pgm_hash_nodes_destroy (hash_table->nodes[i]);
29
pgm_free (hash_table->nodes);
30
pgm_free (hash_table);
34
pgm_return_val_if_fail (hash_table != NULL, NULL);
37
const pgm_hashnode_t* node = *pgm_hashtable_lookup_node (hash_table, key, NULL);
38
return node ? node->value : NULL;
45
pgm_return_val_if_fail (hash_table != NULL, NULL);
48
const pgm_hashnode_t* node = *pgm_hashtable_lookup_node (hash_table, key, hash_return);
49
return node ? node->value : NULL;
56
pgm_return_if_fail (hash_table != NULL);
58
- for (unsigned i = 0; i < hash_table->size; i++)
61
+ for (i = 0; i < hash_table->size; i++)
63
pgm_hash_nodes_destroy (hash_table->nodes[i]);
64
hash_table->nodes[i] = NULL;
67
hash_table->nnodes = 0;
68
PGM_HASHTABLE_RESIZE (hash_table);
71
HASHTABLE_MIN_SIZE, HASHTABLE_MAX_SIZE);
72
pgm_hashnode_t** new_nodes = pgm_new0 (pgm_hashnode_t*, new_size);
74
- for (unsigned i = 0; i < hash_table->size; i++)
75
- for (pgm_hashnode_t *node = hash_table->nodes[i], *next; node; node = next)
78
+ for (i = 0; i < hash_table->size; i++)
80
+ pgm_hashnode_t *node, *next;
81
+ for (node = hash_table->nodes[i]; node; node = next)
85
const pgm_hash_t hash_val = node->key_hash % new_size;
86
node->next = new_nodes[hash_val];
87
new_nodes[hash_val] = node;
93
pgm_free (hash_table->nodes);
94
hash_table->nodes = new_nodes;