digest-murmurhash 0.3.0 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3ae0e93d61ad1118ff16e6a8ee49e2624bfe93c6
4
- data.tar.gz: 221199ad7ef8c94e0eba38d57ec6f0387652e051
3
+ metadata.gz: e4bb19a065230c4cf479bbc3e5d30a3ecacaab7e
4
+ data.tar.gz: 8b6b55cb5d5d3c398e9ac006b5b84359272c034d
5
5
  SHA512:
6
- metadata.gz: 1b4b91306a2c297fb8809037693c9ec30ca87352bc047dcad25b099513183e4534b0b260104133ea94054c129eccf5192604331b493e5076361b8c3e104ca610
7
- data.tar.gz: 58bad31ff82316ca28e66a37dd0709f08bbb59e7df2839f78b80ca1dee00799ee925a3e8f25dab272d1c5d893708a017ae2d8d882db5029aca73b09f475e82fa
6
+ metadata.gz: 09aa8502b047d0487b5727846236e91c33d06e7db3bfdc89f74ddc71f935d7f672232d3c6e27fc5c588fe6c90fb8d151e7611c356e2c168e216e20822862d07a
7
+ data.tar.gz: 1b6a03328a0428b3cc5455ca306fcc4d5bab0c5a8609300e9b7dbc774a499b8921d9f5b96b653ec3c72b8fa4d59cec5fcffe09447eac5d84f1c1b5ef4dc92771
@@ -2,4 +2,5 @@ language: ruby
2
2
  rvm:
3
3
  - 1.9.3
4
4
  - 2.0.0
5
- - 2.1.0
5
+ - 2.1.3
6
+ - 2.2.0
data/Rakefile CHANGED
@@ -17,8 +17,7 @@ Rake::ExtensionTask.new('murmurhash', spec) do |ext|
17
17
  ext.lib_dir = 'lib/digest/murmurhash'
18
18
  end
19
19
 
20
- require 'digest/murmurhash/version'
21
- desc "gem reinstall v#{Digest::MurmurHash::VERSION}"
20
+ desc "gem reinstall"
22
21
  task :reinstall do |t|
23
22
  system "gem uninstall murmurhash"
24
23
  system "rake clean"
@@ -1,11 +1,8 @@
1
1
  # coding: utf-8
2
- lib = File.expand_path('../lib', __FILE__)
3
- $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
- require 'digest/murmurhash/version'
5
2
 
6
3
  Gem::Specification.new do |spec|
7
4
  spec.name = "digest-murmurhash"
8
- spec.version = Digest::MurmurHash::VERSION
5
+ spec.version = "1.0.0"
9
6
  spec.author = "ksss"
10
7
  spec.email = "co000ri@gmail.com"
11
8
  spec.description = %q{Digest::MurmurHash is class collections of use algorithm MurmurHash desiged by Austin Appleby.}
@@ -19,9 +16,9 @@ Gem::Specification.new do |spec|
19
16
  spec.require_paths = ["lib"]
20
17
  spec.extensions = ["ext/digest/murmurhash/extconf.rb"]
21
18
 
22
- spec.add_runtime_dependency "digest-stringbuffer", ["~> 0.0.2"]
23
- spec.add_development_dependency "bundler", "~> 1.3"
19
+ spec.add_runtime_dependency "digest-simple"
20
+ spec.add_development_dependency "bundler"
24
21
  spec.add_development_dependency "rake"
25
- spec.add_development_dependency "rspec", ['~> 2.11']
26
- spec.add_development_dependency "rake-compiler", ["~> 0.8.3"]
22
+ spec.add_development_dependency "rspec"
23
+ spec.add_development_dependency "rake-compiler"
27
24
  end
@@ -1,6 +1,3 @@
1
1
  require 'mkmf'
2
2
 
3
- $preload = %w[digest]
4
- $CFLAGS << " -Wall"
5
-
6
3
  create_makefile('digest/murmurhash/murmurhash')
