ucx/map.h

Thu, 05 Jan 2012 14:53:54 +0100

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Thu, 05 Jan 2012 14:53:54 +0100
changeset 20
db7d9860dbbd
parent 2
79646375a420
child 29
bce0d7f2912b
permissions
-rw-r--r--

added some map functions

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 {
olaf@20 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);
olaf@20 38
olaf@20 39 int ucx_map_put(UcxMap *map, UcxKey key, void *data);
olaf@20 40 void* ucx_map_get(UcxMap *map, UcxKey key);
olaf@20 41
olaf@20 42 #define ucx_map_sstr_put(m, s, d) ucx_map_put(m, ucx_key(s.ptr, s.length), d)
olaf@20 43 #define ucx_map_cstr_put(m, s, d) ucx_map_put(m, ucx_key(s, strlen(s)), d)
olaf@20 44 #define ucx_map_sstr_get(m, s) ucx_map_get(m, ucx_key(s.ptr, s.length))
olaf@20 45 #define ucx_map_cstr_get(m, s) ucx_map_get(m, ucx_key(s, strlen(s)))
olaf@20 46
olaf@20 47 UcxKey ucx_key(void *data, size_t len);
olaf@20 48
olaf@20 49 int ucx_hash(char *data, size_t len);
olaf@2 50
olaf@2 51 #ifdef __cplusplus
olaf@2 52 }
olaf@2 53 #endif
olaf@2 54
olaf@2 55 #endif /* MAP_H */
olaf@2 56

mercurial