diff options
author | Kevin McCarthy <kevin@8t8.us> | 2017-01-28 18:47:48 -0800 |
---|---|---|
committer | Kevin McCarthy <kevin@8t8.us> | 2017-01-28 18:47:48 -0800 |
commit | f538c3ca16b2ba9682c6c9799120d379ea4afd68 (patch) | |
tree | b3acf21c8e2ca9d6cd396e84a6d9842b0b44dfe7 /hash.c | |
parent | 705801c1c2ce97531be392e6bd553c9671fdcb1e (diff) |
Add hash_find_elem to get the hash element.
This will be used in the following patch for directly manipulating the
label counter.
Diffstat (limited to 'hash.c')
-rw-r--r-- | hash.c | 20 |
1 files changed, 18 insertions, 2 deletions
@@ -172,7 +172,7 @@ int int_hash_insert (HASH * table, unsigned int intkey, void *data, int allow_du return union_hash_insert (table, key, data, allow_dup); } -static void *union_hash_find (const HASH *table, union hash_key key) +static struct hash_elem *union_hash_find_elem (const HASH *table, union hash_key key) { int hash; struct hash_elem *ptr; @@ -185,11 +185,20 @@ static void *union_hash_find (const HASH *table, union hash_key key) for (; ptr; ptr = ptr->next) { if (table->cmp_key (key, ptr->key) == 0) - return (ptr->data); + return (ptr); } return NULL; } +static void *union_hash_find (const HASH *table, union hash_key key) +{ + struct hash_elem *ptr = union_hash_find_elem (table, key); + if (ptr) + return ptr->data; + else + return NULL; +} + void *hash_find (const HASH *table, const char *strkey) { union hash_key key; @@ -197,6 +206,13 @@ void *hash_find (const HASH *table, const char *strkey) return union_hash_find (table, key); } +struct hash_elem *hash_find_elem (const HASH *table, const char *strkey) +{ + union hash_key key; + key.strkey = strkey; + return union_hash_find_elem (table, key); +} + void *int_hash_find (const HASH *table, unsigned int intkey) { union hash_key key; |