Resync
[CMakeLuaTailorHgBridge.git] / CMakeLua / Utilities / cmcurl-7.19.0 / lib / hash.h
blob33bd2d69ccd1cf7b8dfc5c48c9230778e99e7f04
1 #ifndef __HASH_H
2 #define __HASH_H
3 /***************************************************************************
4 * _ _ ____ _
5 * Project ___| | | | _ \| |
6 * / __| | | | |_) | |
7 * | (__| |_| | _ <| |___
8 * \___|\___/|_| \_\_____|
10 * Copyright (C) 1998 - 2007, Daniel Stenberg, <daniel@haxx.se>, et al.
12 * This software is licensed as described in the file COPYING, which
13 * you should have received as part of this distribution. The terms
14 * are also available at http://curl.haxx.se/docs/copyright.html.
16 * You may opt to use, copy, modify, merge, publish, distribute and/or sell
17 * copies of the Software, and permit persons to whom the Software is
18 * furnished to do so, under the terms of the COPYING file.
20 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
21 * KIND, either express or implied.
23 * $Id: hash.h,v 1.1.1.1 2008-09-23 16:32:05 hoffman Exp $
24 ***************************************************************************/
26 #include "setup.h"
28 #include <stddef.h>
30 #include "llist.h"
32 /* Hash function prototype */
33 typedef size_t (*hash_function) (void* key,
34 size_t key_length,
35 size_t slots_num);
38 Comparator function prototype. Compares two keys.
40 typedef size_t (*comp_function) (void* key1,
41 size_t key1_len,
42 void*key2,
43 size_t key2_len);
45 typedef void (*curl_hash_dtor)(void *);
47 struct curl_hash {
48 struct curl_llist **table;
50 /* Hash function to be used for this hash table */
51 hash_function hash_func;
53 /* Comparator function to compare keys */
54 comp_function comp_func;
55 curl_hash_dtor dtor;
56 int slots;
57 size_t size;
60 struct curl_hash_element {
61 void *ptr;
62 char *key;
63 size_t key_len;
67 int Curl_hash_init(struct curl_hash *h,
68 int slots,
69 hash_function hfunc,
70 comp_function comparator,
71 curl_hash_dtor dtor);
73 struct curl_hash *Curl_hash_alloc(int slots,
74 hash_function hfunc,
75 comp_function comparator,
76 curl_hash_dtor dtor);
78 void *Curl_hash_add(struct curl_hash *h, void *key, size_t key_len, void *p);
79 int Curl_hash_delete(struct curl_hash *h, void *key, size_t key_len);
80 void *Curl_hash_pick(struct curl_hash *, void * key, size_t key_len);
81 void Curl_hash_apply(struct curl_hash *h, void *user,
82 void (*cb)(void *user, void *ptr));
83 int Curl_hash_count(struct curl_hash *h);
84 void Curl_hash_clean(struct curl_hash *h);
85 void Curl_hash_clean_with_criterium(struct curl_hash *h, void *user,
86 int (*comp)(void *, void *));
87 void Curl_hash_destroy(struct curl_hash *h);
89 size_t Curl_hash_str(void* key, size_t key_length, size_t slots_num);
90 size_t Curl_str_key_compare(void*k1, size_t key1_len, void*k2,
91 size_t key2_len);
93 #endif