ucx/map.h

Tue, 21 Feb 2012 01:13:17 +0100

author
Mike Becker <universe@uap-core.de>
date
Tue, 21 Feb 2012 01:13:17 +0100
changeset 29
bce0d7f2912b
parent 20
db7d9860dbbd
child 30
23bb65cbf7a4
permissions
-rw-r--r--

fixed map with the help of new tests

olaf@2 1 /*
olaf@2 2 *
olaf@2 3 */
olaf@2 4
olaf@2 5 #ifndef MAP_H
olaf@2 6 #define MAP_H
olaf@2 7
olaf@20 8 #include "ucx.h"
olaf@20 9 #include "string.h"
olaf@20 10
olaf@2 11 #ifdef __cplusplus
olaf@2 12 extern "C" {
olaf@2 13 #endif
olaf@2 14
olaf@20 15 typedef struct UcxMap UcxMap;
olaf@20 16 typedef struct UcxKey UcxKey;
olaf@20 17 typedef struct UcxMapElement UcxMapElement;
olaf@2 18
olaf@20 19 struct UcxMap {
universe@29 20 UcxMapElement **map;
olaf@20 21 size_t size;
olaf@20 22 };
olaf@2 23
olaf@20 24 struct UcxKey {
olaf@20 25 void *data;
olaf@20 26 size_t len;
olaf@20 27 int hash;
olaf@20 28 };
olaf@20 29
olaf@20 30 struct UcxMapElement {
olaf@20 31 void *data;
olaf@20 32 UcxMapElement *next;
olaf@20 33 UcxKey key;
olaf@20 34 };
olaf@20 35
olaf@20 36
olaf@20 37 UcxMap *ucx_map_new(size_t size);
universe@29 38 void ucx_map_free(UcxMap *map);
olaf@20 39
olaf@20 40 int ucx_map_put(UcxMap *map, UcxKey key, void *data);
olaf@20 41 void* ucx_map_get(UcxMap *map, UcxKey key);
olaf@20 42
universe@29 43 #define ucx_map_sstr_put(m, s, d) ucx_map_put(m, ucx_key(s.ptr, 1+s.length), d)
universe@29 44 #define ucx_map_cstr_put(m, s, d) ucx_map_put(m, ucx_key(s, 1+strlen(s)), d)
universe@29 45 #define ucx_map_sstr_get(m, s) ucx_map_get(m, ucx_key(s.ptr, 1+s.length))
universe@29 46 #define ucx_map_cstr_get(m, s) ucx_map_get(m, ucx_key(s, 1+strlen(s)))
olaf@20 47
olaf@20 48 UcxKey ucx_key(void *data, size_t len);
olaf@20 49
olaf@20 50 int ucx_hash(char *data, size_t len);
olaf@2 51
olaf@2 52 #ifdef __cplusplus
olaf@2 53 }
olaf@2 54 #endif
olaf@2 55
olaf@2 56 #endif /* MAP_H */
olaf@2 57

mercurial