00001
00002
00003
00004
00005 #ifndef __HASH_H
00006 #define __HASH_H
00007
00008 #include "setup.h"
00009
00010 #include <stddef.h>
00011
00012 #include "llist.h"
00013
00014 typedef size_t (*hash_function) (void* key,
00015 size_t key_length,
00016 size_t slots_num);
00017
00018 typedef size_t (*comp_function) (void* key1,
00019 size_t key1_len,
00020 void*key2,
00021 size_t key2_len);
00022
00023 typedef void (*curl_hash_dtor)(void *);
00024
00025 struct curl_hash {
00026 struct curl_llist **table;
00027
00028
00029 hash_function hash_func;
00030
00031
00032 comp_function comp_func;
00033 curl_hash_dtor dtor;
00034 int slots;
00035 size_t size;
00036 };
00037
00038 struct curl_hash_element {
00039 void *ptr;
00040 char *key;
00041 size_t key_len;
00042 };
00043
00044 int Curl_hash_init(struct curl_hash *h,
00045 int slots,
00046 hash_function hfunc,
00047 comp_function comparator,
00048 curl_hash_dtor dtor);
00049
00050 struct curl_hash *Curl_hash_alloc(int slots,
00051 hash_function hfunc,
00052 comp_function comparator,
00053 curl_hash_dtor dtor);
00054
00055 void *Curl_hash_add(struct curl_hash *h, void *key, size_t key_len, void *p);
00056 int Curl_hash_delete(struct curl_hash *h, void *key, size_t key_len);
00057 void *Curl_hash_pick(struct curl_hash *, void * key, size_t key_len);
00058 void Curl_hash_apply(struct curl_hash *h, void *user,
00059 void (*cb)(void *user, void *ptr));
00060 int Curl_hash_count(struct curl_hash *h);
00061 void Curl_hash_clean(struct curl_hash *h);
00062 void Curl_hash_clean_with_criterium(struct curl_hash *h, void *user,
00063 int (*comp)(void *, void *));
00064 void Curl_hash_destroy(struct curl_hash *h);
00065
00066 size_t Curl_hash_str(void* key, size_t key_length, size_t slots_num);
00067 size_t Curl_str_key_compare(void*k1, size_t key1_len, void*k2,
00068 size_t key2_len);
00069
00070 #endif