root/src/utils/noit_hash.h

Revision ce17a6d806789e0648baa8f1e9abb243abbf1755, 4.1 kB (checked in by Theo Schlossnagle <jesus@omniti.com>, 9 months ago)

remove double function declaration.

  • 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 #include <ck_ht.h>
40
41 typedef void (*NoitHashFreeFunc)(void *);
42
43 typedef struct {
44   ck_ht_t ht CK_CC_CACHELINE;
45 } noit_hash_table;
46
47 typedef ck_ht_iterator_t noit_hash_iter;
48
49 #define NOIT_HASH_EMPTY { { NULL, NULL, 0, 0, NULL} }
50 #define NOIT_HASH_ITER_ZERO CK_HT_ITERATOR_INITIALIZER
51
52 void noit_hash_init(noit_hash_table *h);
53 void noit_hash_init_size(noit_hash_table *h, int size);
54 /* NOTE! "k" and "data" MUST NOT be transient buffers, as the hash table
55  * implementation does not duplicate them.  You provide a pair of
56  * NoitHashFreeFunc functions to free up their storage when you call
57  * noit_hash_delete(), noit_hash_delete_all() or noit_hash_destroy().
58  * */
59 int noit_hash_store(noit_hash_table *h, const char *k, int klen, void *data);
60 int noit_hash_replace(noit_hash_table *h, const char *k, int klen, void *data,
61                       NoitHashFreeFunc keyfree, NoitHashFreeFunc datafree);
62 int noit_hash_retrieve(noit_hash_table *h, const char *k, int klen, void **data);
63 int noit_hash_retr_str(noit_hash_table *h, const char *k, int klen, const char **dstr);
64 int noit_hash_delete(noit_hash_table *h, const char *k, int klen,
65                      NoitHashFreeFunc keyfree, NoitHashFreeFunc datafree);
66 void noit_hash_delete_all(noit_hash_table *h, NoitHashFreeFunc keyfree,
67                           NoitHashFreeFunc datafree);
68 void noit_hash_destroy(noit_hash_table *h, NoitHashFreeFunc keyfree,
69                        NoitHashFreeFunc datafree);
70 int noit_hash_size(noit_hash_table *h);
71
72 /* This is a convenience function only.  It assumes that all keys and values
73  * in the destination hash are strings and allocated with malloc() and
74  * assumes that the source contains only keys and values that can be
75  * suitably duplicated by strdup().
76  */
77 void noit_hash_merge_as_dict(noit_hash_table *dst, noit_hash_table *src);
78
79 /* This is an iterator and requires the hash to not be written to during the
80    iteration process.
81    To use:
82      noit_hash_iter iter = NOIT_HASH_ITER_ZERO;
83
84      const char *k;
85      int klen;
86      void *data;
87
88      while(noit_hash_next(h, &iter, &k, &klen, &data)) {
89        .... use k, klen and data ....
90      }
91 */
92 int noit_hash_next(noit_hash_table *h, noit_hash_iter *iter,
93                    const char **k, int *klen, void **data);
94 int noit_hash_next_str(noit_hash_table *h, noit_hash_iter *iter,
95                        const char **k, int *klen, const char **dstr);
96
97 #endif
Note: See TracBrowser for help on using the browser.