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

     1 /*
     2  * 
     3  */
     5 #ifndef MAP_H
     6 #define	MAP_H
     8 #include "ucx.h"
     9 #include "string.h"
    10 #include <stddef.h>
    12 #ifdef	__cplusplus
    13 extern "C" {
    14 #endif
    16 #define UCX_MAP_FOREACH(type,elm,map,iter) \
    17         for(type elm;ucx_map_iter_next(&iter,(void*)&elm)==0;)
    19 typedef struct UcxMap          UcxMap;
    20 typedef struct UcxKey          UcxKey;
    21 typedef struct UcxMapElement   UcxMapElement;
    22 typedef struct UcxMapIterator  UcxMapIterator;
    24 struct UcxMap {
    25     UcxMapElement **map;
    26     size_t        size;
    27 };
    29 struct UcxKey {
    30     void   *data;
    31     size_t len;
    32     int    hash;
    33 };
    35 struct UcxMapElement {
    36     void          *data;
    37     UcxMapElement *next;
    38     UcxKey        key;
    39 };
    41 struct UcxMapIterator {
    42     UcxMap        *map;
    43     UcxMapElement *cur;
    44     int           index;
    45 };
    48 UcxMap *ucx_map_new(size_t size);
    49 void ucx_map_free(UcxMap *map);
    51 int ucx_map_put(UcxMap *map, UcxKey key, void *data);
    52 void* ucx_map_get(UcxMap *map, UcxKey key);
    54 #define ucx_map_sstr_put(m, s, d) ucx_map_put(m, ucx_key(s.ptr, s.length), d)
    55 #define ucx_map_cstr_put(m, s, d) ucx_map_put(m, ucx_key(s, 1+strlen(s)), d)
    56 #define ucx_map_sstr_get(m, s) ucx_map_get(m, ucx_key(s.ptr, s.length))
    57 #define ucx_map_cstr_get(m, s) ucx_map_get(m, ucx_key(s, 1+strlen(s)))
    59 UcxKey ucx_key(void *data, size_t len);
    61 int ucx_hash(char *data, size_t len);
    63 UcxMapIterator ucx_map_iterator(UcxMap *map);
    65 int ucx_map_iter_next(UcxMapIterator *i, void **elm);
    67 #ifdef	__cplusplus
    68 }
    69 #endif
    71 #endif	/* MAP_H */

mercurial