murmurhash3 0.1.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -293,12 +293,16 @@ rb_fmix64(VALUE self, VALUE integer)
293
293
  static VALUE
294
294
  rb_murmur3_32_str_hash(int argc, VALUE* argv, VALUE self)
295
295
  {
296
- VALUE rstr, rseed;
296
+ VALUE rstr;
297
297
  uint32_t result;
298
298
 
299
- rb_scan_args(argc, argv, "11", &rstr, &rseed);
299
+ if (argc == 0 || argc > 2) {
300
+ rb_raise(rb_eArgError, "accept 1 or 2 arguments: (string[, seed])");
301
+ }
302
+ rstr = argv[0];
303
+ StringValue(rstr);
300
304
 
301
- result = MurmurHash3_x86_32(RSTRING_PTR(rstr), RSTRING_LEN(rstr), argc == 1 ? 0 : NUM2UINT(rseed));
305
+ result = MurmurHash3_x86_32(RSTRING_PTR(rstr), RSTRING_LEN(rstr), argc == 1 ? 0 : NUM2UINT(argv[1]));
302
306
 
303
307
  return UINT2NUM(result);
304
308
  }
@@ -306,14 +310,16 @@ rb_murmur3_32_str_hash(int argc, VALUE* argv, VALUE self)
306
310
  static VALUE
307
311
  rb_murmur3_32_int32_hash(int argc, VALUE* argv, VALUE self)
308
312
  {
309
- VALUE rint, rseed;
313
+ VALUE rint;
310
314
  uint32_t _int;
311
315
  uint32_t result;
312
316
 
313
- rb_scan_args(argc, argv, "11", &rint, &rseed);
314
- _int = NUM2UINT(rint);
317
+ if (argc == 0 || argc > 2) {
318
+ rb_raise(rb_eArgError, "accept 1 or 2 arguments: (int32[, seed])");
319
+ }
320
+ _int = NUM2UINT(argv[0]);
315
321
 
316
- result = MurmurHash3_x86_32(&_int, 4, argc == 1 ? 0 : NUM2UINT(rseed));
322
+ result = MurmurHash3_x86_32(&_int, 4, argc == 1 ? 0 : NUM2UINT(argv[1]));
317
323
 
318
324
  return UINT2NUM(result);
319
325
  }
@@ -321,18 +327,20 @@ rb_murmur3_32_int32_hash(int argc, VALUE* argv, VALUE self)
321
327
  static VALUE
322
328
  rb_murmur3_32_int64_hash(int argc, VALUE* argv, VALUE self)
323
329
  {
324
- VALUE rint, rseed;
330
+ VALUE rint;
325
331
  uint64_t _int;
326
332
  uint32_t result;
327
333
 
328
- rb_scan_args(argc, argv, "11", &rint, &rseed);
334
+ if (argc == 0 || argc > 2) {
335
+ rb_raise(rb_eArgError, "accept 1 or 2 arguments: (int64[, seed])");
336
+ }
329
337
  #if SIZEOF_LONG == 8
330
- _int = NUM2ULONG(rint);
338
+ _int = NUM2ULONG(argv[0]);
331
339
  #else
332
- _int = NUM2ULL(rint);
340
+ _int = NUM2ULL(argv[0]);
333
341
  #endif
334
342
 
335
- result = MurmurHash3_x86_32(&_int, 8, argc == 1 ? 0 : NUM2UINT(rseed));
343
+ result = MurmurHash3_x86_32(&_int, 8, argc == 1 ? 0 : NUM2UINT(argv[1]));
336
344
 
337
345
  return UINT2NUM(result);
338
346
  }
@@ -340,7 +348,6 @@ rb_murmur3_32_int64_hash(int argc, VALUE* argv, VALUE self)
340
348
  #define PREPARE_128_BIT() \
341
349
  VALUE rstr, rseed, ar_result; \
342
350
  uint32_t result[4]; \
343
- rb_scan_args(argc, argv, "11", &rstr, &rseed)
344
351
 
345
352
  #define SWAP_128_BIT() do { \
346
353
  uint32_t tmp; \
