]> git.tuebingen.mpg.de Git - paraslash.git/blobdiff - hash.h
Merge the new afs code.
[paraslash.git] / hash.h
diff --git a/hash.h b/hash.h
new file mode 100644 (file)
index 0000000..99f4486
--- /dev/null
+++ b/hash.h
@@ -0,0 +1,32 @@
+#include "portable_io.h"
+#define HASH_TYPE unsigned char
+
+//#include "super_fast_hash.h"
+//#define hash_function super_fast_hash
+#include "sha1.h"
+#define hash_function sha1_hash
+
+static inline int hash_compare(HASH_TYPE *h1, HASH_TYPE *h2)
+{
+       int i;
+
+       for (i = 0; i < HASH_SIZE; i++) {
+               if (h1[i] < h2[i])
+                       return -1;
+               if (h1[i] > h2[i])
+                       return 1;
+       }
+       return 0;
+}
+
+static inline void hash_to_asc(HASH_TYPE *hash, char *asc)
+{
+       int i;
+       const char hexchar[] = "0123456789abcdef";
+
+       for (i = 0; i < HASH_SIZE; i++) {
+               asc[2 * i] = hexchar[hash[i] >> 4];
+               asc[2 * i + 1] = hexchar[hash[i] & 0xf];
+       }
+       asc[2 * HASH_SIZE] = '\0';
+}