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