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