Imported Upstream version 0.6.10
[platform/upstream/libsolv.git] / src / hash.h
index 829085d..1290afa 100644 (file)
  * generic hash functions
  */
 
-#ifndef SATSOLVER_HASH_H
-#define SATSOLVER_HASH_H
+#ifndef LIBSOLV_HASH_H
+#define LIBSOLV_HASH_H
 
 #include "pooltypes.h"
 
+#ifdef __cplusplus
+extern "C" {
+#endif
+
 /* value of a hash */
 typedef unsigned int Hashval;
-/* mask for hash, used as modulo operator to ensure 'wrapping' of hash
-   values -> hash table */
-typedef unsigned int Hashmask;
 
 /* inside the hash table, Ids are stored. Hash maps: string -> hash -> Id */
 typedef Id *Hashtable;
@@ -51,6 +52,16 @@ strnhash(const char *str, unsigned len)
   return r;
 }
 
+static inline Hashval
+strhash_cont(const char *str, Hashval r)
+{
+  unsigned int c;
+  while ((c = *(const unsigned char *)str++) != 0)
+    r += (r << 3) + c;
+  return r;
+}
+
+
 /* hash for rel
  * rel -> hash
  */
@@ -62,11 +73,11 @@ relhash(Id name, Id evr, int flags)
 
 
 /* compute bitmask for value
- * returns smallest (2^n-1) > num
- * 
+ * returns smallest (2^n-1) > 2 * num
+ *
  * used for Hashtable 'modulo' operation
- */ 
-static inline Hashmask
+ */
+static inline Hashval
 mkmask(unsigned int num)
 {
   num *= 2;
@@ -75,4 +86,8 @@ mkmask(unsigned int num)
   return num * 2 - 1;
 }
 
-#endif /* SATSOLVER_HASH_H */
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* LIBSOLV_HASH_H */