#include <stdint.h>

#define FNV_OFFSET 14695981039346656037UL
#define FNV_PRIME 1099511628211UL

uint64_t hash_key(char* key){
    uint64_t hash=FNV_OFFSET;
    for (char* p =key; *p!='\0'; p++){
        hash=hash^(uint64_t)(*p);//on fait un xor avec la valeur du caractère.
        hash=hash*FNV_PRIME;
    }
    return hash;
}

void print_ht(hashtbl* t){
    int cap = t->capacity;
    char** table=t->table;
    for (int i =0;i<cap;i++){
        if(table[i]!=NULL){
            printf("%d %s %d\n", i, table[i], (int)hash_key(table[i])%cap);
        }
        else{
            printf("%d\n", i);
        }

    }
}

int main(){

    hashtbl* hash_tab = create_ht(8);
    char* test[]={"", "il", "en", "faut", "peu", "pour", "etre" , "heureux", "vraiment"};
    for (int i=0;i<9;i++){
        insert_ht(hash_tab,test[i]);
        print_ht(hash_tab);
    }

    for (int i=0;i<8;i++){
        delete_ht(hash_tab,test[i]);
        print_ht(hash_tab);

    }
    destroy_ht(hash_tab);
    return 0;
}
