summaryrefslogtreecommitdiff
path: root/src/hash.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/hash.c')
-rw-r--r--src/hash.c28
1 files changed, 28 insertions, 0 deletions
diff --git a/src/hash.c b/src/hash.c
index a81bb76..ee24a29 100644
--- a/src/hash.c
+++ b/src/hash.c
@@ -87,5 +87,33 @@ void apk_hash_insert(struct apk_hash *h, apk_hash_item item)
void apk_hash_delete(struct apk_hash *h, apk_blob_t key)
{
+ ptrdiff_t offset = h->ops->node_offset;
+ unsigned long hash;
+ apk_hash_node *pos;
+ apk_hash_item item;
+ apk_blob_t itemkey;
+
+ hash = h->ops->hash_key(key) % h->buckets->num;
+ if (h->ops->compare_item != NULL) {
+ hlist_for_each(pos, &h->buckets->item[hash]) {
+ item = ((void *) pos) - offset;
+ if (h->ops->compare_item(item, key) == 0) {
+ hlist_del(pos, &h->buckets->item[hash]);
+ h->ops->delete_item(item);
+ return;
+ }
+
+ }
+ } else {
+ hlist_for_each(pos, &h->buckets->item[hash]) {
+ item = ((void *) pos) - offset;
+ itemkey = h->ops->get_key(item);
+ if (h->ops->compare(key, itemkey) == 0) {
+ hlist_del(pos, &h->buckets->item[hash]);
+ h->ops->delete_item(item);
+ return;
+ }
+ }
+ }
}