Update Debian Vcs-* fields to point to git repository
[onak.git] / hash.h
1 /*
2  * hash.h - hashing routines mainly used for caching key details.
3  *
4  * Copyright 2000-2002 Jonathan McDowell <noodles@earth.li>
5  *
6  * This program is free software: you can redistribute it and/or modify it
7  * under the terms of the GNU General Public License as published by the Free
8  * Software Foundation; version 2 of the License.
9  *
10  * This program is distributed in the hope that it will be useful, but WITHOUT
11  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13  * more details.
14  *
15  * You should have received a copy of the GNU General Public License along with
16  * this program; if not, write to the Free Software Foundation, Inc., 51
17  * Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18  */
19
20 #ifndef __HASH_H__
21 #define __HASH_H__
22
23 #include "keystructs.h"
24 #include "ll.h"
25 #include "stats.h"
26
27 #define HASHSIZE 1024
28 #define HASHMASK 0x3FF
29
30 /**
31  *      inithash - Initialize the hash ready for use.
32  *
33  *      This function prepares the hash ready for use. It should be called
34  *      before any of the functions below are used.
35  */
36 void inithash(void);
37
38 /**
39  *      destroyhash - Clean up the hash after use.
40  *
41  *      This function destroys the hash after use, freeing any memory that was
42  *      used during its lifetime.
43  */
44 void destroyhash(void);
45
46 /**
47  *      addtohash - Adds a key to the hash.
48  *      @key: The key to add.
49  *
50  *      Takes a key and stores it in the hash.
51  */
52 void addtohash(struct stats_key *key);
53
54 /**
55  *      createandaddtohash - Creates a key and adds it to the hash.
56  *      @keyid: The key to create and add.
57  *
58  *      Takes a key, checks if it exists in the hash and if not creates it
59  *      and adds it to the hash. Returns the key from the hash whether it
60  *      already existed or we just created it.
61  */
62 struct stats_key *createandaddtohash(uint64_t keyid);
63
64 /**
65  *      findinhash - Finds a key in the hash.
66  *      @keyid: The key we want.
67  *
68  *      Finds a key in the hash and returns it.
69  */
70 struct stats_key *findinhash(uint64_t keyid);
71
72 /**
73  *      hashelements - Returns the size of the hash
74  *
75  *      Returns the number of elements that have been loaded into the hash.
76  */
77 unsigned long hashelements(void);
78
79 /**
80  *      gethashtableentry - Returns an entry from the hash table.
81  *      @entry: The entry to return. 0 <= entry < HASHSIZE must hold.
82  *
83  *      Gets a particular entry from the hash. Useful for doing something over
84  *      all entries in the hash.
85  */
86 struct ll *gethashtableentry(unsigned int entry);
87
88 #endif /* __HASH_H__ */