@@ -363,9 +370,16 @@ rb_murmur3_32_int64_hash(int argc, VALUE* argv, VALUE self)
363
370
  static VALUE
364
371
  rb_murmur3_128_str_hash(int argc, VALUE* argv, VALUE self)
365
372
  {
366
- PREPARE_128_BIT();
373
+ VALUE rstr, ar_result;
374
+ uint32_t result[4];
375
+
376
+ if (argc == 0 || argc > 2) {
377
+ rb_raise(rb_eArgError, "accept 1 or 2 arguments: (string[, seed])");
378
+ }
379
+ rstr = argv[0];
380
+ StringValue(rstr);
367
381
 
368
- MurmurHash3_x64_128(RSTRING_PTR(rstr), RSTRING_LEN(rstr), argc == 1 ? 0 : NUM2UINT(rseed), result);
382
+ MurmurHash3_x64_128(RSTRING_PTR(rstr), RSTRING_LEN(rstr), argc == 1 ? 0 : NUM2UINT(argv[1]), result);
369
383
  #if WORDS_BIGENDIAN
370
384
  SWAP_128_BIT();
371
385
  #endif
@@ -375,12 +389,14 @@ rb_murmur3_128_str_hash(int argc, VALUE* argv, VALUE self)
375
389
  static VALUE
376
390
  rb_murmur3_128_int32_hash(int argc, VALUE* argv, VALUE self)
377
391
  {
378
- PREPARE_128_BIT();
392
+ VALUE ar_result;
393
+ uint32_t result[4], _int;
379
394
 
380
- {
381
- uint32_t _int = NUM2UINT(rstr);
382
- MurmurHash3_x64_128(&_int, 4, argc == 1 ? 0 : NUM2UINT(rseed), result);
395
+ if (argc == 0 || argc > 2) {
396
+ rb_raise(rb_eArgError, "accept 1 or 2 arguments: (int32[, seed])");
383
397
  }
398
+ _int = NUM2UINT(argv[0]);
399
+ MurmurHash3_x64_128(&_int, 4, argc == 1 ? 0 : NUM2UINT(argv[1]), result);
384
400
  #if WORDS_BIGENDIAN
385
401
  SWAP_128_BIT();
386
402
  #endif
@@ -390,16 +406,19 @@ rb_murmur3_128_int32_hash(int argc, VALUE* argv, VALUE self)
390
406
  static VALUE
391
407
  rb_murmur3_128_int64_hash(int argc, VALUE* argv, VALUE self)
392
408
  {
393
- PREPARE_128_BIT();
409
+ VALUE ar_result;
410
+ uint32_t result[4];
411
+ uint64_t _int;
394
412
 
395
- {
413
+ if (argc == 0 || argc > 2) {
414
+ rb_raise(rb_eArgError, "accept 1 or 2 arguments: (int64[, seed])");
415
+ }
396
416
  #if SIZEOF_LONG == 8
397
- uint64_t _int = NUM2ULONG(rstr);
417
+ _int = NUM2ULONG(argv[0]);
398
418
  #else
399
- uint64_t _int = NUM2ULL(rstr);
419
+ _int = NUM2ULL(argv[0]);
400
420
  #endif
401
- MurmurHash3_x64_128(&_int, 8, argc == 1 ? 0 : NUM2UINT(rseed), result);
402
- }
421
+ MurmurHash3_x64_128(&_int, 8, argc == 1 ? 0 : NUM2UINT(argv[1]), result);
403
422
  #if WORDS_BIGENDIAN
404
423
  SWAP_128_BIT();
405
424
  #endif
@@ -1,3 +1,3 @@
1
1
  module MurmurHash3
2
- VERSION = "0.1.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: murmurhash3
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1.1
4
+ version: 0.1.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-08-02 00:00:00.000000000 Z
12
+ date: 2012-08-06 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: implementation of murmur3 hashing function
15
15
  email:
@@ -52,3 +52,4 @@ specification_version: 3
52
52
  summary: implements mumur3 hashing function
53
53
  test_files:
54
54
  - test/test_murmur.rb
55
+ has_rdoc: