+++ /dev/null
-#include <stdio.h>
-#include "list.h"
-#include "hashtable.h"
-#include <string.h>
-
-
-#define MAX_CHARS 48
-
-struct item {
- struct list_head node;
- int value;
- char label[MAX_CHARS];
-};
-
-unsigned int hash_func(char *key, unsigned int modulus)
-{
- unsigned int hash = 0;
- int i;
-
- // loop while max_chars is not reached and a null character is not found
- for (i=0; i < MAX_CHARS && key[i]!=0; i++) {
- hash = (hash*37+ key[i]);
- }
-
- return (hash % modulus);
-}
-
-
-int main()
-{
- struct hash_table htable;
- struct item a,c;
- //struct item a = {{NULL, NULL}, 5, "FRESCOR"};
- //struct item c = {{NULL, NULL}, 100, "FRSH"};
-
- unsigned int hash;
-
- INIT_LIST_HEAD(&a.node);
- a.value = 5;
- strcpy(a.label,"FRESCOR");
-
- INIT_LIST_HEAD(&c.node);
- c.value = 100;
- strcpy(c.label,"FRSH");
-
- htable_init(&htable, 5);
-
- hash = hash_func(a.label, htable.size);
- printf("hash(a) = %d\n", hash);
- htable_add(&htable, hash, &a.node);
-
- hash = hash_func(c.label, htable.size);
- printf("hash(b) = %d\n", hash);
- htable_add(&htable, hash, &c.node);
-
- htable_free(&htable);
-
- return 0;
-}