susumu.yata
null+****@clear*****
Thu Aug 1 19:39:20 JST 2013
susumu.yata 2013-08-01 19:39:20 +0900 (Thu, 01 Aug 2013) New Revision: 92791678d0c034ff2eb00155936672c3eff5ea29 https://github.com/groonga/grnxx/commit/92791678d0c034ff2eb00155936672c3eff5ea29 Message: Use Murmur3's 64-bit finalizer for integers. Modified files: lib/grnxx/map/hash.hpp Modified: lib/grnxx/map/hash.hpp (+31 -64) =================================================================== --- lib/grnxx/map/hash.hpp 2013-07-31 16:57:09 +0900 (37b410b) +++ lib/grnxx/map/hash.hpp 2013-08-01 19:39:20 +0900 (23475ff) @@ -32,99 +32,66 @@ namespace map { template <typename T> struct Hash; -// Use key as is. +// Use Murmur3's 64-bit finalizer for integers. template <> -struct Hash<int8_t> { - using KeyArg = typename Traits<int8_t>::ArgumentType; - uint64_t operator()(KeyArg key) const { - return static_cast<uint8_t>(key); +struct Hash<uint64_t> { + uint64_t operator()(uint64_t key) const { + uint64_t hash = key; + hash ^= hash >> 33; + hash *= 0xFF51AFD7ED558CCDULL; + hash ^= hash >> 33; + hash *= 0xC4CEB9FE1A85EC53ULL; + hash ^= hash >> 33; + return hash; } }; -// Use key as is. template <> -struct Hash<uint8_t> { - using KeyArg = typename Traits<uint8_t>::ArgumentType; - uint64_t operator()(KeyArg key) const { - return key; +struct Hash<int64_t> { + uint64_t operator()(int64_t key) const { + return Hash<uint64_t>()(key); } }; -// Use key as is. template <> -struct Hash<int16_t> { - using KeyArg = typename Traits<int16_t>::ArgumentType; - uint64_t operator()(KeyArg key) const { - return static_cast<uint16_t>(key); +struct Hash<uint32_t> { + uint64_t operator()(uint32_t key) const { + return Hash<uint64_t>()(key); } }; -// Use key as is. template <> -struct Hash<uint16_t> { - using KeyArg = typename Traits<uint16_t>::ArgumentType; - uint64_t operator()(KeyArg key) const { - return key; +struct Hash<int32_t> { + uint64_t operator()(int32_t key) const { + return Hash<uint32_t>()(key); } }; -// Murmur3's 32-bit finalizer. template <> -struct Hash<int32_t> { - using KeyArg = typename Traits<int32_t>::ArgumentType; - uint64_t operator()(KeyArg key) const { - uint32_t hash = key; - hash ^= hash >> 16; - hash *= 0x85ebca6b; - hash ^= hash >> 13; - hash *= 0xc2b2ae35; - hash ^= hash >> 16; - return hash; +struct Hash<uint16_t> { + uint64_t operator()(uint16_t key) const { + return Hash<uint64_t>()(key); } }; -// Murmur3's 32-bit finalizer. template <> -struct Hash<uint32_t> { - using KeyArg = typename Traits<uint32_t>::ArgumentType; - uint64_t operator()(KeyArg key) const { - uint32_t hash = key; - hash ^= hash >> 16; - hash *= 0x85ebca6b; - hash ^= hash >> 13; - hash *= 0xC2B2AE35; - hash ^= hash >> 16; - return hash; +struct Hash<int16_t> { + uint64_t operator()(int16_t key) const { + return Hash<uint16_t>()(key); } }; -// Murmur3's 64-bit finalizer. template <> -struct Hash<int64_t> { - using KeyArg = typename Traits<int64_t>::ArgumentType; - uint64_t operator()(KeyArg key) const { - uint64_t hash = key; - hash ^= hash >> 33; - hash *= 0xFF51AFD7ED558CCD; - hash ^= hash >> 33; - hash *= 0xC4CEB9FE1A85EC53; - hash ^= hash >> 33; - return hash; +struct Hash<uint8_t> { + uint64_t operator()(uint8_t key) const { + return Hash<uint64_t>()(key); } }; -// Murmur3's 64-bit finalizer. template <> -struct Hash<uint64_t> { - using KeyArg = typename Traits<uint64_t>::ArgumentType; - uint64_t operator()(KeyArg key) const { - uint64_t hash = key; - hash ^= hash >> 33; - hash *= 0xFF51AFD7ED558CCD; - hash ^= hash >> 33; - hash *= 0xC4CEB9FE1A85EC53; - hash ^= hash >> 33; - return hash; +struct Hash<int8_t> { + uint64_t operator()(int8_t key) const { + return Hash<uint8_t>()(key); } }; -------------- next part -------------- HTML����������������������������... 下載