ucx/map.h

Tue, 02 Oct 2012 11:18:47 +0200

author
Mike Becker <universe@uap-core.de>
date
Tue, 02 Oct 2012 11:18:47 +0200
changeset 38
35f67a8ef875
parent 31
91ac86557290
child 41
7f90a03e186e
permissions
-rw-r--r--

added missing stddef includes

added no break comments

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"
universe@38 10 #include <stddef.h>
olaf@20 11
olaf@2 12 #ifdef __cplusplus
olaf@2 13 extern "C" {
olaf@2 14 #endif
olaf@2 15
olaf@31 16 #define UCX_MAP_FOREACH(type,elm,map,iter) \
olaf@31 17 for(type elm;ucx_map_iter_next(&iter,(void*)&elm)==0;)
olaf@31 18
olaf@31 19 typedef struct UcxMap UcxMap;
olaf@31 20 typedef struct UcxKey UcxKey;
olaf@31 21 typedef struct UcxMapElement UcxMapElement;
olaf@31 22 typedef struct UcxMapIterator UcxMapIterator;
olaf@2 23
olaf@20 24 struct UcxMap {
universe@29 25 UcxMapElement **map;
olaf@20 26 size_t size;
olaf@20 27 };
olaf@2 28
olaf@20 29 struct UcxKey {
olaf@20 30 void *data;
olaf@20 31 size_t len;
olaf@20 32 int hash;
olaf@20 33 };
olaf@20 34
olaf@20 35 struct UcxMapElement {
olaf@20 36 void *data;
olaf@20 37 UcxMapElement *next;
olaf@20 38 UcxKey key;
olaf@20 39 };
olaf@20 40
olaf@31 41 struct UcxMapIterator {
olaf@31 42 UcxMap *map;
olaf@31 43 UcxMapElement *cur;
olaf@31 44 int index;
olaf@31 45 };
olaf@31 46
olaf@20 47
olaf@20 48 UcxMap *ucx_map_new(size_t size);
universe@29 49 void ucx_map_free(UcxMap *map);
olaf@20 50
olaf@20 51 int ucx_map_put(UcxMap *map, UcxKey key, void *data);
olaf@20 52 void* ucx_map_get(UcxMap *map, UcxKey key);
olaf@20 53
olaf@30 54 #define ucx_map_sstr_put(m, s, d) ucx_map_put(m, ucx_key(s.ptr, s.length), d)
universe@29 55 #define ucx_map_cstr_put(m, s, d) ucx_map_put(m, ucx_key(s, 1+strlen(s)), d)
olaf@30 56 #define ucx_map_sstr_get(m, s) ucx_map_get(m, ucx_key(s.ptr, s.length))
universe@29 57 #define ucx_map_cstr_get(m, s) ucx_map_get(m, ucx_key(s, 1+strlen(s)))
olaf@20 58
olaf@20 59 UcxKey ucx_key(void *data, size_t len);
olaf@20 60
olaf@20 61 int ucx_hash(char *data, size_t len);
olaf@2 62
olaf@31 63 UcxMapIterator ucx_map_iterator(UcxMap *map);
olaf@31 64
olaf@31 65 int ucx_map_iter_next(UcxMapIterator *i, void **elm);
olaf@31 66
olaf@2 67 #ifdef __cplusplus
olaf@2 68 }
olaf@2 69 #endif
olaf@2 70
olaf@2 71 #endif /* MAP_H */
olaf@2 72

mercurial