gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] r13045 - in gnunet/src: include util


From: gnunet
Subject: [GNUnet-SVN] r13045 - in gnunet/src: include util
Date: Tue, 21 Sep 2010 14:55:24 +0200

Author: nevans
Date: 2010-09-21 14:55:24 +0200 (Tue, 21 Sep 2010)
New Revision: 13045

Modified:
   gnunet/src/include/gnunet_crypto_lib.h
   gnunet/src/util/crypto_hash.c
Log:
additional useful hash function

Modified: gnunet/src/include/gnunet_crypto_lib.h
===================================================================
--- gnunet/src/include/gnunet_crypto_lib.h      2010-09-21 11:04:56 UTC (rev 
13044)
+++ gnunet/src/include/gnunet_crypto_lib.h      2010-09-21 12:55:24 UTC (rev 
13045)
@@ -484,7 +484,21 @@
 int GNUNET_CRYPTO_hash_get_bit (const GNUNET_HashCode * code,
                                 unsigned int bit);
 
+/**
+ * Determine how many low order bits match in two
+ * GNUNET_HashCodes.  i.e. - 010011 and 011111 share
+ * the first two lowest order bits, and therefore the
+ * return value is two (NOT XOR distance, nor how many
+ * bits match absolutely!).
+ *
+ * @param first the first hashcode
+ * @param second the hashcode to compare first to
+ *
+ * @return the number of bits that match
+ */
+unsigned int GNUNET_CRYPTO_hash_matching_bits(const GNUNET_HashCode *first, 
const GNUNET_HashCode *second);
 
+
 /**
  * Compare function for HashCodes, producing a total ordering
  * of all hashcodes.

Modified: gnunet/src/util/crypto_hash.c
===================================================================
--- gnunet/src/util/crypto_hash.c       2010-09-21 11:04:56 UTC (rev 13044)
+++ gnunet/src/util/crypto_hash.c       2010-09-21 12:55:24 UTC (rev 13045)
@@ -757,6 +757,28 @@
 }
 
 /**
+ * Determine how many low order bits match in two
+ * GNUNET_HashCodes.  i.e. - 010011 and 011111 share
+ * the first two lowest order bits, and therefore the
+ * return value is two (NOT XOR distance, nor how many
+ * bits match absolutely!).
+ *
+ * @param first the first hashcode
+ * @param second the hashcode to compare first to
+ *
+ * @return the number of bits that match
+ */
+unsigned int GNUNET_CRYPTO_hash_matching_bits(const GNUNET_HashCode *first, 
const GNUNET_HashCode *second)
+{
+  unsigned int i;
+
+  for (i = 0; i < sizeof (GNUNET_HashCode) * 8; i++)
+    if (GNUNET_CRYPTO_hash_get_bit (first, i) != GNUNET_CRYPTO_hash_get_bit 
(second, i))
+      return i;
+  return sizeof (GNUNET_HashCode) * 8;
+}
+
+/**
  * Compare function for HashCodes, producing a total ordering
  * of all hashcodes.
  * @return 1 if h1 > h2, -1 if h1 < h2 and 0 if h1 == h2.




reply via email to

[Prev in Thread] Current Thread [Next in Thread]