summaryrefslogtreecommitdiff
path: root/src/hash.c
diff options
context:
space:
mode:
authorTimo Teras <timo.teras@iki.fi>2009-07-14 10:47:20 +0300
committerTimo Teras <timo.teras@iki.fi>2009-07-14 10:47:20 +0300
commitf1985b03bdf77c049cc28b25fe6275867c25ba49 (patch)
tree54951693bad97b824e2a8f4f7fcfbd4727ca9d69 /src/hash.c
parent4562f44f9bac793b8397fdf35491da5d7ef815fa (diff)
downloadapk-tools-f1985b03bdf77c049cc28b25fe6275867c25ba49.tar.gz
apk-tools-f1985b03bdf77c049cc28b25fe6275867c25ba49.tar.bz2
apk-tools-f1985b03bdf77c049cc28b25fe6275867c25ba49.tar.xz
apk-tools-f1985b03bdf77c049cc28b25fe6275867c25ba49.zip
hash: allow caching of hash value
Diffstat (limited to 'src/hash.c')
-rw-r--r--src/hash.c19
1 files changed, 6 insertions, 13 deletions
diff --git a/src/hash.c b/src/hash.c
index 8013d06..c85a29d 100644
--- a/src/hash.c
+++ b/src/hash.c
@@ -4,7 +4,7 @@
* Copyright (C) 2008 Timo Teräs <timo.teras@iki.fi>
* All rights reserved.
*
- * This program is free software; you can redistribute it and/or modify it
+ * This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 as published
* by the Free Software Foundation. See http://www.gnu.org/ for details.
*/
@@ -43,15 +43,14 @@ int apk_hash_foreach(struct apk_hash *h, apk_hash_enumerator_f e, void *ctx)
return 0;
}
-apk_hash_item apk_hash_get(struct apk_hash *h, apk_blob_t key)
+apk_hash_item apk_hash_get_hashed(struct apk_hash *h, apk_blob_t key, unsigned long hash)
{
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;
+ hash %= h->buckets->num;
if (h->ops->compare_item != NULL) {
hlist_for_each(pos, &h->buckets->item[hash]) {
item = ((void *) pos) - offset;
@@ -70,30 +69,24 @@ apk_hash_item apk_hash_get(struct apk_hash *h, apk_blob_t key)
return NULL;
}
-void apk_hash_insert(struct apk_hash *h, apk_hash_item item)
+void apk_hash_insert_hashed(struct apk_hash *h, apk_hash_item item, unsigned long hash)
{
- unsigned long hash;
apk_hash_node *node;
- 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++;
}
-void apk_hash_delete(struct apk_hash *h, apk_blob_t key)
+void apk_hash_delete_hashed(struct apk_hash *h, apk_blob_t key, unsigned long hash)
{
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;
+ hash %= h->buckets->num;
if (h->ops->compare_item != NULL) {
hlist_for_each(pos, &h->buckets->item[hash]) {
item = ((void *) pos) - offset;