ext/digest/murmurhash/murmurhash.h in digest-murmurhash-0.2.3 vs ext/digest/murmurhash/murmurhash.h in digest-murmurhash-0.3.0

- old
+ new

@@ -1,11 +1,55 @@ #ifndef MURMURHASH_INCLUDED # define MURMURHASH_INCLUDED #include "ruby.h" +#if defined(_MSC_VER) +# define BIG_CONSTANT(x) (x) +// Other compilers +#else // defined(_MSC_VER) +# define BIG_CONSTANT(x) (x##LLU) +#endif // !defined(_MSC_VER) + +#define DEFAULT_SEED "\x00\x00\x00\x00\x00\x00\x00\x00" #define MURMURHASH_MAGIC 0x5bd1e995 +#define MURMURHASH_MAGIC64A BIG_CONSTANT(0xc6a4a7935bd1e995) +#if INTEGER_PACK_LITTLE_ENDIAN +# define ASSINE_BY_ENDIAN_32(digest, h) do { \ + (digest)[3] = (h) >> 24; \ + (digest)[2] = (h) >> 16; \ + (digest)[1] = (h) >> 8; \ + (digest)[0] = (h); \ +} while (0) +# define ASSINE_BY_ENDIAN_64(digest, h) do { \ + (digest)[7] = (h) >> 56; \ + (digest)[6] = (h) >> 48; \ + (digest)[5] = (h) >> 40; \ + (digest)[4] = (h) >> 32; \ + (digest)[3] = (h) >> 24; \ + (digest)[2] = (h) >> 16; \ + (digest)[1] = (h) >> 8; \ + (digest)[0] = (h); \ +} while (0) +#else +# define ASSINE_BY_ENDIAN_32(digest, h) do { \ + (digest)[0] = (h) >> 24; \ + (digest)[1] = (h) >> 16; \ + (digest)[2] = (h) >> 8; \ + (digest)[3] = (h); \ +} while (0) +# define ASSINE_BY_ENDIAN_64(digest, h) do { \ + (digest)[0] = (h) >> 56; \ + (digest)[1] = (h) >> 48; \ + (digest)[2] = (h) >> 40; \ + (digest)[3] = (h) >> 32; \ + (digest)[4] = (h) >> 24; \ + (digest)[5] = (h) >> 16; \ + (digest)[6] = (h) >> 8; \ + (digest)[7] = (h); \ +} while (0) +#endif /* should be same type structure to digest/stringbuffer */ typedef struct { char* buffer; char* p; @@ -17,45 +61,18 @@ Data_Get_Struct(self, buffer_t, name); \ if (name == NULL) { \ rb_raise(rb_eArgError, "NULL found for " # name " when shouldn't be.'"); \ } -/* - * from https://github.com/ruby/ruby/blob/trunk/ext/digest/digest.c - * Copyright (C) 1995-2001 Yukihiro Matsumoto - * Copyright (C) 2001-2006 Akinori MUSHA - */ -static VALUE -hexencode_str_new(VALUE str_digest) -{ - char *digest; - size_t digest_len; - size_t i; - VALUE str; - char *p; - static const char hex[] = { - '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', - 'a', 'b', 'c', 'd', 'e', 'f' - }; +VALUE murmur_seed_get32(VALUE self); +VALUE murmur_seed_get64(VALUE self); - StringValue(str_digest); - digest = RSTRING_PTR(str_digest); - digest_len = RSTRING_LEN(str_digest); +extern ID id_seed, id_DEFAULT_SEED; - if (LONG_MAX / 2 < digest_len) { - rb_raise(rb_eRuntimeError, "digest string too long"); - } - - str = rb_usascii_str_new(0, digest_len * 2); - - for (i = 0, p = RSTRING_PTR(str); i < digest_len; i++) { - unsigned char byte = digest[i]; - - p[i + i] = hex[byte >> 4]; - p[i + i + 1] = hex[byte & 0x0f]; - } - - return str; -} +uint32_t _murmur_finish32(VALUE self, uint32_t (*process)(const char *, uint32_t, uint32_t)); +uint64_t _murmur_finish64(VALUE self, uint64_t (*process)(const char *, uint32_t, uint64_t)); +uint32_t _murmur_s_digest32(int argc, VALUE *argv, VALUE klass, uint32_t (*process)(const char *, uint32_t, uint32_t)); +uint64_t _murmur_s_digest64(int argc, VALUE *argv, VALUE klass, uint64_t (*process)(const char *, uint32_t, uint64_t)); +VALUE hexencode_str_new(VALUE str_digest); #endif /* ifndef MURMURHASH_INCLUDED */