0ea3fe97d80506812f9c17396de131df2ea4d9d9
[ossec-hids.git] / src / headers / hash_op.h
1 /* @(#) $Id$ */
2
3 /* Copyright (C) 2009 Trend Micro Inc.
4  * All rights reserved.
5  *
6  * This program is a free software; you can redistribute it
7  * and/or modify it under the terms of the GNU General Public
8  * License (version 2) as published by the FSF - Free Software
9  * Foundation.
10  *
11  * License details at the LICENSE file included with OSSEC or
12  * online at: http://www.ossec.net/en/licensing.html
13  */
14  
15 /* Common API for dealing with directory trees */
16           
17
18 #ifndef _OS_HASHOP
19 #define _OS_HASHOP
20
21
22 /* Node structure */
23 typedef struct _OSHashNode
24 {
25     struct _OSHashNode *next;
26    
27     void *key;
28     void *data; 
29 }OSHashNode;
30
31
32 typedef struct _OSHash
33 {
34     unsigned int rows;
35     unsigned int initial_seed;
36     unsigned int constant;
37     
38     OSHashNode **table;
39 }OSHash;
40
41
42
43 /** Prototypes **/
44
45
46 /** OSHash *OSHash_Create();
47  * Creates and initializes hash.
48  */
49 OSHash *OSHash_Create();
50
51
52
53 /** void *OSHash_Free(OSHash *self)
54  * Frees the memory used by the hash.
55  */
56 void *OSHash_Free(OSHash *self);
57   
58
59
60 /** void OSHash_Add(OSHash *hash, char *key, void *data)
61  * Returns 0 on error.
62  * Returns 1 on duplicated key (not added)
63  * Returns 2 on success
64  * Key must not be NULL.
65  */
66 int OSHash_Add(OSHash *hash, char *key, void *data);
67
68
69 /** void *OSHash_Get(OSHash *self, char *key)
70  * Returns NULL on error (key not found).
71  * Returns the key otherwise.
72  * Key must not be NULL.
73  */
74 void *OSHash_Get(OSHash *self, char *key);
75
76 int OSHash_setSize(OSHash *self, int new_size);
77
78 #endif
79
80 /* EOF */