10 struct list_head node;
12 char label[MAX_CHARS];
15 unsigned int hash_func(char *key, unsigned int modulus)
17 unsigned int hash = 0;
20 // loop while max_chars is not reached and a null character is not found
21 for (i=0; i < MAX_CHARS && key[i]!=0; i++) {
22 hash = (hash*37+ key[i]);
25 return (hash % modulus);
31 struct hash_table htable;
33 //struct item a = {{NULL, NULL}, 5, "FRESCOR"};
34 //struct item c = {{NULL, NULL}, 100, "FRSH"};
38 INIT_LIST_HEAD(&a.node);
40 strcpy(a.label,"FRESCOR");
42 INIT_LIST_HEAD(&c.node);
44 strcpy(c.label,"FRSH");
46 htable_init(&htable, 5);
48 hash = hash_func(a.label, htable.size);
49 printf("hash(a) = %d\n", hash);
50 htable_add(&htable, hash, &a.node);
52 hash = hash_func(c.label, htable.size);
53 printf("hash(b) = %d\n", hash);
54 htable_add(&htable, hash, &c.node);