2
+----------------------------------------------------------------------+
3
| See COPYING file for further copyright information |
4
+----------------------------------------------------------------------+
5
| Author: Oleg Grenrus <oleg.grenrus@dynamoid.com> |
6
| See CREDITS for contributors |
7
+----------------------------------------------------------------------+
16
# include "ig_win32.h"
18
# include <stdint.h> /* defines uint32_t etc */
23
/** Key/value pair of hash_si.
24
* @author Oleg Grenrus <oleg.grenrus@dynamoid.com>
29
char *key; /**< Pointer to key. */
30
size_t key_len; /**< Key length. */
31
uint32_t value; /**< Value. */
35
* Like c++ map<char *, int32_t>.
36
* Current implementation uses linear probing.
37
* @author Oleg Grenrus <oleg.grenrus@dynamoid.com>
40
size_t size; /**< Allocated size of array. */
41
size_t used; /**< Used size of array. */
42
struct hash_si_pair *data; /**< Pointer to array or pairs of data. */
45
/** Inits hash_si structure.
46
* @param h pointer to hash_si struct.
47
* @param size initial size of the hash array.
48
* @return 0 on success, 1 else.
50
int hash_si_init (struct hash_si *h, size_t size);
52
/** Frees hash_si structure.
53
* Doesn't call free(h).
54
* @param h pointer to hash_si struct.
56
void hash_si_deinit (struct hash_si *h);
58
/** Inserts value into hash_si.
59
* @param h Pointer to hash_si struct.
60
* @param key Pointer to key.
61
* @param key_len Key length.
63
* @return 0 on success, 1 or 2 else.
65
int hash_si_insert (struct hash_si *h, const char *key, size_t key_len, uint32_t value);
67
/** Finds value from hash_si.
68
* Value returned thru value param.
69
* @param h Pointer to hash_si struct.
70
* @param key Pointer to key.
71
* @param key_len Key length.
72
* @param[out] value Found value.
73
* @return 0 if found, 1 if not.
75
int hash_si_find (struct hash_si *h, const char *key, size_t key_len, uint32_t * value);
77
/** Remove value from hash_si.
78
* Removed value is available thru value param.
79
* @param h Pointer to hash_si struct.
80
* @param key Pointer to key.
81
* @param key_len Key length.
82
* @param[out] value Removed value.
83
* @return 0 ivalue removed, 1 if not existed.
85
int hash_si_remove (struct hash_si *h, const char *key, size_t key_len, uint32_t * value);
87
/** Travarses hash_si.
88
* Calls traverse_function on every item. Traverse function should not modify hash
89
* @param h Pointer to hash_si struct.
90
* @param traverse_function Function to call on every item of hash_si.
92
void hash_si_traverse (struct hash_si *h, int (*traverse_function) (const char *key, size_t key_len, uint32_t value));
94
/** Returns size of hash_si.
95
* @param h Pointer to hash_si struct.
96
* @return Size of hash_si.
98
size_t hash_si_size (struct hash_si *h);
100
/** Returns capacity of hash_si.
101
* @param h Pointer to hash_si struct.
102
* @return Capacity of hash_si.
104
size_t hash_si_capacity (struct hash_si *h);