root/src/utils/noit_hash.h

Revision b7ec8071a69b07dca745fa521b287c9f4ffec06e, 4.5 kB (checked in by Theo Schlossnagle <jesus@omniti.com>, 6 years ago)

SSL support that doesn't quite work -- so so so close.

  • Property mode set to 100644
Line 
1 /*
2  * Copyright (c) 2005-2007, OmniTI Computer Consulting, Inc.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are
7  * met:
8  *
9  *    * Redistributions of source code must retain the above copyright
10  *      notice, this list of conditions and the following disclaimer.
11  *    * Redistributions in binary form must reproduce the above
12  *      copyright notice, this list of conditions and the following
13  *      disclaimer in the documentation and/or other materials provided
14  *      with the distribution.
15  *    * Neither the name OmniTI Computer Consulting, Inc. nor the names
16  *      of its contributors may be used to endorse or promote products
17  *      derived from this software without specific prior written
18  *      permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  */
32
33 /* this is just a copy (with search and replace) from jlog_hash */
34
35 #ifndef _NOIT_HASH_H
36 #define _NOIT_HASH_H
37
38 #include "noit_config.h"
39
40 typedef void (*NoitHashFreeFunc)(void *);
41
42 typedef struct _noit_hash_bucket {
43   const char *k;
44   int klen;
45   void *data;
46   struct _noit_hash_bucket *next;
47 } noit_hash_bucket;
48
49 typedef struct {
50   noit_hash_bucket **buckets;
51   u_int32_t table_size;
52   u_int32_t initval;
53   u_int32_t num_used_buckets;
54   u_int32_t size;
55   unsigned dont_rebucket:1;
56   unsigned _spare:31;
57 } noit_hash_table;
58
59 #define NOIT_HASH_EMPTY { NULL, 0, 0, 0, 0, 0, 0 }
60
61 typedef struct {
62   void *p2;
63   int p1;
64 } noit_hash_iter;
65
66 #define NOIT_HASH_ITER_ZERO { NULL, 0 }
67
68 void noit_hash_init(noit_hash_table *h);
69 /* NOTE! "k" and "data" MUST NOT be transient buffers, as the hash table
70  * implementation does not duplicate them.  You provide a pair of
71  * NoitHashFreeFunc functions to free up their storage when you call
72  * noit_hash_delete(), noit_hash_delete_all() or noit_hash_destroy().
73  * */
74 int noit_hash_store(noit_hash_table *h, const char *k, int klen, void *data);
75 int noit_hash_replace(noit_hash_table *h, const char *k, int klen, void *data,
76                       NoitHashFreeFunc keyfree, NoitHashFreeFunc datafree);
77 int noit_hash_retrieve(noit_hash_table *h, const char *k, int klen, void **data);
78 int noit_hash_delete(noit_hash_table *h, const char *k, int klen,
79                      NoitHashFreeFunc keyfree, NoitHashFreeFunc datafree);
80 void noit_hash_delete_all(noit_hash_table *h, NoitHashFreeFunc keyfree,
81                           NoitHashFreeFunc datafree);
82 void noit_hash_destroy(noit_hash_table *h, NoitHashFreeFunc keyfree,
83                        NoitHashFreeFunc datafree);
84
85 /* This is a convenience function only.  It assumes that all keys and values
86  * in the destination hash are strings and allocated with malloc() and
87  * assumes that the source contains only keys and values that can be
88  * suitably duplicated by strdup().
89  */
90 void noit_hash_merge_as_dict(noit_hash_table *dst, noit_hash_table *src);
91
92 /* This is an iterator and requires the hash to not be written to during the
93    iteration process.
94    To use:
95      noit_hash_iter iter = NOIT_HASH_ITER_ZERO;
96
97      const char *k;
98      int klen;
99      void *data;
100
101      while(noit_hash_next(h, &iter, &k, &klen, &data)) {
102        .... use k, klen and data ....
103      }
104 */
105 int noit_hash_next(noit_hash_table *h, noit_hash_iter *iter,
106                    const char **k, int *klen, void **data);
107 int noit_hash_firstkey(noit_hash_table *h, const char **k, int *klen);
108 int noit_hash_nextkey(noit_hash_table *h, const char **k, int *klen, const char *lk, int lklen);
109
110 /* This function serves no real API use sans calculating expected buckets
111    for keys (or extending the hash... which is unsupported) */
112 u_int32_t noit_hash__hash(const char *k, u_int32_t length, u_int32_t initval);
113 noit_hash_bucket *noit_hash__new_bucket(const char *k, int klen, void *data);
114 void noit_hash__rebucket(noit_hash_table *h, int newsize);
115 #endif
Note: See TracBrowser for help on using the browser.