diff options
author | Timo Teras <timo.teras@iki.fi> | 2009-07-14 10:47:20 +0300 |
---|---|---|
committer | Timo Teras <timo.teras@iki.fi> | 2009-07-14 10:47:20 +0300 |
commit | f1985b03bdf77c049cc28b25fe6275867c25ba49 (patch) | |
tree | 54951693bad97b824e2a8f4f7fcfbd4727ca9d69 /src/apk_hash.h | |
parent | 4562f44f9bac793b8397fdf35491da5d7ef815fa (diff) | |
download | apk-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/apk_hash.h')
-rw-r--r-- | src/apk_hash.h | 36 |
1 files changed, 32 insertions, 4 deletions
diff --git a/src/apk_hash.h b/src/apk_hash.h index b9c975e..bcaaed1 100644 --- a/src/apk_hash.h +++ b/src/apk_hash.h @@ -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. */ @@ -48,8 +48,36 @@ void apk_hash_init(struct apk_hash *h, const struct apk_hash_ops *ops, void apk_hash_free(struct apk_hash *h); int apk_hash_foreach(struct apk_hash *h, apk_hash_enumerator_f e, void *ctx); -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); -void apk_hash_delete(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); +void apk_hash_insert_hashed(struct apk_hash *h, apk_hash_item item, unsigned long hash); +void apk_hash_delete_hashed(struct apk_hash *h, apk_blob_t key, unsigned long hash); + +static inline unsigned long apk_hash_from_key(struct apk_hash *h, apk_blob_t key) +{ + return h->ops->hash_key(key); +} + +static inline unsigned long apk_hash_from_item(struct apk_hash *h, apk_hash_item item) +{ + if (h->ops->hash_item != NULL) + return h->ops->hash_item(item); + return apk_hash_from_key(h, h->ops->get_key(item)); +} + +static inline apk_hash_item apk_hash_get(struct apk_hash *h, apk_blob_t key) +{ + return apk_hash_get_hashed(h, key, apk_hash_from_key(h, key)); +} + + +static inline void apk_hash_insert(struct apk_hash *h, apk_hash_item item) +{ + return apk_hash_insert_hashed(h, item, apk_hash_from_item(h, item)); +} + +static inline void apk_hash_delete(struct apk_hash *h, apk_blob_t key) +{ + return apk_hash_delete_hashed(h, key, apk_hash_from_key(h, key)); +} #endif |