@@ -8,246 +8,165 @@
8
8
  #include "murmurhash_aligned2.h"
9
9
 
10
10
  VALUE cDigest_MurmurHash1,
11
- cDigest_MurmurHash2,
12
- cDigest_MurmurHash2A,
13
- cDigest_MurmurHash64A,
14
- cDigest_MurmurHash64B,
15
- cDigest_MurmurHashNeutral2,
16
- cDigest_MurmurHashAligned2;
17
- ID id_seed,
18
- id_DEFAULT_SEED;
19
-
20
- VALUE
21
- murmur_seed_get32(VALUE self)
22
- {
23
- if (!rb_ivar_defined(self, id_seed)) {
24
- rb_ivar_set(self, id_seed, rb_usascii_str_new(DEFAULT_SEED, 4));
25
- }
26
- return rb_ivar_get(self, id_seed);
27
- }
28
-
29
- VALUE
30
- murmur_seed_set32(VALUE self, VALUE obj)
31
- {
32
- StringValue(obj);
33
- if (RSTRING_LEN(obj) != 4) {
34
- rb_raise(rb_eArgError, "seed string should 64 bit chars");
35
- }
36
- return rb_ivar_set(self, id_seed, obj);
37
- }
11
+ cDigest_MurmurHash2,
12
+ cDigest_MurmurHash2A,
13
+ cDigest_MurmurHash64A,
14
+ cDigest_MurmurHash64B,
15
+ cDigest_MurmurHashNeutral2,
16
+ cDigest_MurmurHashAligned2;
17
+ ID id_DEFAULT_SEED;
18
+ ID iv_seed;
19
+ ID iv_buffer;
38
20
 
39
- VALUE
40
- murmur_seed_get64(VALUE self)
21
+ void
22
+ assign_by_endian_32(uint8_t *digest, uint64_t h)
41
23
  {
42
- if (!rb_ivar_defined(self, id_seed)) {
43
- rb_ivar_set(self, id_seed, rb_usascii_str_new(DEFAULT_SEED, 8));
44
- }
45
- return rb_ivar_get(self, id_seed);
24
+ if (BIGENDIAN_P()) {
25
+ digest[0] = h >> 24;
26
+ digest[1] = h >> 16;
27
+ digest[2] = h >> 8;
28
+ digest[3] = h;
29
+ }
30
+ else {
31
+ digest[3] = h >> 24;
32
+ digest[2] = h >> 16;
33
+ digest[1] = h >> 8;
34
+ digest[0] = h;
35
+ }
46
36
  }
47
37
 
48
- VALUE
49
- murmur_seed_set64(VALUE self, VALUE obj)
38
+ void
39
+ assign_by_endian_64(uint8_t *digest, uint64_t h)
50
40
  {
51
- StringValue(obj);
52
- if (RSTRING_LEN(obj) != 8) {
53
- rb_raise(rb_eArgError, "seed string should 64 bit chars");
54
- }
55
- return rb_ivar_set(self, id_seed, obj);
41
+ if (BIGENDIAN_P()) {
42
+ digest[0] = h >> 56;
43
+ digest[1] = h >> 48;
44
+ digest[2] = h >> 40;
45
+ digest[3] = h >> 32;
46
+ digest[4] = h >> 24;
47
+ digest[5] = h >> 16;
48
+ digest[6] = h >> 8;
49
+ digest[7] = h;
50
+ }
51
+ else {
52
+ digest[7] = h >> 56;
53
+ digest[6] = h >> 48;
54
+ digest[5] = h >> 40;
55
+ digest[4] = h >> 32;
56
+ digest[3] = h >> 24;
57
+ digest[2] = h >> 16;
58
+ digest[1] = h >> 8;
59
+ digest[0] = h;
60
+ }
56
61
  }
57
62
 
58
63
  uint32_t
59
64
  _murmur_finish32(VALUE self, uint32_t (*process)(const char *, uint32_t, uint32_t))
