cscvs to tla changeset 77
[onak.git] / hash.h
1 /*
2  * hash.h - hashing routines mainly used for caching key details.
3  *
4  * Jonathan McDowell <noodles@earth.li>
5  *
6  * Copyright 2000-2002 Project Purple
7  *
8  * $Id: hash.h,v 1.4 2003/06/04 20:57:08 noodles Exp $
9  */
10
11 #ifndef __HASH_H__
12 #define __HASH_H__
13
14 #include "keystructs.h"
15 #include "ll.h"
16
17 #define HASHSIZE 1024
18 #define HASHMASK 0x3FF
19
20 /**
21  *      inithash - Initialize the hash ready for use.
22  *
23  *      This function prepares the hash ready for use. It should be called
24  *      before any of the functions below are used.
25  */
26 void inithash(void);
27
28 /**
29  *      destroyhash - Clean up the hash after use.
30  *
31  *      This function destroys the hash after use, freeing any memory that was
32  *      used during its lifetime.
33  */
34 void destroyhash(void);
35
36 /**
37  *      addtohash - Adds a key to the hash.
38  *      @key: The key to add.
39  *
40  *      Takes a key and stores it in the hash.
41  */
42 void addtohash(struct stats_key *key);
43
44 /**
45  *      createandaddtohash - Creates a key and adds it to the hash.
46  *      @keyid: The key to create and add.
47  *
48  *      Takes a key, checks if it exists in the hash and if not creates it
49  *      and adds it to the hash. Returns the key from the hash whether it
50  *      already existed or we just created it.
51  */
52 struct stats_key *createandaddtohash(uint64_t keyid);
53
54 /**
55  *      findinhash - Finds a key in the hash.
56  *      @keyid: The key we want.
57  *
58  *      Finds a key in the hash and returns it.
59  */
60 struct stats_key *findinhash(uint64_t keyid);
61
62 /**
63  *      hashelements - Returns the size of the hash
64  *
65  *      Returns the number of elements that have been loaded into the hash.
66  */
67 unsigned long hashelements(void);
68
69 /**
70  *      gethashtableentry - Returns an entry from the hash table.
71  *      @entry: The entry to return. 0 <= entry < HASHSIZE must hold.
72  *
73  *      Gets a particular entry from the hash. Useful for doing something over
74  *      all entries in the hash.
75  */
76 struct ll *gethashtableentry(int entry);
77
78 #endif /* __HASH_H__ */