Modify eu-strip option to perform strip in post script of rpm package & add option...
[platform/upstream/rpm.git] / lib / rpmhash.C
index 016afb2..9820327 100644 (file)
@@ -4,6 +4,7 @@
  */
 
 #include "system.h"
+#include <stdio.h>
 #include "debug.h"
 
 #define Bucket JOIN(HASHTYPE,Buket)
@@ -42,16 +43,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;
@@ -102,26 +101,31 @@ static void HASHPREFIX(Resize)(HASHTYPE ht, int numBuckets) {
     ht->numBuckets = numBuckets;
 }
 
-void HASHPREFIX(AddEntry)(HASHTYPE ht, HTKEYTYPE key
+unsigned int HASHPREFIX(KeyHash)(HASHTYPE ht, HTKEYTYPE key)
+{
+    return ht->fn(key);
+}
+
+void HASHPREFIX(AddHEntry)(HASHTYPE ht, HTKEYTYPE key, unsigned int keyHash
 #ifdef HTDATATYPE
 , HTDATATYPE data
 #endif
 )
 {
-    unsigned int hash;
-    Bucket b;
-    Bucket * b_addr;
-
-    hash = ht->fn(key) % ht->numBuckets;
-    b = ht->buckets[hash];
-    b_addr = ht->buckets + hash;
+    unsigned int hash = keyHash % ht->numBuckets;
+    Bucket b = ht->buckets[hash];
+#ifdef HTDATATYPE
+    Bucket * b_addr = ht->buckets + hash;
+#endif
 
     if (b == NULL) {
        ht->bucketCount += 1;
     }
 
     while (b && ht->eq(b->key, key)) {
+#ifdef HTDATATYPE
        b_addr = &(b->next);
+#endif
        b = b->next;
     }
 
@@ -152,6 +156,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;
@@ -198,33 +215,51 @@ 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;
 }
 
-#ifdef HTDATATYPE
+int HASHPREFIX(HasEntry)(HASHTYPE ht, HTKEYTYPE key)
+{
+    return HASHPREFIX(HasHEntry)(ht, key, ht->fn(key));
+}
 
-int HASHPREFIX(GetEntry)(HASHTYPE ht, HTKEYTYPE key, HTDATATYPE** data,
-              int * dataCount, HTKEYTYPE* tableKey)
+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)
        *data = rc ? b->data : NULL;
     if (dataCount)
        *dataCount = rc ? b->dataCount : 0;
+#endif
     if (tableKey && rc)
        *tableKey = b->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;