60
65
  {
61
- const char *seed = RSTRING_PTR(murmur_seed_get32(self));
62
- MURMURHASH(self, ptr);
63
- return process(ptr->buffer, ptr->p - ptr->buffer, *(uint32_t*)seed);
66
+ const char *seed = RSTRING_PTR(rb_ivar_get(self, iv_seed));
67
+ VALUE buffer = rb_ivar_get(self, iv_buffer);
68
+ return process(RSTRING_PTR(buffer), RSTRING_LEN(buffer), *(uint32_t*)seed);
64
69
  }
65
70
 
66
71
  uint64_t
67
72
  _murmur_finish64(VALUE self, uint64_t (*process)(const char *, uint32_t, uint64_t))
68
73
  {
69
- const char *seed = RSTRING_PTR(murmur_seed_get64(self));
70
- MURMURHASH(self, ptr);
71
- return process(ptr->buffer, ptr->p - ptr->buffer, *(uint64_t*)seed);
74
+ const char *seed = RSTRING_PTR(rb_ivar_get(self, iv_seed));
75
+ VALUE buffer = rb_ivar_get(self, iv_buffer);
76
+ return process(RSTRING_PTR(buffer), RSTRING_LEN(buffer), *(uint64_t*)seed);
72
77
  }
73
78
 
74
-
75
79
  uint32_t
76
80
  _murmur_s_digest32(int argc, VALUE *argv, VALUE klass, uint32_t (*process)(const char *, uint32_t, uint32_t))
77
81
  {
78
- VALUE str;
79
- const char *seed;
82
+ VALUE str;
83
+ const char *seed;
80
84
 
81
- if (argc < 1)
82
- rb_raise(rb_eArgError, "no data given");
85
+ if (argc < 1)
86
+ rb_raise(rb_eArgError, "no data given");
83
87
 
84
- str = *argv;
88
+ str = *argv;
85
89
 
86
- StringValue(str);
90
+ StringValue(str);
87
91
 
88
- if (1 < argc) {
89
- StringValue(argv[1]);
90
- if (RSTRING_LEN(argv[1]) != 4) {
91
- rb_raise(rb_eArgError, "seed string should 32 bit chars");
92
- }
93
- seed = RSTRING_PTR(argv[1]);
94
- } else {
95
- seed = RSTRING_PTR(rb_const_get(klass, id_DEFAULT_SEED));
96
- }
92
+ if (1 < argc) {
93
+ StringValue(argv[1]);
94
+ if (RSTRING_LEN(argv[1]) != 4) {
95
+ rb_raise(rb_eArgError, "seed string should 32 bit chars");
96
+ }
97
+ seed = RSTRING_PTR(argv[1]);
98
+ } else {
99
+ seed = RSTRING_PTR(rb_const_get(klass, id_DEFAULT_SEED));
100
+ }
97
101
 
98
- return process(RSTRING_PTR(str), RSTRING_LEN(str), *(uint32_t*)seed);
102
+ return process(RSTRING_PTR(str), RSTRING_LEN(str), *(uint32_t*)seed);
99
103
  }
100
104
 
101
105
  uint64_t
102
106
  _murmur_s_digest64(int argc, VALUE *argv, VALUE klass, uint64_t (*process)(const char *, uint32_t, uint64_t))
