cscvs to tla changeset 1
[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
9 #ifndef __HASH_H__
10 #define __HASH_H__
11
12 #include "ll.h"
13 #include "stats.h"
14
15 #define HASHSIZE 1024
16 #define HASHMASK 0x3FF
17
18 /**
19  *      inithash - Initialize the hash ready for use.
20  *
21  *      This function prepares the hash ready for use. It should be called
22  *      before any of the functions below are used.
23  */
24 void inithash(void);
25
26 /**
27  *      addtohash - Adds a key to the hash.
28  *      @key: The key to add.
29  *
30  *      Takes a key and stores it in the hash.
31  */
32 void addtohash(struct stats_key *key);
33
34 /**
35  *      createandaddtohash - Creates a key and adds it to the hash.
36  *      @keyid: The key to create and add.
37  *
38  *      Takes a key, checks if it exists in the hash and if not creates it
39  *      and adds it to the hash. Returns the key from the hash whether it
40  *      already existed or we just created it.
41  */
42 struct stats_key *createandaddtohash(uint64_t keyid);
43
44 /**
45  *      findinhash - Finds a key in the hash.
46  *      @keyid: The key we want.
47  *
48  *      Finds a key in the hash and returns it.
49  */
50 struct stats_key *findinhash(uint64_t keyid);
51
52 /**
53  *      hashelements - Returns the size of the hash
54  *
55  *      Returns the number of elements that have been loaded into the hash.
56  */
57 unsigned long hashelements(void);
58
59 /**
60  *      gethashtableentry - Returns an entry from the hash table.
61  *      @entry: The entry to return. 0 <= entry < HASHSIZE must hold.
62  *
63  *      Gets a particular entry from the hash. Useful for doing something over
64  *      all entries in the hash.
65  */
66 struct ll *gethashtableentry(int entry);
67
68 /**
69  *      hash_getkeysigs - Gets the signatures on a key.
70  *      @keyid: The key we want the signatures for.
71  *      
72  *      This function gets the signatures on a key. It's the same as the
73  *      getkeysigs function from the keydb module except we also cache the data
74  *      so that if we need it again we already have it available.
75  */
76 struct ll *hash_getkeysigs(uint64_t keyid);
77
78 #endif /* __HASH_H__ */