diff options
author | Katharina Fey <kookie@spacekookie.de> | 2019-07-14 02:00:32 +0100 |
---|---|---|
committer | Katharina Fey <kookie@spacekookie.de> | 2019-07-14 18:47:18 +0100 |
commit | c312e74f95fcfe9bd1e91c092a2d987cb067a075 (patch) | |
tree | b068a2030ff8fdba31cddd505ddbee20d687571c /hash.c | |
parent | 6c9c0502798681d7eaa91c81858d3c113e124676 (diff) |
Implementing HASH node `remove_key` function
Diffstat (limited to '')
-rw-r--r-- | hash.c | 12 |
1 files changed, 12 insertions, 0 deletions
@@ -65,9 +65,21 @@ err_t hash_insert_key(struct bowl *self, char *key, struct bowl *child) err_t hash_remove_key(struct bowl *self, char *key, struct bowl **child) { + CHECK(self, INVALID_STATE) + CHECK(child, INVALID_STATE) CHECK(key, INVALID_STATE) + // Even though we're a HASH node, we use an array under the hood + struct bowl_arr *arr = self->_pl.array; + CHECK(arr, INVALID_STATE) + + size_t idx; + err_t e = _hash(key, arr->size, &idx); + if(e) return e; + + (*child) = arr->ptr[idx]; + arr->ptr[idx] = NULL; return OK; } |