Skip to content

Commit

Permalink
Implement the hipack_dict_get() function
Browse files Browse the repository at this point in the history
  • Loading branch information
aperezdc committed Apr 1, 2015
1 parent cc18a4f commit 385a2c3
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion hipack-dict.c
Expand Up @@ -177,7 +177,29 @@ hipack_dict_get (const hipack_dict_t *dict,
const hipack_string_t *key)
{
assert (dict);
/* TODO */
assert (key);

uint32_t hash_val = hipack_string_hash (key) % dict->size;
hipack_dict_node_t *node = dict->nodes[hash_val];

if (node) {
if (hipack_string_equal (key, node->key)) {
return &node->value;
}

hipack_dict_node_t *last_node = node;
node = node->next;
while (node) {
if (hipack_string_equal (key, node->key)) {
last_node->next = node->next;
node->next = dict->nodes[hash_val];
dict->nodes[hash_val] = node;
return &node->value;
}
last_node = node;
node = node->next;
}
}
return NULL;
}

Expand Down

0 comments on commit 385a2c3

Please sign in to comment.