ext/digest/murmurhash/murmurhash1.c in digest-murmurhash-0.2.1 vs ext/digest/murmurhash/murmurhash1.c in digest-murmurhash-0.2.2
- old
+ new
@@ -68,9 +68,40 @@
MURMURHASH(self, ptr);
return UINT2NUM(murmur_hash_process1(ptr->buffer, ptr->p - ptr->buffer));
}
VALUE
+murmur1_s_digest(int argc, VALUE *argv, VALUE klass)
+{
+ VALUE str;
+ uint32_t h;
+ uint8_t digest[4];
+
+ if (argc < 1)
+ rb_raise(rb_eArgError, "no data given");
+
+ str = *argv++;
+ argc--;
+
+ StringValue(str);
+
+ h = murmur_hash_process1(RSTRING_PTR(str), RSTRING_LEN(str));
+
+ digest[0] = h >> 24;
+ digest[1] = h >> 16;
+ digest[2] = h >> 8;
+ digest[3] = 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)
{
VALUE str;
if (argc < 1)