hash.h
Go to the documentation of this file.
1 #ifndef HEADER_CURL_HASH_H
2 #define HEADER_CURL_HASH_H
3 /***************************************************************************
4  * _ _ ____ _
5  * Project ___| | | | _ \| |
6  * / __| | | | |_) | |
7  * | (__| |_| | _ <| |___
8  * \___|\___/|_| \_\_____|
9  *
10  * Copyright (C) 1998 - 2017, Daniel Stenberg, <daniel@haxx.se>, et al.
11  *
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.haxx.se/docs/copyright.html.
15  *
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.
19  *
20  * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
21  * KIND, either express or implied.
22  *
23  ***************************************************************************/
24 
25 #include "curl_setup.h"
26 
27 #include <stddef.h>
28 
29 #include "llist.h"
30 
31 /* Hash function prototype */
32 typedef size_t (*hash_function) (void *key,
33  size_t key_length,
34  size_t slots_num);
35 
36 /*
37  Comparator function prototype. Compares two keys.
38 */
39 typedef size_t (*comp_function) (void *key1,
40  size_t key1_len,
41  void *key2,
42  size_t key2_len);
43 
44 typedef void (*curl_hash_dtor)(void *);
45 
46 struct curl_hash {
47  struct curl_llist *table;
48 
49  /* Hash function to be used for this hash table */
51 
52  /* Comparator function to compare keys */
55  int slots;
56  size_t size;
57 };
58 
60  struct curl_llist_element list;
61  void *ptr;
62  size_t key_len;
63  char key[1]; /* allocated memory following the struct */
64 };
65 
67  struct curl_hash *hash;
70 };
71 
72 int Curl_hash_init(struct curl_hash *h,
73  int slots,
74  hash_function hfunc,
75  comp_function comparator,
77 
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_destroy(struct curl_hash *h);
85 void Curl_hash_clean(struct curl_hash *h);
86 void Curl_hash_clean_with_criterium(struct curl_hash *h, void *user,
87  int (*comp)(void *, void *));
88 size_t Curl_hash_str(void *key, size_t key_length, size_t slots_num);
89 size_t Curl_str_key_compare(void *k1, size_t key1_len, void *k2,
90  size_t key2_len);
91 void Curl_hash_start_iterate(struct curl_hash *hash,
92  struct curl_hash_iterator *iter);
93 struct curl_hash_element *
95 
96 void Curl_hash_print(struct curl_hash *h,
97  void (*func)(void *));
98 
99 
100 #endif /* HEADER_CURL_HASH_H */
Definition: hash.h:46
int key2
Definition: unit1602.c:57
void Curl_hash_apply(struct curl_hash *h, void *user, void(*cb)(void *user, void *ptr))
hash_function hash_func
Definition: hash.h:50
UNITTEST_START char * ptr
Definition: unit1330.c:38
void(* curl_hash_dtor)(void *)
Definition: hash.h:44
int Curl_hash_init(struct curl_hash *h, int slots, hash_function hfunc, comp_function comparator, curl_hash_dtor dtor)
Definition: hash.c:57
int Curl_hash_count(struct curl_hash *h)
const char ** p
Definition: unit1394.c:76
comp_function comp_func
Definition: hash.h:53
void * Curl_hash_add(struct curl_hash *h, void *key, size_t key_len, void *p)
Definition: hash.c:110
curl_easy_setopt expects a curl_off_t argument for this option curl_easy_setopt expects a curl_write_callback argument for this option curl_easy_setopt expects a curl_ioctl_callback argument for this option curl_easy_setopt expects a curl_opensocket_callback argument for this option curl_easy_setopt expects a curl_debug_callback argument for this option curl_easy_setopt expects a curl_conv_callback argument for this option curl_easy_setopt expects a private data pointer as argument for this option curl_easy_setopt expects a FILE *argument for this option curl_easy_setopt expects a struct curl_httppost *argument for this option curl_easy_setopt expects a struct curl_slist *argument for this option curl_easy_getinfo expects a pointer to char *for this info curl_easy_getinfo expects a pointer to double for this info curl_easy_getinfo expects a pointer to struct curl_tlssessioninfo *for this info curl_easy_getinfo expects a pointer to curl_socket_t for this info size_t
struct curl_llist_element * current_element
Definition: hash.h:69
size_t key_len
Definition: hash.h:62
void Curl_hash_destroy(struct curl_hash *h)
Definition: hash.c:208
void Curl_hash_print(struct curl_hash *h, void(*func)(void *))
void Curl_hash_clean_with_criterium(struct curl_hash *h, void *user, int(*comp)(void *, void *))
Definition: hash.c:233
int slot_index
Definition: hash.h:68
size_t(* hash_function)(void *key, size_t key_length, size_t slots_num)
Definition: hash.h:32
size_t size
Definition: hash.h:56
size_t Curl_hash_str(void *key, size_t key_length, size_t slots_num)
Definition: hash.c:260
curl_hash_dtor dtor
Definition: hash.h:54
struct curl_hash_element * Curl_hash_next_element(struct curl_hash_iterator *iter)
Definition: hash.c:292
size_t key_len
Definition: unit1305.c:124
size_t(* comp_function)(void *key1, size_t key1_len, void *key2, size_t key2_len)
Definition: hash.h:39
static size_t cb(char *d, size_t n, size_t l, void *p)
Definition: 10-at-a-time.c:91
struct curl_hash * hash
Definition: hash.h:67
void Curl_hash_start_iterate(struct curl_hash *hash, struct curl_hash_iterator *iter)
Definition: hash.c:283
void Curl_hash_clean(struct curl_hash *h)
Definition: hash.c:226
UNITTEST_START char key1[]
Definition: unit1603.c:52
struct curl_llist * table
Definition: hash.h:47
size_t Curl_str_key_compare(void *k1, size_t key1_len, void *k2, size_t key2_len)
Definition: hash.c:274
int key
Definition: unit1602.c:56
void * ptr
Definition: hash.h:61
int slots
Definition: hash.h:55
void * Curl_hash_pick(struct curl_hash *, void *key, size_t key_len)
Definition: hash.c:162
int Curl_hash_delete(struct curl_hash *h, void *key, size_t key_len)
Definition: hash.c:140


rc_tagdetect_client
Author(s): Monika Florek-Jasinska , Raphael Schaller
autogenerated on Sat Feb 13 2021 03:42:15