suricata
util-hash.h
Go to the documentation of this file.
1 /* Copyright (C) 2007-2010 Open Information Security Foundation
2  *
3  * You can copy, redistribute or modify this Program under the terms of
4  * the GNU General Public License version 2 as published by the Free
5  * Software Foundation.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * version 2 along with this program; if not, write to the Free Software
14  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
15  * 02110-1301, USA.
16  */
17 
18 /**
19  * \file
20  *
21  * \author Victor Julien <victor@inliniac.net>
22  */
23 
24 #ifndef __HASH_H__
25 #define __HASH_H__
26 
27 /* hash bucket structure */
28 typedef struct HashTableBucket_ {
29  void *data;
30  uint16_t size;
33 
34 /* hash table structure */
35 typedef struct HashTable_ {
37  uint32_t array_size;
38 #ifdef UNITTESTS
39  uint32_t count;
40 #endif
41  uint32_t (*Hash)(struct HashTable_ *, void *, uint16_t);
42  char (*Compare)(void *, uint16_t, void *, uint16_t);
43  void (*Free)(void *);
44 } HashTable;
45 
46 #define HASH_NO_SIZE 0
47 
48 /* prototypes */
49 HashTable* HashTableInit(uint32_t, uint32_t (*Hash)(struct HashTable_ *, void *, uint16_t), char (*Compare)(void *, uint16_t, void *, uint16_t), void (*Free)(void *));
50 void HashTableFree(HashTable *);
52 int HashTableAdd(HashTable *, void *, uint16_t);
53 int HashTableRemove(HashTable *, void *, uint16_t);
54 void *HashTableLookup(HashTable *, void *, uint16_t);
55 uint32_t HashTableGenericHash(HashTable *, void *, uint16_t);
56 char HashTableDefaultCompare(void *, uint16_t, void *, uint16_t);
57 
58 void HashTableRegisterTests(void);
59 
60 #endif /* __HASH_H__ */
61 
uint32_t HashTableGenericHash(HashTable *, void *, uint16_t)
Definition: util-hash.c:221
void(* Free)(void *)
Definition: util-hash.h:43
uint32_t(* Hash)(struct HashTable_ *, void *, uint16_t)
Definition: util-hash.h:41
uint32_t array_size
Definition: util-hash.h:37
char(* Compare)(void *, uint16_t, void *, uint16_t)
Definition: util-hash.h:42
struct HashTableBucket_ HashTableBucket
struct HashTable_ HashTable
char HashTableDefaultCompare(void *, uint16_t, void *, uint16_t)
Definition: util-hash.c:238
uint32_t count
Definition: util-hash.h:39
struct HashTableBucket_ * next
Definition: util-hash.h:31
void HashTableRegisterTests(void)
Definition: util-hash.c:427
void HashTablePrint(HashTable *)
Definition: util-hash.c:105
void HashTableFree(HashTable *)
Definition: util-hash.c:79
int HashTableAdd(HashTable *, void *, uint16_t)
Definition: util-hash.c:113
HashTableBucket ** array
Definition: util-hash.h:36
HashTable * HashTableInit(uint32_t, uint32_t(*Hash)(struct HashTable_ *, void *, uint16_t), char(*Compare)(void *, uint16_t, void *, uint16_t), void(*Free)(void *))
Definition: util-hash.c:34
int HashTableRemove(HashTable *, void *, uint16_t)
Definition: util-hash.c:152
void * HashTableLookup(HashTable *, void *, uint16_t)
Definition: util-hash.c:193
uint16_t size
Definition: util-hash.h:30