103
107
  {
104
- VALUE str;
105
- const char *seed;
108
+ VALUE str;
109
+ const char *seed;
106
110
 
107
- if (argc < 1)
108
- rb_raise(rb_eArgError, "no data given");
111
+ if (argc < 1)
112
+ rb_raise(rb_eArgError, "no data given");
109
113
 
110
- str = *argv;
114
+ str = *argv;
111
115
 
112
- StringValue(str);
116
+ StringValue(str);
113
117
 
114
- if (1 < argc) {
115
- StringValue(argv[1]);
116
- if (RSTRING_LEN(argv[1]) != 8) {
117
- rb_raise(rb_eArgError, "seed string should 64 bit chars");
118
- }
119
- seed = RSTRING_PTR(argv[1]);
120
- } else {
121
- seed = RSTRING_PTR(rb_const_get(klass, id_DEFAULT_SEED));
122
- }
118
+ if (1 < argc) {
119
+ StringValue(argv[1]);
120
+ if (RSTRING_LEN(argv[1]) != 8) {
121
+ rb_raise(rb_eArgError, "seed string should 64 bit chars");
122
+ }
123
+ seed = RSTRING_PTR(argv[1]);
124
+ } else {
125
+ seed = RSTRING_PTR(rb_const_get(klass, id_DEFAULT_SEED));
126
+ }
123
127
 
124
- return process(RSTRING_PTR(str), RSTRING_LEN(str), *(uint64_t*)seed);
125
- }
126
-
127
- /*
128
- * from https://github.com/ruby/ruby/blob/trunk/ext/digest/digest.c
129
- * Copyright (C) 1995-2001 Yukihiro Matsumoto
130
- * Copyright (C) 2001-2006 Akinori MUSHA
131
- */
132
- VALUE
133
- hexencode_str_new(VALUE str_digest)
134
- {
135
- char *digest;
136
- size_t digest_len;
137
- size_t i;
138
- VALUE str;
139
- char *p;
140
- static const char hex[] = {
141
- '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
142
- 'a', 'b', 'c', 'd', 'e', 'f'
143
- };
144
-
145
- StringValue(str_digest);
146
- digest = RSTRING_PTR(str_digest);
147
- digest_len = RSTRING_LEN(str_digest);
148
-
149
- if (LONG_MAX / 2 < digest_len) {
150
- rb_raise(rb_eRuntimeError, "digest string too long");
151
- }
152
-
153
- str = rb_usascii_str_new(0, digest_len * 2);
154
-
155
- for (i = 0, p = RSTRING_PTR(str); i < digest_len; i++) {
156
- unsigned char byte = digest[i];
157
-
158
- p[i + i] = hex[byte >> 4];
159
- p[i + i + 1] = hex[byte & 0x0f];
160
- }
161
-
162
- return str;
128
+ return process(RSTRING_PTR(str), RSTRING_LEN(str), *(uint64_t*)seed);
163
129
  }
164
130
 
165
131
  void
166
132
  Init_murmurhash(void)
