ext/digest/murmurhash/murmurhash1.c in digest-murmurhash-0.3.0 vs ext/digest/murmurhash/murmurhash1.c in digest-murmurhash-1.0.0

- old
+ new

@@ -3,79 +3,67 @@ */ #include "murmurhash1.h" #define murmur1(r) do { \ - h *= m; \ - h ^= h >> r; \ + h *= m; \ + h ^= h >> r; \ } while(0) static uint32_t murmur_hash_process1(const char *data, uint32_t length, uint32_t seed) { - const uint32_t m = MURMURHASH_MAGIC; - const uint8_t r = 16; - uint32_t h; + const uint32_t m = MURMURHASH_MAGIC; + const uint8_t r = 16; + uint32_t h; - h = seed ^ (length * m); + h = seed ^ (length * m); - while (4 <= length) { - h += *(uint32_t*)data; - murmur1(r); - data += 4; - length -= 4; - } + while (4 <= length) { + h += *(uint32_t*)data; + murmur1(r); + data += 4; + length -= 4; + } - switch (length) { - case 3: - h += data[2] << 16; - case 2: - h += data[1] << 8; - case 1: - h += data[0]; - murmur1(r); - } + switch (length) { + case 3: + h += data[2] << 16; + case 2: + h += data[1] << 8; + case 1: + h += data[0]; + murmur1(r); + } - murmur1(10); - murmur1(17); + murmur1(10); + murmur1(17); - return h; + return h; } VALUE murmur1_finish(VALUE self) { - uint8_t digest[4]; - uint64_t h; + uint8_t digest[4]; + uint64_t h; - h = _murmur_finish32(self, murmur_hash_process1); - ASSINE_BY_ENDIAN_32(digest, h); - return rb_str_new((const char*) digest, 4); + h = _murmur_finish32(self, murmur_hash_process1); + assign_by_endian_32(digest, h); + return rb_str_new((const char*) digest, 4); } VALUE -murmur1_to_i(VALUE self) -{ - return UINT2NUM(_murmur_finish32(self, murmur_hash_process1)); -} - -VALUE murmur1_s_digest(int argc, VALUE *argv, VALUE klass) { - uint8_t digest[4]; - uint32_t h; - h = _murmur_s_digest32(argc, argv, klass, murmur_hash_process1); - ASSINE_BY_ENDIAN_32(digest, h); - return rb_str_new((const char*) digest, 4); + uint8_t digest[4]; + uint32_t h; + h = _murmur_s_digest32(argc, argv, klass, murmur_hash_process1); + assign_by_endian_32(digest, h); + return rb_str_new((const char*) digest, 4); } VALUE -murmur1_s_hexdigest(int argc, VALUE *argv, VALUE klass) -{ - return hexencode_str_new(murmur1_s_digest(argc, argv, klass)); -} - -VALUE murmur1_s_rawdigest(int argc, VALUE *argv, VALUE klass) { - return UINT2NUM(_murmur_s_digest32(argc, argv, klass, murmur_hash_process1)); + return UINT2NUM(_murmur_s_digest32(argc, argv, klass, murmur_hash_process1)); }