Implement C string key support for dictionaries
This commit is contained in:
parent
9e0583909f
commit
f9721c6b0e
2 changed files with 19 additions and 0 deletions
|
@ -37,8 +37,12 @@ int hexagram_dict_each(hexagram_dict *dict,
|
|||
|
||||
void *hexagram_dict_get(hexagram_dict *dict, void *key, size_t keysz);
|
||||
|
||||
void *hexagram_dict_get_s(hexagram_dict *dict, const char *key);
|
||||
|
||||
int hexagram_dict_delete(hexagram_dict *dict, void *key, size_t keysz);
|
||||
|
||||
int hexagram_dict_delete_s(hexagram_dict *dict, const char *key);
|
||||
|
||||
void *hexagram_dict_set_with_hash(hexagram_dict *dict,
|
||||
void *key,
|
||||
void *value,
|
||||
|
@ -49,4 +53,6 @@ void *hexagram_dict_set(hexagram_dict *dict,
|
|||
size_t keysz,
|
||||
void *value);
|
||||
|
||||
void *hexagram_dict_set_s(hexagram_dict *dict, const char *key, void *value);
|
||||
|
||||
#endif /* _HEXAGRAM_DICT_H */
|
||||
|
|
13
src/dict.c
13
src/dict.c
|
@ -201,6 +201,10 @@ error_hash:
|
|||
return NULL;
|
||||
}
|
||||
|
||||
void *hexagram_dict_get_s(hexagram_dict *dict, const char *key) {
|
||||
return hexagram_dict_get(dict, (void *)key, strlen(key));
|
||||
}
|
||||
|
||||
int hexagram_dict_delete(hexagram_dict *dict, void *key, size_t keysz) {
|
||||
hexagram_dict_slot *slot;
|
||||
uint32_t hash;
|
||||
|
@ -228,6 +232,10 @@ error_slot_find_readable:
|
|||
return -1;
|
||||
}
|
||||
|
||||
int hexagram_dict_delete_s(hexagram_dict *dict, const char *key) {
|
||||
return hexagram_dict_delete(dict, (void*)key, strlen(key));
|
||||
}
|
||||
|
||||
void *hexagram_dict_set_with_hash(hexagram_dict *dict,
|
||||
void *key,
|
||||
void *value,
|
||||
|
@ -262,3 +270,8 @@ void *hexagram_dict_set(hexagram_dict *dict,
|
|||
error_hash:
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void *hexagram_dict_set_s(hexagram_dict *dict, const char *key, void *value) {
|
||||
return hexagram_dict_set(dict, (void *)key, strlen(key), value);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue