summaryrefslogtreecommitdiffstats
path: root/src/hash.c
diff options
context:
space:
mode:
authorTimo Teras <timo.teras@iki.fi>2009-01-14 10:44:47 +0200
committerTimo Teras <timo.teras@iki.fi>2009-01-14 10:44:47 +0200
commit15b547c55b2045e68f9f48f7d929d47b300dc3a9 (patch)
tree7f54ff0671d56e099a8551ba8325a41c4029db19 /src/hash.c
parent3309eaa90008dcd4febf907f619a2f4f060d08b6 (diff)
downloadapk-tools-15b547c55b2045e68f9f48f7d929d47b300dc3a9.tar.bz2
apk-tools-15b547c55b2045e68f9f48f7d929d47b300dc3a9.tar.xz
db: keep only filename in file entries, hash by both directory and file
Diffstat (limited to 'src/hash.c')
-rw-r--r--src/hash.c26
1 files changed, 18 insertions, 8 deletions
diff --git a/src/hash.c b/src/hash.c
index 9260b9b..a81bb76 100644
--- a/src/hash.c
+++ b/src/hash.c
@@ -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++;