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

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

mercurial