new upstream release (3.3.0); modify package compatibility for Stretch
[ossec-hids.git] / src / headers / hash_op.h
1 /* Copyright (C) 2009 Trend Micro Inc.
2  * All rights reserved.
3  *
4  * This program is a free software; you can redistribute it
5  * and/or modify it under the terms of the GNU General Public
6  * License (version 2) as published by the FSF - Free Software
7  * Foundation.
8  */
9
10 /* Common API for dealing with hash operations */
11
12 #ifndef _OS_HASHOP
13 #define _OS_HASHOP
14
15 /* Node structure */
16 typedef struct _OSHashNode {
17     struct _OSHashNode *next;
18
19     char *key;
20     void *data;
21 } OSHashNode;
22
23 typedef struct _OSHash {
24     unsigned int rows;
25     unsigned int initial_seed;
26     unsigned int constant;
27
28     OSHashNode **table;
29 } OSHash;
30
31 /* Prototypes */
32
33 /* Create and initialize hash */
34 OSHash *OSHash_Create(void);
35
36 /* Free the memory used by the hash */
37 void *OSHash_Free(OSHash *self) __attribute__((nonnull));
38
39 /* Returns 0 on error
40  * Returns 1 on duplicated key (not added)
41  * Returns 2 on success
42  * Key must not be NULL
43  */
44 int OSHash_Add(OSHash *hash, const char *key, void *data) __attribute__((nonnull(1, 2)));
45 int OSHash_Update(OSHash *hash, const char *key, void *data) __attribute__((nonnull(1, 2)));
46 void *OSHash_Delete(OSHash *self, const char *key) __attribute__((nonnull));
47
48 /* Returns NULL on error (key not found)
49  * Returns the key otherwise
50  * Key must not be NULL
51  */
52 void *OSHash_Get(const OSHash *self, const char *key) __attribute__((nonnull));
53
54 int OSHash_setSize(OSHash *self, unsigned int new_size) __attribute__((nonnull));
55
56 #endif
57