rxi / map

A type-safe hash map implementation for C

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

maybe should test map_str_t

zuoruochen opened this issue · comments

in map_set_(&(m)->base, key, &(m)->tmp, sizeof((m)->tmp)) ) , sizeof((m)->tmp)) is sizeof(ptr),the return value is always 4 or 8. I think there are some other bugs.

commented

If I understand what you're saying correctly: This is the intended behaviour -- the char arrays that you pass to a map_str_t map are treated like all other data types the map handles, such that the strings themselves are not copied (only the pointers), it is the user's responsibility to strdup() the strings before adding them to the map and free() them when removing them if that is the desired behaviour. If you are storing fixed sized strings you can wrap a char array in a struct and store those in the map instead, for example:

typedef struct {
  char s[64];
} short_str_t;

typedef map_t(short_str_t) short_str_map_t;

If you want the library to automatically copy and free string values you will have to either modify it for your use case or seek another library.