~ufirst/phpredis/igbinary

« back to all changes in this revision

Viewing changes to igbinary-1.2.1/hash.h

  • Committer: Michael Ruoss
  • Date: 2015-03-18 14:12:19 UTC
  • Revision ID: git-v1:c591bdc61de714458440ff13454bc51d94ab5f3d
new build info structure

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
  +----------------------------------------------------------------------+
 
3
  | See COPYING file for further copyright information                   |
 
4
  +----------------------------------------------------------------------+
 
5
  | Author: Oleg Grenrus <oleg.grenrus@dynamoid.com>                     |
 
6
  | See CREDITS for contributors                                         |
 
7
  +----------------------------------------------------------------------+
 
8
*/
 
9
 
 
10
#ifndef HASH_H
 
11
#define HASH_H
 
12
 
 
13
#include <assert.h>
 
14
 
 
15
#ifdef PHP_WIN32
 
16
# include "ig_win32.h"
 
17
#else
 
18
# include <stdint.h>     /* defines uint32_t etc */
 
19
#endif
 
20
 
 
21
#include <stddef.h>
 
22
 
 
23
/** Key/value pair of hash_si.
 
24
 * @author Oleg Grenrus <oleg.grenrus@dynamoid.com>
 
25
 * @see hash_si
 
26
 */
 
27
struct hash_si_pair
 
28
{
 
29
        char *key;                      /**< Pointer to key. */
 
30
        size_t key_len;         /**< Key length. */
 
31
        uint32_t value;         /**< Value. */
 
32
};
 
33
 
 
34
/** Hash-array.
 
35
 * Like c++ map<char *, int32_t>.
 
36
 * Current implementation uses linear probing.
 
37
 * @author Oleg Grenrus <oleg.grenrus@dynamoid.com>
 
38
 */
 
39
struct hash_si {
 
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. */
 
43
};
 
44
 
 
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.
 
49
 */
 
50
int hash_si_init (struct hash_si *h, size_t size);
 
51
 
 
52
/** Frees hash_si structure.
 
53
 * Doesn't call free(h).
 
54
 * @param h pointer to hash_si struct.
 
55
 */
 
56
void hash_si_deinit (struct hash_si *h);
 
57
 
 
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.
 
62
 * @param value Value.
 
63
 * @return 0 on success, 1 or 2 else.
 
64
 */
 
65
int hash_si_insert (struct hash_si *h, const char *key, size_t key_len, uint32_t value);
 
66
 
 
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.
 
74
 */
 
75
int hash_si_find (struct hash_si *h, const char *key, size_t key_len, uint32_t * value);
 
76
 
 
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.
 
84
 */
 
85
int hash_si_remove (struct hash_si *h, const char *key, size_t key_len, uint32_t * value);
 
86
 
 
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.
 
91
 */
 
92
void hash_si_traverse (struct hash_si *h, int (*traverse_function) (const char *key, size_t key_len, uint32_t value));
 
93
 
 
94
/** Returns size of hash_si.
 
95
 * @param h Pointer to hash_si struct.
 
96
 * @return Size of hash_si.
 
97
 */
 
98
size_t hash_si_size (struct hash_si *h);
 
99
 
 
100
/** Returns capacity of hash_si.
 
101
 * @param h Pointer to hash_si struct.
 
102
 * @return Capacity of hash_si.
 
103
 */
 
104
size_t hash_si_capacity (struct hash_si *h);
 
105
 
 
106
#endif /* HASH_H */