1 #ifndef HEADER_CURL_HASH_H
2 #define HEADER_CURL_HASH_H
3 /***************************************************************************
5 * Project ___| | | | _ \| |
7 * | (__| |_| | _ <| |___
8 * \___|\___/|_| \_\_____|
10 * Copyright (C) 1998 - 2022, 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 https://curl.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 * SPDX-License-Identifier: curl
25 ***************************************************************************/
27 #include "curl_setup.h"
33 /* Hash function prototype */
34 typedef size_t (*hash_function) (void *key,
39 Comparator function prototype. Compares two keys.
41 typedef size_t (*comp_function) (void *key1,
46 typedef void (*Curl_hash_dtor)(void *);
49 struct Curl_llist *table;
51 /* Hash function to be used for this hash table */
52 hash_function hash_func;
54 /* Comparator function to compare keys */
55 comp_function comp_func;
61 struct Curl_hash_element {
62 struct Curl_llist_element list;
65 char key[1]; /* allocated memory following the struct */
68 struct Curl_hash_iterator {
69 struct Curl_hash *hash;
71 struct Curl_llist_element *current_element;
74 void Curl_hash_init(struct Curl_hash *h,
77 comp_function comparator,
80 void *Curl_hash_add(struct Curl_hash *h, void *key, size_t key_len, void *p);
81 int Curl_hash_delete(struct Curl_hash *h, void *key, size_t key_len);
82 void *Curl_hash_pick(struct Curl_hash *, void *key, size_t key_len);
83 void Curl_hash_apply(struct Curl_hash *h, void *user,
84 void (*cb)(void *user, void *ptr));
85 #define Curl_hash_count(h) ((h)->size)
86 void Curl_hash_destroy(struct Curl_hash *h);
87 void Curl_hash_clean(struct Curl_hash *h);
88 void Curl_hash_clean_with_criterium(struct Curl_hash *h, void *user,
89 int (*comp)(void *, void *));
90 size_t Curl_hash_str(void *key, size_t key_length, size_t slots_num);
91 size_t Curl_str_key_compare(void *k1, size_t key1_len, void *k2,
93 void Curl_hash_start_iterate(struct Curl_hash *hash,
94 struct Curl_hash_iterator *iter);
95 struct Curl_hash_element *
96 Curl_hash_next_element(struct Curl_hash_iterator *iter);
98 void Curl_hash_print(struct Curl_hash *h,
99 void (*func)(void *));
102 #endif /* HEADER_CURL_HASH_H */