hash.h
Go to the documentation of this file.
00001 #ifndef HEADER_CURL_HASH_H
00002 #define HEADER_CURL_HASH_H
00003 /***************************************************************************
00004  *                                  _   _ ____  _
00005  *  Project                     ___| | | |  _ \| |
00006  *                             / __| | | | |_) | |
00007  *                            | (__| |_| |  _ <| |___
00008  *                             \___|\___/|_| \_\_____|
00009  *
00010  * Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al.
00011  *
00012  * This software is licensed as described in the file COPYING, which
00013  * you should have received as part of this distribution. The terms
00014  * are also available at https://curl.haxx.se/docs/copyright.html.
00015  *
00016  * You may opt to use, copy, modify, merge, publish, distribute and/or sell
00017  * copies of the Software, and permit persons to whom the Software is
00018  * furnished to do so, under the terms of the COPYING file.
00019  *
00020  * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
00021  * KIND, either express or implied.
00022  *
00023  ***************************************************************************/
00024 
00025 #include "curl_setup.h"
00026 
00027 #include <stddef.h>
00028 
00029 #include "llist.h"
00030 
00031 /* Hash function prototype */
00032 typedef size_t (*hash_function) (void *key,
00033                                  size_t key_length,
00034                                  size_t slots_num);
00035 
00036 /*
00037    Comparator function prototype. Compares two keys.
00038 */
00039 typedef size_t (*comp_function) (void *key1,
00040                                  size_t key1_len,
00041                                  void *key2,
00042                                  size_t key2_len);
00043 
00044 typedef void (*curl_hash_dtor)(void *);
00045 
00046 struct curl_hash {
00047   struct curl_llist **table;
00048 
00049   /* Hash function to be used for this hash table */
00050   hash_function hash_func;
00051 
00052   /* Comparator function to compare keys */
00053   comp_function comp_func;
00054   curl_hash_dtor   dtor;
00055   int slots;
00056   size_t size;
00057 };
00058 
00059 struct curl_hash_element {
00060   void   *ptr;
00061   char   *key;
00062   size_t key_len;
00063 };
00064 
00065 struct curl_hash_iterator {
00066   struct curl_hash *hash;
00067   int slot_index;
00068   struct curl_llist_element *current_element;
00069 };
00070 
00071 int Curl_hash_init(struct curl_hash *h,
00072                    int slots,
00073                    hash_function hfunc,
00074                    comp_function comparator,
00075                    curl_hash_dtor dtor);
00076 
00077 void *Curl_hash_add(struct curl_hash *h, void *key, size_t key_len, void *p);
00078 int Curl_hash_delete(struct curl_hash *h, void *key, size_t key_len);
00079 void *Curl_hash_pick(struct curl_hash *, void *key, size_t key_len);
00080 void Curl_hash_apply(struct curl_hash *h, void *user,
00081                      void (*cb)(void *user, void *ptr));
00082 int Curl_hash_count(struct curl_hash *h);
00083 void Curl_hash_destroy(struct curl_hash *h);
00084 void Curl_hash_clean(struct curl_hash *h);
00085 void Curl_hash_clean_with_criterium(struct curl_hash *h, void *user,
00086                                     int (*comp)(void *, void *));
00087 size_t Curl_hash_str(void *key, size_t key_length, size_t slots_num);
00088 size_t Curl_str_key_compare(void *k1, size_t key1_len, void *k2,
00089                             size_t key2_len);
00090 void Curl_hash_start_iterate(struct curl_hash *hash,
00091                              struct curl_hash_iterator *iter);
00092 struct curl_hash_element *
00093 Curl_hash_next_element(struct curl_hash_iterator *iter);
00094 
00095 void Curl_hash_print(struct curl_hash *h,
00096                      void (*func)(void *));
00097 
00098 
00099 #endif /* HEADER_CURL_HASH_H */


rc_visard_driver
Author(s): Heiko Hirschmueller , Christian Emmerich , Felix Ruess
autogenerated on Thu Jun 6 2019 20:43:04