diff options
author | Nathan S. Evans <evans@in.tum.de> | 2010-09-21 12:55:24 +0000 |
---|---|---|
committer | Nathan S. Evans <evans@in.tum.de> | 2010-09-21 12:55:24 +0000 |
commit | fe43907c45344d500907e593f3132db71f7e4a58 (patch) | |
tree | e6c473892b6b0cf9873ed326c773aed4e7f2e4ec /src/util | |
parent | f27f0f6afa53f94878f18bef86a5f96f8aae13c4 (diff) | |
download | gnunet-fe43907c45344d500907e593f3132db71f7e4a58.tar.gz gnunet-fe43907c45344d500907e593f3132db71f7e4a58.zip |
additional useful hash function
Diffstat (limited to 'src/util')
-rw-r--r-- | src/util/crypto_hash.c | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/src/util/crypto_hash.c b/src/util/crypto_hash.c index af492e15e..0fb2451b2 100644 --- a/src/util/crypto_hash.c +++ b/src/util/crypto_hash.c | |||
@@ -757,6 +757,28 @@ GNUNET_CRYPTO_hash_get_bit (const GNUNET_HashCode * code, unsigned int bit) | |||
757 | } | 757 | } |
758 | 758 | ||
759 | /** | 759 | /** |
760 | * Determine how many low order bits match in two | ||
761 | * GNUNET_HashCodes. i.e. - 010011 and 011111 share | ||
762 | * the first two lowest order bits, and therefore the | ||
763 | * return value is two (NOT XOR distance, nor how many | ||
764 | * bits match absolutely!). | ||
765 | * | ||
766 | * @param first the first hashcode | ||
767 | * @param second the hashcode to compare first to | ||
768 | * | ||
769 | * @return the number of bits that match | ||
770 | */ | ||
771 | unsigned int GNUNET_CRYPTO_hash_matching_bits(const GNUNET_HashCode *first, const GNUNET_HashCode *second) | ||
772 | { | ||
773 | unsigned int i; | ||
774 | |||
775 | for (i = 0; i < sizeof (GNUNET_HashCode) * 8; i++) | ||
776 | if (GNUNET_CRYPTO_hash_get_bit (first, i) != GNUNET_CRYPTO_hash_get_bit (second, i)) | ||
777 | return i; | ||
778 | return sizeof (GNUNET_HashCode) * 8; | ||
779 | } | ||
780 | |||
781 | /** | ||
760 | * Compare function for HashCodes, producing a total ordering | 782 | * Compare function for HashCodes, producing a total ordering |
761 | * of all hashcodes. | 783 | * of all hashcodes. |
762 | * @return 1 if h1 > h2, -1 if h1 < h2 and 0 if h1 == h2. | 784 | * @return 1 if h1 > h2, -1 if h1 < h2 and 0 if h1 == h2. |