Use C99 uint32_t rather than u_int32_t
[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
26 #define HASHSIZE 1024
27 #define HASHMASK 0x3FF
28
29 /**
30  *      inithash - Initialize the hash ready for use.
31  *
32  *      This function prepares the hash ready for use. It should be called
33  *      before any of the functions below are used.
34  */
35 void inithash(void);
36
37 /**
38  *      destroyhash - Clean up the hash after use.
39  *
40  *      This function destroys the hash after use, freeing any memory that was
41  *      used during its lifetime.
42  */
43 void destroyhash(void);
44
45 /**
46  *      addtohash - Adds a key to the hash.
47  *      @key: The key to add.
48  *
49  *      Takes a key and stores it in the hash.
50  */
51 void addtohash(struct stats_key *key);
52
53 /**
54  *      createandaddtohash - Creates a key and adds it to the hash.
55  *      @keyid: The key to create and add.
56  *
57  *      Takes a key, checks if it exists in the hash and if not creates it
58  *      and adds it to the hash. Returns the key from the hash whether it
59  *      already existed or we just created it.
60  */
61 struct stats_key *createandaddtohash(uint64_t keyid);
62
63 /**
64  *      findinhash - Finds a key in the hash.
65  *      @keyid: The key we want.
66  *
67  *      Finds a key in the hash and returns it.
68  */
69 struct stats_key *findinhash(uint64_t keyid);
70
71 /**
72  *      hashelements - Returns the size of the hash
73  *
74  *      Returns the number of elements that have been loaded into the hash.
75  */
76 unsigned long hashelements(void);
77
78 /**
79  *      gethashtableentry - Returns an entry from the hash table.
80  *      @entry: The entry to return. 0 <= entry < HASHSIZE must hold.
81  *
82  *      Gets a particular entry from the hash. Useful for doing something over
83  *      all entries in the hash.
84  */
85 struct ll *gethashtableentry(unsigned int entry);
86
87 #endif /* __HASH_H__ */