Nilorea Library

- Main Page
- Modules
- Data Structures
- Files

- File List
- Globals

All Data Structures Files Functions Variables Typedefs Macros Groups
n_hash.h
Go to the documentation of this file.
1
8 #ifndef NILOREA_HASH_HEADER_GUARD
9 #define NILOREA_HASH_HEADER_GUARD
10
11 #ifdef __cplusplus
12 extern "C" {
13 #endif
14
21 #if defined( LINUX ) || defined( AIX ) || defined( SOLARIS )
22 #include <arpa/inet.h>
23 #ifndef _XOPEN_SOURCE
24 #define _XOPEN_SOURCE 500
25 #include <string.h>
26 #undef _X_OPEN_SOURCE
27 #else
28 #include <string.h>
29 #endif
30 #endif
31
32 #include <stdint.h>
33 #include "n_log.h"
34 #include "n_list.h"
35
36 #if defined(_MSC_VER)
37
38 #define FORCE_INLINE __forceinline
39 #include <stdlib.h>
41 #define ROTL32(x,y) _rotl(x,y)
42
43 #define BIG_CONSTANT(x) (x)
44
45 #else
46
47 #ifdef SOLARIS
48
49 #define FORCE_INLINE __attribute__((always_inline))
50 #else
51
52 #define FORCE_INLINE inline __attribute__((always_inline))
53 #endif
54
55
57 #define ROTL32(x,y) rotl32(x,y)
58
59 #define BIG_CONSTANT(x) (x##LLU)
60
61 #endif /* if defined MSVC ... */
62
64 #define HASH_INT 0
65
66 #define HASH_DOUBLE 1
67
68 #define HASH_STRING 2
69
70 #define HASH_PTR 3
71
72 #define HASH_UNKNOWN 4
73
74
76 union HASH_VALUE
77 {
79 int ival ;
81 double fval ;
83 void *ptr ;
85 char *string ;
86 };
87
88
90 typedef struct HASH_NODE
91 {
93 char *key ;
95 int type ;
97 union HASH_VALUE data ;
98 } HASH_NODE ;
99
100
102 typedef struct HASH_TABLE
103 {
105 int size ,
107 nb_keys ;
109 LIST **hash_table;
110 } HASH_TABLE ;
111
112
113
114 /* murmur hash func 32bit */
115 void MurmurHash3_x86_32 ( const void * key, int len, uint32_t seed, void * out );
116 /* murmur hash func 128bit */
117 void MurmurHash3_x86_128 ( const void * key, int len, uint32_t seed, void * out );
118
119 /* get the type of the node */
120 char *ht_node_type( HASH_NODE *node );
121
122 /* new hash table allocator */
123 HASH_TABLE *new_ht( int size );
124
125 /* put an integer */
126 int ht_put_int( HASH_TABLE *table , char * key , int val );
127 /* put a double */
128 int ht_put_double( HASH_TABLE *table , char * key , double val );
129 /* put a a pointer */
130 int ht_put_ptr( HASH_TABLE *table , char * key , void *val , void (*destructor)( void *ptr ) );
131 /* put an char *string */
132 int ht_put_string( HASH_TABLE *table , char * key , char *val );
133
134 /* get a given key's node */
135 HASH_NODE *ht_get_node( HASH_TABLE *table , char *key ) ;
136 /* get an int from a key's node */
137 int ht_get_int( HASH_TABLE *table , char * key , int *val );
138 /* get a double from a key's node */
139 int ht_get_double( HASH_TABLE *table , char * key , double *val );
140 /* get a pointer from a key's node */
141 int ht_get_ptr( HASH_TABLE *table , char * key , void **val );
142 /* get a char *string from a key's node */
143 int ht_get_string( HASH_TABLE *table , char * key , char **val );
144
145 /* remove given's key node from the table */
146 int ht_remove( HASH_TABLE *table , char *key );
147 /* empty a hash table. char *strings are also freed */
148 int empty_ht( HASH_TABLE *table );
149 /* destroy a hash table*/
150 int destroy_ht( HASH_TABLE **table );
151
154 #ifdef __cplusplus
155 }
156 #endif
157
158 #endif