From 3785d3202d00ecd993275957368dcdb4f896263f Mon Sep 17 00:00:00 2001 From: Davis King Date: Sat, 28 May 2011 18:06:32 -0400 Subject: [PATCH] Added comments regarding endianness and hashing. --- dlib/general_hash/hash_abstract.h | 29 +++++++++++++++++++++++++ dlib/matrix/matrix_utilities_abstract.h | 8 +++++++ 2 files changed, 37 insertions(+) diff --git a/dlib/general_hash/hash_abstract.h b/dlib/general_hash/hash_abstract.h index 5636e03a6..6cbccb81f 100644 --- a/dlib/general_hash/hash_abstract.h +++ b/dlib/general_hash/hash_abstract.h @@ -37,6 +37,11 @@ namespace dlib - Each value of seed results in a different hash function being used. (e.g. hash(item,0) should generally not be equal to hash(item,1)) - uses the murmur_hash3() routine to compute the actual hash. + - Note that the returned hash value will be different on big-endian and + little-endian systems since hash() doesn't attempt to perform any byte + swapping of the data contained in item. If you want to always obtain + the same hash then you need to byte swap the elements of item before + passing it to hash(). !*/ // ---------------------------------------------------------------------------------------- @@ -47,11 +52,19 @@ namespace dlib uint32 seed = 0 ); /*! + requires + - T is a standard layout type (e.g. a POD type like int, float, + or a simple struct). ensures - returns a 32bit hash of the data stored in item. - Each value of seed results in a different hash function being used. (e.g. hash(item,0) should generally not be equal to hash(item,1)) - uses the murmur_hash3() routine to compute the actual hash. + - Note that the returned hash value will be different on big-endian and + little-endian systems since hash() doesn't attempt to perform any byte + swapping of the data contained in item. If you want to always obtain + the same hash then you need to byte swap the elements of item before + passing it to hash(). !*/ // ---------------------------------------------------------------------------------------- @@ -62,11 +75,19 @@ namespace dlib uint32 seed = 0 ); /*! + requires + - T and U are standard layout types (e.g. POD types like int, float, + or simple structs). ensures - returns a 32bit hash of the data stored in item. - Each value of seed results in a different hash function being used. (e.g. hash(item,0) should generally not be equal to hash(item,1)) - uses the murmur_hash3() routine to compute the actual hash. + - Note that the returned hash value will be different on big-endian and + little-endian systems since hash() doesn't attempt to perform any byte + swapping of the data contained in item. If you want to always obtain + the same hash then you need to byte swap the elements of item before + passing it to hash(). !*/ // ---------------------------------------------------------------------------------------- @@ -77,11 +98,19 @@ namespace dlib uint32 seed = 0 ); /*! + requires + - T and U are standard layout types (e.g. POD types like int, float, + or simple structs). ensures - returns a 32bit hash of the data stored in item. - Each value of seed results in a different hash function being used. (e.g. hash(item,0) should generally not be equal to hash(item,1)) - uses the murmur_hash3() routine to compute the actual hash. + - Note that the returned hash value will be different on big-endian and + little-endian systems since hash() doesn't attempt to perform any byte + swapping of the data contained in item. If you want to always obtain + the same hash then you need to byte swap the elements of item before + passing it to hash(). !*/ // ---------------------------------------------------------------------------------------- diff --git a/dlib/matrix/matrix_utilities_abstract.h b/dlib/matrix/matrix_utilities_abstract.h index d1bd9ccf3..c251f03b2 100644 --- a/dlib/matrix/matrix_utilities_abstract.h +++ b/dlib/matrix/matrix_utilities_abstract.h @@ -705,11 +705,19 @@ namespace dlib uint32 seed = 0 ); /*! + requires + - T is a standard layout type (e.g. a POD type like int, float, + or a simple struct). ensures - returns a 32bit hash of the data stored in item. - Each value of seed results in a different hash function being used. (e.g. hash(item,0) should generally not be equal to hash(item,1)) - uses the murmur_hash3() routine to compute the actual hash. + - Note that the returned hash value will be different on big-endian and + little-endian systems since hash() doesn't attempt to perform any byte + swapping of the data contained in item. If you want to always obtain + the same hash then you need to byte swap the elements of item before + passing it to hash(). !*/ // ----------------------------------------------------------------------------------------