1 | /* $Id: hash.h,v 1.6 2011/06/28 00:13:48 sbajic Exp $ */ |
---|
2 | |
---|
3 | /* |
---|
4 | Bayesian Noise Reduction - Jonathan A. Zdziarski |
---|
5 | http://www.zdziarski.com/papers/bnr.html |
---|
6 | COPYRIGHT (C) 2004-2012 DSPAM PROJECT |
---|
7 | |
---|
8 | This program is free software: you can redistribute it and/or modify |
---|
9 | it under the terms of the GNU Affero General Public License as |
---|
10 | published by the Free Software Foundation, either version 3 of the |
---|
11 | License, or (at your option) any later version. |
---|
12 | |
---|
13 | This program is distributed in the hope that it will be useful, |
---|
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
16 | GNU Affero General Public License for more details. |
---|
17 | |
---|
18 | You should have received a copy of the GNU Affero General Public License |
---|
19 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
---|
20 | |
---|
21 | */ |
---|
22 | |
---|
23 | #ifndef _BNR_HASH_H |
---|
24 | #define _BNR_HASH_H |
---|
25 | |
---|
26 | enum |
---|
27 | { bnr_hash_num_primes = 28 }; |
---|
28 | |
---|
29 | /* bnr_hash root */ |
---|
30 | struct bnr_hash |
---|
31 | { |
---|
32 | unsigned long size; |
---|
33 | unsigned long items; |
---|
34 | struct bnr_hash_node **tbl; |
---|
35 | }; |
---|
36 | |
---|
37 | /* bnr_hash node */ |
---|
38 | struct bnr_hash_node |
---|
39 | { |
---|
40 | struct bnr_hash_node *next; |
---|
41 | |
---|
42 | char *name; |
---|
43 | float value; |
---|
44 | }; |
---|
45 | |
---|
46 | /* bnr_hash cursor */ |
---|
47 | struct bnr_hash_c |
---|
48 | { |
---|
49 | unsigned long iter_index; |
---|
50 | struct bnr_hash_node *iter_next; |
---|
51 | }; |
---|
52 | |
---|
53 | /* constructor and destructor */ |
---|
54 | struct bnr_hash * bnr_hash_create (unsigned long size); |
---|
55 | int bnr_hash_destroy (struct bnr_hash *hash); |
---|
56 | |
---|
57 | int bnr_hash_set (struct bnr_hash *hash, const char *name, float value); |
---|
58 | int bnr_hash_hit (struct bnr_hash *hash, const char *name); |
---|
59 | int bnr_hash_delete (struct bnr_hash *hash, const char *name); |
---|
60 | float bnr_hash_value(struct bnr_hash *hash, const char *name); |
---|
61 | |
---|
62 | struct bnr_hash_node *bnr_hash_node_create (const char *name); |
---|
63 | long bnr_hash_hashcode(struct bnr_hash *hash, const char *name); |
---|
64 | |
---|
65 | /* iteration functions */ |
---|
66 | struct bnr_hash_node *c_bnr_hash_first (struct bnr_hash *hash, struct bnr_hash_c *c); |
---|
67 | struct bnr_hash_node *c_bnr_hash_next (struct bnr_hash *hash, struct bnr_hash_c *c); |
---|
68 | |
---|
69 | #endif /* _BNR_HASH_H */ |
---|