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

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

mercurial