Lines Matching refs:hash
1 /* simple hash table
6 #include "hash.h"
10 hash_t *hash;
12 hash = malloc(sizeof(hash_t));
13 hash->table = calloc(size, sizeof(hash_entry_t *));
14 if (!hash || !hash->table){
18 hash->size = size;
20 return hash;
23 void hash_print(hash_t *hash)
28 printf("hash:%p\n", hash);
30 for (i = 0; i < hash->size; i++) {
32 for (curr = hash->table[i]; curr != NULL; curr = curr->next)
39 void hash_destroy(hash_t *hash)
43 for (i = 0; i < hash->size; i++) {
44 for (curr = hash->table[i]; curr != NULL; ) {
49 free(hash->table);
50 free(hash);
53 void hash_insert(hash_t *hash, unsigned long key, unsigned long val)
58 bucket = hash_fn(hash, key);
60 curr = hash->table[bucket];
76 new_entry->next = hash->table[bucket];
77 hash->table[bucket] = new_entry;
80 unsigned long hash_lookup(hash_t *hash, unsigned long key)
85 bucket = hash_fn(hash,key);
86 curr = hash->table[bucket];
102 unsigned long hash_delete(hash_t *hash, unsigned long key)
108 bucket = hash_fn(hash,key);
109 curr = hash->table[bucket];
126 if (curr == hash->table[bucket])
127 hash->table[bucket] = curr->next;
134 int hash_swap(hash_t *hash, unsigned long key1, unsigned long key2)
141 bucket = hash_fn(hash,key1);
142 entry1 = hash->table[bucket];
156 bucket = hash_fn(hash,key2);
157 entry2 = hash->table[bucket];