167
133
  {
168
- VALUE mDigest, cDigest_StringBuffer;
169
-
170
- id_seed = rb_intern("seed");
171
- id_DEFAULT_SEED = rb_intern("DEFAULT_SEED");
172
-
173
- /* Digest::MurmurHash is require that Digest::StringBuffer */
174
- mDigest = rb_path2class("Digest");
175
- cDigest_StringBuffer = rb_path2class("Digest::StringBuffer");
176
-
177
- /* class Digest::MurmurHash1 < Digest::StringBuffer */
178
- cDigest_MurmurHash1 = rb_define_class_under(mDigest, "MurmurHash1", cDigest_StringBuffer);
179
- rb_define_const(cDigest_MurmurHash1, "DEFAULT_SEED", rb_usascii_str_new(DEFAULT_SEED, 4));
180
- rb_define_singleton_method(cDigest_MurmurHash1, "digest", murmur1_s_digest, -1);
181
- rb_define_singleton_method(cDigest_MurmurHash1, "hexdigest", murmur1_s_hexdigest, -1);
182
- rb_define_singleton_method(cDigest_MurmurHash1, "rawdigest", murmur1_s_rawdigest, -1);
183
- rb_define_private_method(cDigest_MurmurHash1, "finish", murmur1_finish, 0);
184
- rb_define_method(cDigest_MurmurHash1, "to_i", murmur1_to_i, 0);
185
- rb_define_method(cDigest_MurmurHash1, "seed", murmur_seed_get32, 0);
186
- rb_define_method(cDigest_MurmurHash1, "seed=", murmur_seed_set32, 1);
187
-
188
- /* class Digest::MurmurHash2 < Digest::StringBuffer */
189
- cDigest_MurmurHash2 = rb_define_class_under(mDigest, "MurmurHash2", cDigest_StringBuffer);
190
- rb_define_const(cDigest_MurmurHash2, "DEFAULT_SEED", rb_usascii_str_new(DEFAULT_SEED, 4));
191
- rb_define_singleton_method(cDigest_MurmurHash2, "digest", murmur2_s_digest, -1);
192
- rb_define_singleton_method(cDigest_MurmurHash2, "hexdigest", murmur2_s_hexdigest, -1);
193
- rb_define_singleton_method(cDigest_MurmurHash2, "rawdigest", murmur2_s_rawdigest, -1);
194
- rb_define_private_method(cDigest_MurmurHash2, "finish", murmur2_finish, 0);
195
- rb_define_method(cDigest_MurmurHash2, "to_i", murmur2_to_i, 0);
196
- rb_define_method(cDigest_MurmurHash2, "seed", murmur_seed_get32, 0);
197
- rb_define_method(cDigest_MurmurHash2, "seed=", murmur_seed_set32, 1);
198
-
199
- /* class Digest::MurmurHash2A < Digest::StringBuffer */
200
- cDigest_MurmurHash2A = rb_define_class_under(mDigest, "MurmurHash2A", cDigest_StringBuffer);
201
- rb_define_const(cDigest_MurmurHash2A, "DEFAULT_SEED", rb_usascii_str_new(DEFAULT_SEED, 4));
202
- rb_define_singleton_method(cDigest_MurmurHash2A, "digest", murmur2a_s_digest, -1);
203
- rb_define_singleton_method(cDigest_MurmurHash2A, "hexdigest", murmur2a_s_hexdigest, -1);
204
- rb_define_singleton_method(cDigest_MurmurHash2A, "rawdigest", murmur2a_s_rawdigest, -1);
205
- rb_define_private_method(cDigest_MurmurHash2A, "finish", murmur2a_finish, 0);
206
- rb_define_method(cDigest_MurmurHash2A, "to_i", murmur2a_to_i, 0);
207
- rb_define_method(cDigest_MurmurHash2A, "seed", murmur_seed_get32, 0);
208
- rb_define_method(cDigest_MurmurHash2A, "seed=", murmur_seed_set32, 1);
209
-
210
- /* class Digest::MurmurHash64A < Digest::StringBuffer */
211
- cDigest_MurmurHash64A = rb_define_class_under(mDigest, "MurmurHash64A", cDigest_StringBuffer);
212
- rb_define_const(cDigest_MurmurHash64A, "DEFAULT_SEED", rb_usascii_str_new(DEFAULT_SEED, 8));
213
- rb_define_singleton_method(cDigest_MurmurHash64A, "digest", murmur64a_s_digest, -1);
214
- rb_define_singleton_method(cDigest_MurmurHash64A, "hexdigest", murmur64a_s_hexdigest, -1);
215
- rb_define_singleton_method(cDigest_MurmurHash64A, "rawdigest", murmur64a_s_rawdigest, -1);
216
- rb_define_private_method(cDigest_MurmurHash64A, "finish", murmur64a_finish, 0);
217
- rb_define_method(cDigest_MurmurHash64A, "to_i", murmur64a_to_i, 0);
218
- rb_define_method(cDigest_MurmurHash64A, "seed", murmur_seed_get64, 0);
219
- rb_define_method(cDigest_MurmurHash64A, "seed=", murmur_seed_set64, 1);
220
-
221
- /* class Digest::MurmurHash64B < Digest::StringBuffer */
222
- cDigest_MurmurHash64B = rb_define_class_under(mDigest, "MurmurHash64B", cDigest_StringBuffer);
223
- rb_define_const(cDigest_MurmurHash64B, "DEFAULT_SEED", rb_usascii_str_new(DEFAULT_SEED, 8));
224
- rb_define_singleton_method(cDigest_MurmurHash64B, "digest", murmur64b_s_digest, -1);
225
- rb_define_singleton_method(cDigest_MurmurHash64B, "hexdigest", murmur64b_s_hexdigest, -1);
226
- rb_define_singleton_method(cDigest_MurmurHash64B, "rawdigest", murmur64b_s_rawdigest, -1);
227
- rb_define_private_method(cDigest_MurmurHash64B, "finish", murmur64b_finish, 0);
228
- rb_define_method(cDigest_MurmurHash64B, "to_i", murmur64b_to_i, 0);
229
- rb_define_method(cDigest_MurmurHash64B, "seed", murmur_seed_get64, 0);
230
- rb_define_method(cDigest_MurmurHash64B, "seed=", murmur_seed_set64, 1);
231
-
232
- /* class Digest::MurmurHashNeutral2 < Digest::StringBuffer */
233
- cDigest_MurmurHashNeutral2 = rb_define_class_under(mDigest, "MurmurHashNeutral2", cDigest_StringBuffer);
234
- rb_define_const(cDigest_MurmurHashNeutral2, "DEFAULT_SEED", rb_usascii_str_new(DEFAULT_SEED, 4));
235
- rb_define_singleton_method(cDigest_MurmurHashNeutral2, "digest", murmur_neutral2_s_digest, -1);
236
- rb_define_singleton_method(cDigest_MurmurHashNeutral2, "hexdigest", murmur_neutral2_s_hexdigest, -1);
237
- rb_define_singleton_method(cDigest_MurmurHashNeutral2, "rawdigest", murmur_neutral2_s_rawdigest, -1);
238
- rb_define_private_method(cDigest_MurmurHashNeutral2, "finish", murmur_neutral2_finish, 0);
239
- rb_define_method(cDigest_MurmurHashNeutral2, "to_i", murmur_neutral2_to_i, 0);
240
- rb_define_method(cDigest_MurmurHashNeutral2, "seed", murmur_seed_get32, 0);
241
- rb_define_method(cDigest_MurmurHashNeutral2, "seed=", murmur_seed_set32, 1);
242
-
243
- /* class Digest::MurmurHashAligned2 < Digest::StringBuffer */
244
- cDigest_MurmurHashAligned2 = rb_define_class_under(mDigest, "MurmurHashAligned2", cDigest_StringBuffer);
245
- rb_define_const(cDigest_MurmurHashAligned2, "DEFAULT_SEED", rb_usascii_str_new(DEFAULT_SEED, 4));
246
- rb_define_singleton_method(cDigest_MurmurHashAligned2, "digest", murmur_aligned2_s_digest, -1);
247
- rb_define_singleton_method(cDigest_MurmurHashAligned2, "hexdigest", murmur_aligned2_s_hexdigest, -1);
248
- rb_define_singleton_method(cDigest_MurmurHashAligned2, "rawdigest", murmur_aligned2_s_rawdigest, -1);
249
- rb_define_private_method(cDigest_MurmurHashAligned2, "finish", murmur_aligned2_finish, 0);
250
- rb_define_method(cDigest_MurmurHashAligned2, "to_i", murmur_aligned2_to_i, 0);
251
- rb_define_method(cDigest_MurmurHashAligned2, "seed", murmur_seed_get32, 0);
252
- rb_define_method(cDigest_MurmurHashAligned2, "seed=", murmur_seed_set32, 1);
134
+ id_DEFAULT_SEED = rb_intern("DEFAULT_SEED");
135
+ iv_seed = rb_intern("@seed");
136
+ iv_buffer = rb_intern("@buffer");
137
+
138
+ cDigest_MurmurHash1 = rb_path2class("Digest::MurmurHash1");
139
+ rb_define_singleton_method(cDigest_MurmurHash1, "digest", murmur1_s_digest, -1);
140
+ rb_define_singleton_method(cDigest_MurmurHash1, "rawdigest", murmur1_s_rawdigest, -1);
141
+ rb_define_private_method(cDigest_MurmurHash1, "finish", murmur1_finish, 0);
142
+
143
+ cDigest_MurmurHash2 = rb_path2class("Digest::MurmurHash2");
144
+ rb_define_singleton_method(cDigest_MurmurHash2, "digest", murmur2_s_digest, -1);
145
+ rb_define_singleton_method(cDigest_MurmurHash2, "rawdigest", murmur2_s_rawdigest, -1);
146
+ rb_define_private_method(cDigest_MurmurHash2, "finish", murmur2_finish, 0);
147
+
148
+ cDigest_MurmurHash2A = rb_path2class("Digest::MurmurHash2A");
149
+ rb_define_singleton_method(cDigest_MurmurHash2A, "digest", murmur2a_s_digest, -1);
150
+ rb_define_singleton_method(cDigest_MurmurHash2A, "rawdigest", murmur2a_s_rawdigest, -1);
151
+ rb_define_private_method(cDigest_MurmurHash2A, "finish", murmur2a_finish, 0);
152
+
153
+ cDigest_MurmurHash64A = rb_path2class("Digest::MurmurHash64A");
154
+ rb_define_singleton_method(cDigest_MurmurHash64A, "digest", murmur64a_s_digest, -1);
155
+ rb_define_singleton_method(cDigest_MurmurHash64A, "rawdigest", murmur64a_s_rawdigest, -1);
156
+ rb_define_private_method(cDigest_MurmurHash64A, "finish", murmur64a_finish, 0);
157
+
158
+ cDigest_MurmurHash64B = rb_path2class("Digest::MurmurHash64B");
159
+ rb_define_singleton_method(cDigest_MurmurHash64B, "digest", murmur64b_s_digest, -1);
160
+ rb_define_singleton_method(cDigest_MurmurHash64B, "rawdigest", murmur64b_s_rawdigest, -1);
161
+ rb_define_private_method(cDigest_MurmurHash64B, "finish", murmur64b_finish, 0);
162
+
163
+ cDigest_MurmurHashNeutral2 = rb_path2class("Digest::MurmurHashNeutral2");
164
+ rb_define_singleton_method(cDigest_MurmurHashNeutral2, "digest", murmur_neutral2_s_digest, -1);
165
+ rb_define_singleton_method(cDigest_MurmurHashNeutral2, "rawdigest", murmur_neutral2_s_rawdigest, -1);
166
+ rb_define_private_method(cDigest_MurmurHashNeutral2, "finish", murmur_neutral2_finish, 0);
167
+
168
+ cDigest_MurmurHashAligned2 = rb_path2class("Digest::MurmurHashAligned2");
169
+ rb_define_singleton_method(cDigest_MurmurHashAligned2, "digest", murmur_aligned2_s_digest, -1);
170
+ rb_define_singleton_method(cDigest_MurmurHashAligned2, "rawdigest", murmur_aligned2_s_rawdigest, -1);
171
+ rb_define_private_method(cDigest_MurmurHashAligned2, "finish", murmur_aligned2_finish, 0);
253
172
  }
