diff options
author | Timo Teras <timo.teras@iki.fi> | 2009-01-14 10:44:47 +0200 |
---|---|---|
committer | Timo Teras <timo.teras@iki.fi> | 2009-01-14 10:44:47 +0200 |
commit | 15b547c55b2045e68f9f48f7d929d47b300dc3a9 (patch) | |
tree | 7f54ff0671d56e099a8551ba8325a41c4029db19 /src/hash.c | |
parent | 3309eaa90008dcd4febf907f619a2f4f060d08b6 (diff) | |
download | apk-tools-15b547c55b2045e68f9f48f7d929d47b300dc3a9.tar.gz apk-tools-15b547c55b2045e68f9f48f7d929d47b300dc3a9.tar.bz2 apk-tools-15b547c55b2045e68f9f48f7d929d47b300dc3a9.tar.xz apk-tools-15b547c55b2045e68f9f48f7d929d47b300dc3a9.zip |
db: keep only filename in file entries, hash by both directory and file
Diffstat (limited to 'src/hash.c')
-rw-r--r-- | src/hash.c | 26 |
1 files changed, 18 insertions, 8 deletions
@@ -52,11 +52,19 @@ apk_hash_item apk_hash_get(struct apk_hash *h, apk_blob_t key) apk_blob_t itemkey; hash = h->ops->hash_key(key) % h->buckets->num; - 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) - return item; + 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) + return item; + } + } 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) + return item; + } } return NULL; @@ -64,12 +72,14 @@ apk_hash_item apk_hash_get(struct apk_hash *h, apk_blob_t key) void apk_hash_insert(struct apk_hash *h, apk_hash_item item) { - apk_blob_t key; unsigned long hash; apk_hash_node *node; - key = h->ops->get_key(item); - hash = h->ops->hash_key(key) % h->buckets->num; + if (h->ops->hash_item == NULL) + hash = h->ops->hash_key(h->ops->get_key(item)); + else + hash = h->ops->hash_item(item); + hash %= h->buckets->num; node = (apk_hash_node *) (item + h->ops->node_offset); hlist_add_head(node, &h->buckets->item[hash]); h->num_items++; |