digest-murmurhash 0.2.1 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +4 -0
- data/ext/digest/murmurhash/init.c +6 -1
- data/ext/digest/murmurhash/murmurhash.h +38 -0
- data/ext/digest/murmurhash/murmurhash1.c +31 -0
- data/ext/digest/murmurhash/murmurhash1.h +2 -0
- data/ext/digest/murmurhash/murmurhash2.c +31 -1
- data/ext/digest/murmurhash/murmurhash2.h +2 -0
- data/ext/digest/murmurhash/murmurhash2a.c +31 -1
- data/ext/digest/murmurhash/murmurhash2a.h +2 -0
- data/lib/digest/murmurhash.rb +1 -0
- data/lib/digest/murmurhash/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9c86a438d6be0a5ac713575a874d2b468e3b5f0a
|
4
|
+
data.tar.gz: 299f5d61350a387d79ddacc490c00cef42950ef8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 29cb4f0444b18e28e5034b99f77a8136195382710d0638cacec00eae8eb5b0cbfcfe8e8fc17418d2185293d99182738241551b15ab726a3d8bde0d4bd5d44f4d
|
7
|
+
data.tar.gz: 79d3dc13c2d115862860747214e57607be3a9d060c48bfbb27169e093435817cf264b449fa6e27f02896bc9763a8cda4290da190eb2c545960a4403f6c6e609e
|
data/README.md
CHANGED
@@ -8,6 +8,8 @@
|
|
8
8
|
|
9
9
|
**Digest::MurmurHash2** use algorithm MurmurHash2(32-bit).
|
10
10
|
|
11
|
+
**Digest::MurmurHash2A** use algorithm MurmurHash2A(32-bit).
|
12
|
+
|
11
13
|
(**Digest::MurmurHash** exist to write only version number)
|
12
14
|
|
13
15
|
All classes compliance Digest API of Ruby.
|
@@ -36,6 +38,8 @@ p Digest::MurmurHash2.file("./LICENSE.txt").hexdigest #=> '78678326'
|
|
36
38
|
|
37
39
|
**Digest::MurmurHash2** < Digest::StringBuffer
|
38
40
|
|
41
|
+
**Digest::MurmurHash2A** < Digest::StringBuffer
|
42
|
+
|
39
43
|
## Installation
|
40
44
|
|
41
45
|
Add this line to your application's Gemfile:
|
@@ -10,7 +10,6 @@ Init_murmurhash(void)
|
|
10
10
|
VALUE cDigest_MurmurHash1, cDigest_MurmurHash2, cDigest_MurmurHash2A;
|
11
11
|
|
12
12
|
/* Digest::MurmurHash is require that Digest::StringBuffer */
|
13
|
-
rb_require("digest/stringbuffer");
|
14
13
|
mDigest = rb_path2class("Digest");
|
15
14
|
cDigest_StringBuffer = rb_path2class("Digest::StringBuffer");
|
16
15
|
|
@@ -18,17 +17,23 @@ Init_murmurhash(void)
|
|
18
17
|
cDigest_MurmurHash1 = rb_define_class_under(mDigest, "MurmurHash1", cDigest_StringBuffer);
|
19
18
|
rb_define_private_method(cDigest_MurmurHash1, "finish", murmur1_finish, 0);
|
20
19
|
rb_define_method(cDigest_MurmurHash1, "to_i", murmur1_to_i, 0);
|
20
|
+
rb_define_singleton_method(cDigest_MurmurHash1, "digest", murmur1_s_digest, -1);
|
21
|
+
rb_define_singleton_method(cDigest_MurmurHash1, "hexdigest", murmur1_s_hexdigest, -1);
|
21
22
|
rb_define_singleton_method(cDigest_MurmurHash1, "rawdigest", murmur1_s_rawdigest, -1);
|
22
23
|
|
23
24
|
/* class Digest::MurmurHash2 < Digest::StringBuffer */
|
24
25
|
cDigest_MurmurHash2 = rb_define_class_under(mDigest, "MurmurHash2", cDigest_StringBuffer);
|
25
26
|
rb_define_private_method(cDigest_MurmurHash2, "finish", murmur2_finish, 0);
|
26
27
|
rb_define_method(cDigest_MurmurHash2, "to_i", murmur2_to_i, 0);
|
28
|
+
rb_define_singleton_method(cDigest_MurmurHash2, "digest", murmur2_s_digest, -1);
|
29
|
+
rb_define_singleton_method(cDigest_MurmurHash2, "hexdigest", murmur2_s_hexdigest, -1);
|
27
30
|
rb_define_singleton_method(cDigest_MurmurHash2, "rawdigest", murmur2_s_rawdigest, -1);
|
28
31
|
|
29
32
|
/* class Digest::MurmurHash2A < Digest::StringBuffer */
|
30
33
|
cDigest_MurmurHash2A = rb_define_class_under(mDigest, "MurmurHash2A", cDigest_StringBuffer);
|
31
34
|
rb_define_private_method(cDigest_MurmurHash2A, "finish", murmur2a_finish, 0);
|
32
35
|
rb_define_method(cDigest_MurmurHash2A, "to_i", murmur2a_to_i, 0);
|
36
|
+
rb_define_singleton_method(cDigest_MurmurHash2A, "digest", murmur2a_s_digest, -1);
|
37
|
+
rb_define_singleton_method(cDigest_MurmurHash2A, "hexdigest", murmur2a_s_hexdigest, -1);
|
33
38
|
rb_define_singleton_method(cDigest_MurmurHash2A, "rawdigest", murmur2a_s_rawdigest, -1);
|
34
39
|
}
|
@@ -19,5 +19,43 @@ typedef struct {
|
|
19
19
|
rb_raise(rb_eArgError, "NULL found for " # name " when shouldn't be.'"); \
|
20
20
|
}
|
21
21
|
|
22
|
+
/*
|
23
|
+
* from https://github.com/ruby/ruby/blob/trunk/ext/digest/digest.c
|
24
|
+
* Copyright (C) 1995-2001 Yukihiro Matsumoto
|
25
|
+
* Copyright (C) 2001-2006 Akinori MUSHA
|
26
|
+
*/
|
27
|
+
static VALUE
|
28
|
+
hexencode_str_new(VALUE str_digest)
|
29
|
+
{
|
30
|
+
char *digest;
|
31
|
+
size_t digest_len;
|
32
|
+
size_t i;
|
33
|
+
VALUE str;
|
34
|
+
char *p;
|
35
|
+
static const char hex[] = {
|
36
|
+
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
|
37
|
+
'a', 'b', 'c', 'd', 'e', 'f'
|
38
|
+
};
|
39
|
+
|
40
|
+
StringValue(str_digest);
|
41
|
+
digest = RSTRING_PTR(str_digest);
|
42
|
+
digest_len = RSTRING_LEN(str_digest);
|
43
|
+
|
44
|
+
if (LONG_MAX / 2 < digest_len) {
|
45
|
+
rb_raise(rb_eRuntimeError, "digest string too long");
|
46
|
+
}
|
47
|
+
|
48
|
+
str = rb_usascii_str_new(0, digest_len * 2);
|
49
|
+
|
50
|
+
for (i = 0, p = RSTRING_PTR(str); i < digest_len; i++) {
|
51
|
+
unsigned char byte = digest[i];
|
52
|
+
|
53
|
+
p[i + i] = hex[byte >> 4];
|
54
|
+
p[i + i + 1] = hex[byte & 0x0f];
|
55
|
+
}
|
56
|
+
|
57
|
+
return str;
|
58
|
+
}
|
59
|
+
|
22
60
|
#endif /* ifndef MURMURHASH_INCLUDED */
|
23
61
|
|
@@ -69,6 +69,37 @@ murmur1_to_i(VALUE self)
|
|
69
69
|
return UINT2NUM(murmur_hash_process1(ptr->buffer, ptr->p - ptr->buffer));
|
70
70
|
}
|
71
71
|
|
72
|
+
VALUE
|
73
|
+
murmur1_s_digest(int argc, VALUE *argv, VALUE klass)
|
74
|
+
{
|
75
|
+
VALUE str;
|
76
|
+
uint32_t h;
|
77
|
+
uint8_t digest[4];
|
78
|
+
|
79
|
+
if (argc < 1)
|
80
|
+
rb_raise(rb_eArgError, "no data given");
|
81
|
+
|
82
|
+
str = *argv++;
|
83
|
+
argc--;
|
84
|
+
|
85
|
+
StringValue(str);
|
86
|
+
|
87
|
+
h = murmur_hash_process1(RSTRING_PTR(str), RSTRING_LEN(str));
|
88
|
+
|
89
|
+
digest[0] = h >> 24;
|
90
|
+
digest[1] = h >> 16;
|
91
|
+
digest[2] = h >> 8;
|
92
|
+
digest[3] = h;
|
93
|
+
|
94
|
+
return rb_str_new((const char*) digest, 4);
|
95
|
+
}
|
96
|
+
|
97
|
+
VALUE
|
98
|
+
murmur1_s_hexdigest(int argc, VALUE *argv, VALUE klass)
|
99
|
+
{
|
100
|
+
return hexencode_str_new(murmur1_s_digest(argc, argv, klass));
|
101
|
+
}
|
102
|
+
|
72
103
|
VALUE
|
73
104
|
murmur1_s_rawdigest(int argc, VALUE *argv, VALUE klass)
|
74
105
|
{
|
@@ -5,6 +5,8 @@
|
|
5
5
|
|
6
6
|
VALUE murmur1_finish(VALUE self);
|
7
7
|
VALUE murmur1_to_i(VALUE self);
|
8
|
+
VALUE murmur1_s_digest(int argc, VALUE *argv, VALUE klass);
|
9
|
+
VALUE murmur1_s_hexdigest(int argc, VALUE *argv, VALUE klass);
|
8
10
|
VALUE murmur1_s_rawdigest(int argc, VALUE *argv, VALUE klass);
|
9
11
|
|
10
12
|
#endif /* ifndef MURMURHASH1_INCLUDED */
|
@@ -71,11 +71,41 @@ murmur2_to_i(VALUE self)
|
|
71
71
|
return UINT2NUM(murmur_hash_process2(ptr->buffer, ptr->p - ptr->buffer));
|
72
72
|
}
|
73
73
|
|
74
|
+
VALUE
|
75
|
+
murmur2_s_digest(int argc, VALUE *argv, VALUE klass)
|
76
|
+
{
|
77
|
+
VALUE str;
|
78
|
+
uint32_t h;
|
79
|
+
uint8_t digest[4];
|
80
|
+
|
81
|
+
if (argc < 1)
|
82
|
+
rb_raise(rb_eArgError, "no data given");
|
83
|
+
|
84
|
+
str = *argv++;
|
85
|
+
argc--;
|
86
|
+
|
87
|
+
StringValue(str);
|
88
|
+
|
89
|
+
h = murmur_hash_process2(RSTRING_PTR(str), RSTRING_LEN(str));
|
90
|
+
|
91
|
+
digest[0] = h >> 24;
|
92
|
+
digest[1] = h >> 16;
|
93
|
+
digest[2] = h >> 8;
|
94
|
+
digest[3] = h;
|
95
|
+
|
96
|
+
return rb_str_new((const char*) digest, 4);
|
97
|
+
}
|
98
|
+
|
99
|
+
VALUE
|
100
|
+
murmur2_s_hexdigest(int argc, VALUE *argv, VALUE klass)
|
101
|
+
{
|
102
|
+
return hexencode_str_new(murmur2_s_digest(argc, argv, klass));
|
103
|
+
}
|
104
|
+
|
74
105
|
VALUE
|
75
106
|
murmur2_s_rawdigest(int argc, VALUE *argv, VALUE klass)
|
76
107
|
{
|
77
108
|
VALUE str;
|
78
|
-
volatile VALUE obj;
|
79
109
|
|
80
110
|
if (argc < 1)
|
81
111
|
rb_raise(rb_eArgError, "no data given");
|
@@ -5,6 +5,8 @@
|
|
5
5
|
|
6
6
|
VALUE murmur2_finish(VALUE self);
|
7
7
|
VALUE murmur2_to_i(VALUE self);
|
8
|
+
VALUE murmur2_s_digest(int argc, VALUE *argv, VALUE klass);
|
9
|
+
VALUE murmur2_s_hexdigest(int argc, VALUE *argv, VALUE klass);
|
8
10
|
VALUE murmur2_s_rawdigest(int argc, VALUE *argv, VALUE klass);
|
9
11
|
|
10
12
|
#endif /* ifndef MURMURHASH2_INCLUDED */
|
@@ -65,11 +65,41 @@ murmur2a_to_i(VALUE self)
|
|
65
65
|
return UINT2NUM(murmur_hash_process2a(ptr->buffer, ptr->p - ptr->buffer));
|
66
66
|
}
|
67
67
|
|
68
|
+
VALUE
|
69
|
+
murmur2a_s_digest(int argc, VALUE *argv, VALUE klass)
|
70
|
+
{
|
71
|
+
VALUE str;
|
72
|
+
uint32_t h;
|
73
|
+
uint8_t digest[4];
|
74
|
+
|
75
|
+
if (argc < 1)
|
76
|
+
rb_raise(rb_eArgError, "no data given");
|
77
|
+
|
78
|
+
str = *argv++;
|
79
|
+
argc--;
|
80
|
+
|
81
|
+
StringValue(str);
|
82
|
+
|
83
|
+
h = murmur_hash_process2a(RSTRING_PTR(str), RSTRING_LEN(str));
|
84
|
+
|
85
|
+
digest[0] = h >> 24;
|
86
|
+
digest[1] = h >> 16;
|
87
|
+
digest[2] = h >> 8;
|
88
|
+
digest[3] = h;
|
89
|
+
|
90
|
+
return rb_str_new((const char*) digest, 4);
|
91
|
+
}
|
92
|
+
|
93
|
+
VALUE
|
94
|
+
murmur2a_s_hexdigest(int argc, VALUE *argv, VALUE klass)
|
95
|
+
{
|
96
|
+
return hexencode_str_new(murmur2a_s_digest(argc, argv, klass));
|
97
|
+
}
|
98
|
+
|
68
99
|
VALUE
|
69
100
|
murmur2a_s_rawdigest(int argc, VALUE *argv, VALUE klass)
|
70
101
|
{
|
71
102
|
VALUE str;
|
72
|
-
volatile VALUE obj;
|
73
103
|
|
74
104
|
if (argc < 1)
|
75
105
|
rb_raise(rb_eArgError, "no data given");
|
@@ -5,6 +5,8 @@
|
|
5
5
|
|
6
6
|
VALUE murmur2a_finish(VALUE self);
|
7
7
|
VALUE murmur2a_to_i(VALUE self);
|
8
|
+
VALUE murmur2a_s_digest(int argc, VALUE *argv, VALUE klass);
|
9
|
+
VALUE murmur2a_s_hexdigest(int argc, VALUE *argv, VALUE klass);
|
8
10
|
VALUE murmur2a_s_rawdigest(int argc, VALUE *argv, VALUE klass);
|
9
11
|
|
10
12
|
#endif /* ifndef MURMURHASH2A_INCLUDED */
|
data/lib/digest/murmurhash.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: digest-murmurhash
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- ksss
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-12-
|
11
|
+
date: 2013-12-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|