@@ -10,69 +10,37 @@
10
10
  # define BIG_CONSTANT(x) (x##LLU)
11
11
  #endif // !defined(_MSC_VER)
12
12
 
13
- #define DEFAULT_SEED "\x00\x00\x00\x00\x00\x00\x00\x00"
14
- #define MURMURHASH_MAGIC 0x5bd1e995
15
- #define MURMURHASH_MAGIC64A BIG_CONSTANT(0xc6a4a7935bd1e995)
16
- #if INTEGER_PACK_LITTLE_ENDIAN
17
- # define ASSINE_BY_ENDIAN_32(digest, h) do { \
18
- (digest)[3] = (h) >> 24; \
19
- (digest)[2] = (h) >> 16; \
20
- (digest)[1] = (h) >> 8; \
21
- (digest)[0] = (h); \
22
- } while (0)
23
- # define ASSINE_BY_ENDIAN_64(digest, h) do { \
24
- (digest)[7] = (h) >> 56; \
25
- (digest)[6] = (h) >> 48; \
26
- (digest)[5] = (h) >> 40; \
27
- (digest)[4] = (h) >> 32; \
28
- (digest)[3] = (h) >> 24; \
29
- (digest)[2] = (h) >> 16; \
30
- (digest)[1] = (h) >> 8; \
31
- (digest)[0] = (h); \
32
- } while (0)
13
+ #ifdef DYNAMIC_ENDIAN
14
+ /* for universal binary of NEXTSTEP and MacOS X */
15
+ /* useless since autoconf 2.63? */
16
+ static int
17
+ is_bigendian(void)
18
+ {
19
+ static int init = 0;
20
+ static int endian_value;
21
+ char *p;
22
+
23
+ if (init) return endian_value;
24
+ init = 1;
25
+ p = (char*)&init;
26
+ return endian_value = p[0] ? 0 : 1;
27
+ }
28
+ # define BIGENDIAN_P() (is_bigendian())
29
+ #elif defined(WORDS_BIGENDIAN)
30
+ # define BIGENDIAN_P() 1
33
31
  #else
