Project

General

Profile

Bug #262 » 0001-hash_insert-check-if-key-isn-t-already-here-before.patch

Pierre-Louis Bonicoli, 2011-11-13 16:32

View differences:

src/util.c
struct hash_item *it;
assert(hash && key);
if (hash_get(hash, key))
if (hash_has_key(hash, key))
fatal("Element with key %s already in hash %x\n", key, hash);
it = bip_malloc(sizeof(struct hash_item));
......
return hi->item;
}
int hash_has_key(hash_t *hash, const char *key)
{
hash_iterator_t hi;
struct hash_item *it;
for (hash_it_init(hash, &hi); hash_it_key(&hi); hash_it_next(&hi)) {
it = list_it_item(&hi.lit);
if (hi.lit.list->cmp(it, key) == 0)
return 1;
}
return 0;
}
void *hash_remove_if_exists(hash_t *hash, const char *key)
{
assert(hash && key);
src/util.h
void *hash_it_remove(hash_iterator_t *li);
list_t *hash_keys(hash_t *hash);
void hash_rename_key(hash_t *h, const char *oldk, const char *newk);
int hash_has_key(hash_t *hash, const char *key);
int is_valid_nick(char *str);
int is_valid_username(char *str);
(1-1/2)