summaryrefslogtreecommitdiff
path: root/lib/rpmhash.C
diff options
context:
space:
mode:
authorPanu Matilainen <pmatilai@redhat.com>2012-09-05 10:09:16 +0300
committerPanu Matilainen <pmatilai@redhat.com>2012-09-05 10:38:36 +0300
commit0ea18244f22450d80749e4557ebb5a060dcd2034 (patch)
tree080f824457aeef4be171f068a2317fe4fe88a761 /lib/rpmhash.C
parentb323c27d886586b7ceccd5ba33091851457deec9 (diff)
downloadlibrpm-tizen-0ea18244f22450d80749e4557ebb5a060dcd2034.tar.gz
librpm-tizen-0ea18244f22450d80749e4557ebb5a060dcd2034.tar.bz2
librpm-tizen-0ea18244f22450d80749e4557ebb5a060dcd2034.zip
Add alternative hash key add/get/check methods with prehashed key
- In cases where more than one operation is done with the same key, these can be used to avoid the relatively expensive rehashing of the key.
Diffstat (limited to 'lib/rpmhash.C')
-rw-r--r--lib/rpmhash.C53
1 files changed, 41 insertions, 12 deletions
diff --git a/lib/rpmhash.C b/lib/rpmhash.C
index 34a3c58da..281068011 100644
--- a/lib/rpmhash.C
+++ b/lib/rpmhash.C
@@ -42,16 +42,14 @@ struct HASHSTRUCT {
* Find entry in hash table.
* @param ht pointer to hash table
* @param key pointer to key value
+ * @param keyHash key hash
* @return pointer to hash bucket of key (or NULL)
*/
static
-Bucket HASHPREFIX(findEntry)(HASHTYPE ht, HTKEYTYPE key)
+Bucket HASHPREFIX(findEntry)(HASHTYPE ht, HTKEYTYPE key, unsigned int keyHash)
{
- unsigned int hash;
- Bucket b;
-
- hash = ht->fn(key) % ht->numBuckets;
- b = ht->buckets[hash];
+ unsigned int hash = keyHash % ht->numBuckets;
+ Bucket b = ht->buckets[hash];
while (b && ht->eq(b->key, key))
b = b->next;
@@ -107,13 +105,13 @@ unsigned int HASHPREFIX(KeyHash)(HASHTYPE ht, HTKEYTYPE key)
return ht->fn(key);
}
-void HASHPREFIX(AddEntry)(HASHTYPE ht, HTKEYTYPE key
+void HASHPREFIX(AddHEntry)(HASHTYPE ht, HTKEYTYPE key, unsigned int keyHash
#ifdef HTDATATYPE
, HTDATATYPE data
#endif
)
{
- unsigned int hash = ht->fn(key) % ht->numBuckets;
+ unsigned int hash = keyHash % ht->numBuckets;
Bucket b = ht->buckets[hash];
#ifdef HTDATATYPE
Bucket * b_addr = ht->buckets + hash;
@@ -157,6 +155,19 @@ void HASHPREFIX(AddEntry)(HASHTYPE ht, HTKEYTYPE key
}
}
+void HASHPREFIX(AddEntry)(HASHTYPE ht, HTKEYTYPE key
+#ifdef HTDATATYPE
+, HTDATATYPE data
+#endif
+)
+{
+#ifdef HTDATATYPE
+ HASHPREFIX(AddHEntry)(ht, key, ht->fn(key), data);
+#else
+ HASHPREFIX(AddHEntry)(ht, key, ht->fn(key));
+#endif
+}
+
void HASHPREFIX(Empty)( HASHTYPE ht)
{
Bucket b, n;
@@ -203,21 +214,26 @@ HASHTYPE HASHPREFIX(Free)(HASHTYPE ht)
return NULL;
}
-int HASHPREFIX(HasEntry)(HASHTYPE ht, HTKEYTYPE key)
+int HASHPREFIX(HasHEntry)(HASHTYPE ht, HTKEYTYPE key, unsigned int keyHash)
{
Bucket b;
- if (!(b = HASHPREFIX(findEntry)(ht, key))) return 0; else return 1;
+ if (!(b = HASHPREFIX(findEntry)(ht, key, keyHash))) return 0; else return 1;
}
-int HASHPREFIX(GetEntry)(HASHTYPE ht, HTKEYTYPE key,
+int HASHPREFIX(HasEntry)(HASHTYPE ht, HTKEYTYPE key)
+{
+ return HASHPREFIX(HasHEntry)(ht, key, ht->fn(key));
+}
+
+int HASHPREFIX(GetHEntry)(HASHTYPE ht, HTKEYTYPE key, unsigned int keyHash,
#ifdef HTDATATYPE
HTDATATYPE** data, int * dataCount,
#endif
HTKEYTYPE* tableKey)
{
Bucket b;
- int rc = ((b = HASHPREFIX(findEntry)(ht, key)) != NULL);
+ int rc = ((b = HASHPREFIX(findEntry)(ht, key, keyHash)) != NULL);
#ifdef HTDATATYPE
if (data)
@@ -231,6 +247,19 @@ int HASHPREFIX(GetEntry)(HASHTYPE ht, HTKEYTYPE key,
return rc;
}
+int HASHPREFIX(GetEntry)(HASHTYPE ht, HTKEYTYPE key,
+#ifdef HTDATATYPE
+ HTDATATYPE** data, int * dataCount,
+#endif
+ HTKEYTYPE* tableKey)
+{
+ return HASHPREFIX(GetHEntry)(ht, key, ht->fn(key),
+#ifdef HTDATATYPE
+ data, dataCount,
+#endif
+ tableKey);
+}
+
unsigned int HASHPREFIX(NumBuckets)(HASHTYPE ht) {
return ht->numBuckets;
}