34
- # define ASSINE_BY_ENDIAN_32(digest, h) do { \
35
- (digest)[0] = (h) >> 24; \
36
- (digest)[1] = (h) >> 16; \
37
- (digest)[2] = (h) >> 8; \
38
- (digest)[3] = (h); \
39
- } while (0)
40
- # define ASSINE_BY_ENDIAN_64(digest, h) do { \
41
- (digest)[0] = (h) >> 56; \
42
- (digest)[1] = (h) >> 48; \
43
- (digest)[2] = (h) >> 40; \
44
- (digest)[3] = (h) >> 32; \
45
- (digest)[4] = (h) >> 24; \
46
- (digest)[5] = (h) >> 16; \
47
- (digest)[6] = (h) >> 8; \
48
- (digest)[7] = (h); \
49
- } while (0)
32
+ # define BIGENDIAN_P() 0
50
33
  #endif
51
34
 
52
- /* should be same type structure to digest/stringbuffer */
53
- typedef struct {
54
- char* buffer;
55
- char* p;
56
- size_t memsize;
57
- } buffer_t;
58
-
59
- #define MURMURHASH(self, name) \
60
- buffer_t* name; \
61
- Data_Get_Struct(self, buffer_t, name); \
62
- if (name == NULL) { \
63
- rb_raise(rb_eArgError, "NULL found for " # name " when shouldn't be.'"); \
64
- }
65
-
66
- VALUE murmur_seed_get32(VALUE self);
67
- VALUE murmur_seed_get64(VALUE self);
35
+ #define MURMURHASH_MAGIC 0x5bd1e995
36
+ #define MURMURHASH_MAGIC64A BIG_CONSTANT(0xc6a4a7935bd1e995)
68
37
 
69
- extern ID id_seed, id_DEFAULT_SEED;
38
+ void assign_by_endian_32(uint8_t *digest, uint64_t h);
39
+ void assign_by_endian_64(uint8_t *digest, uint64_t h);
70
40
 
71
41
  uint32_t _murmur_finish32(VALUE self, uint32_t (*process)(const char *, uint32_t, uint32_t));
72
42
  uint64_t _murmur_finish64(VALUE self, uint64_t (*process)(const char *, uint32_t, uint64_t));
73
43
  uint32_t _murmur_s_digest32(int argc, VALUE *argv, VALUE klass, uint32_t (*process)(const char *, uint32_t, uint32_t));
74
44
  uint64_t _murmur_s_digest64(int argc, VALUE *argv, VALUE klass, uint64_t (*process)(const char *, uint32_t, uint64_t));
75
- VALUE hexencode_str_new(VALUE str_digest);
76
45
 
77
46
  #endif /* ifndef MURMURHASH_INCLUDED */
78
-