diff options
author | Martin Schanzenbach <mschanzenbach@posteo.de> | 2012-03-19 18:51:32 +0000 |
---|---|---|
committer | Martin Schanzenbach <mschanzenbach@posteo.de> | 2012-03-19 18:51:32 +0000 |
commit | d2fb255905f0c93f50db2112594307bb1265742c (patch) | |
tree | e3e9c7387e66ebae147ff4e32224baea046b5ff8 /src/util/crypto_hash.c | |
parent | cdd5f401a24438425da10a11992c2bfd9992df47 (diff) | |
download | gnunet-d2fb255905f0c93f50db2112594307bb1265742c.tar.gz gnunet-d2fb255905f0c93f50db2112594307bb1265742c.zip |
-new short hashes, new short hash cmp
Diffstat (limited to 'src/util/crypto_hash.c')
-rw-r--r-- | src/util/crypto_hash.c | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/src/util/crypto_hash.c b/src/util/crypto_hash.c index 57e37f3fd..9f8c4b9cf 100644 --- a/src/util/crypto_hash.c +++ b/src/util/crypto_hash.c | |||
@@ -669,6 +669,32 @@ GNUNET_CRYPTO_short_hash_to_enc (const struct GNUNET_CRYPTO_ShortHashCode * bloc | |||
669 | *np = '\0'; | 669 | *np = '\0'; |
670 | } | 670 | } |
671 | 671 | ||
672 | /** | ||
673 | * Compare function for ShortHashCodes, producing a total ordering | ||
674 | * of all hashcodes. | ||
675 | * | ||
676 | * @param h1 some hash code | ||
677 | * @param h2 some hash code | ||
678 | * @return 1 if h1 > h2, -1 if h1 < h2 and 0 if h1 == h2. | ||
679 | */ | ||
680 | int | ||
681 | GNUNET_CRYPTO_short_hash_cmp (const struct GNUNET_CRYPTO_ShortHashCode * h1, | ||
682 | const struct GNUNET_CRYPTO_ShortHashCode * h2) | ||
683 | { | ||
684 | unsigned int *i1; | ||
685 | unsigned int *i2; | ||
686 | int i; | ||
672 | 687 | ||
688 | i1 = (unsigned int *) h1; | ||
689 | i2 = (unsigned int *) h2; | ||
690 | for (i = (sizeof (struct GNUNET_CRYPTO_ShortHashCode) / sizeof (unsigned int)) - 1; i >= 0; i--) | ||
691 | { | ||
692 | if (i1[i] > i2[i]) | ||
693 | return 1; | ||
694 | if (i1[i] < i2[i]) | ||
695 | return -1; | ||
696 | } | ||
697 | return 0; | ||
698 | } | ||
673 | 699 | ||
674 | /* end of crypto_hash.c */ | 700 | /* end of crypto_hash.c */ |