hashlittle 0.1.0 → 0.2.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
  SHA256:
3
- metadata.gz: b88cfbdb270614ebe40be9d44cbde601fa0492d1dd120237451e96eb16830291
4
- data.tar.gz: 49fe46fa8cf98685205c16934070c4dae4b8253cdfabdb30bde31cb3918349e3
3
+ metadata.gz: fa6812f082b18d8adffae323ac2756b67d9bf7a3f024c294b3676d47191ad430
4
+ data.tar.gz: 24cad49766decd951421fc1caa3b19870ed63d88b9e6e035d1f5d6f021c23589
5
5
  SHA512:
6
- metadata.gz: bd7e1962db677db183fbb6e0e3e49ba1161303966978e3bc8fcffb16e7e8ce863816f197c9cd967e0a9ffef211b0ecb98b4d17afc255827b3cd142e9a084d324
7
- data.tar.gz: 0ce4419afddf9d05be265282da6ca6a30ae08b9bb92cd40d75fca0a578d291c651507f3603753bbefd9d31b8b252baab103d4c830e4ad0caf87f0e47d1f8be0f
6
+ metadata.gz: 592f5dda44c99e90f8923eb4fe921820b70b35b47d2607dba0bda5467e6b1e0a7d08b760d501f683b035967b84080ba97b289bf76f03ffa696badced9be07ce5
7
+ data.tar.gz: 356307cc3ef3a543268e0f1fdd295fc5324775ebddc5802c43a408af5903c96e0bc42e86c6b368a1fdd975d2a5142013a98daecc584dbd65aa62732a5967b23b
data/README.md CHANGED
@@ -16,11 +16,11 @@ If bundler is not being used to manage dependencies, install the gem by executin
16
16
 
17
17
  require 'hashlittle'
18
18
 
19
- Hashlittle.hashlittle("test") # 3188463954
20
- Hashlittle.hashlittle("test", 123) # 1744958730 optional seed argument
19
+ Hashlittle.hashlittle("test") # 3188463954
20
+ Hashlittle.hashlittle("test", 123) # 1744958730 optional seed argument
21
21
 
22
- Hashlittle.hashlittle2("test") # [3188463954, 1839385006]
23
- Hashlittle.hashlittle2("test", a) # [3188463954, 1839385006] store result in a pre-existing array
22
+ Hashlittle.hashlittle2("test") # 7900098448711227730
23
+ Hashlittle.hashlittle2("test", 123) # 5719842420682781962 optional seed argument
24
24
 
25
25
  ## Development
26
26
 
@@ -28,33 +28,32 @@ static VALUE rb_hashlittle(int argc, VALUE *argv, VALUE self) {
28
28
  }
29
29
 
30
30
  static VALUE rb_hashlittle2(int argc, VALUE *argv, VALUE self) {
31
- VALUE rb_key, rb_result;
32
- uint32_t pb = 0;
33
- uint32_t pc = 0;
34
-
35
- rb_scan_args(argc, argv, "11", &rb_key, &rb_result);
36
-
37
- if (NIL_P(rb_result)) {
38
- rb_result = rb_ary_new2(2);
39
- } else {
40
- Check_Type(rb_result, T_ARRAY);
41
- rb_ary_modify(rb_result);
31
+ VALUE rb_key, rb_seed;
32
+ uint32_t pc = 0, pb = 0;
33
+ uint64_t result;
34
+
35
+ // Accept an optional uint64 as seed
36
+ rb_scan_args(argc, argv, "11", &rb_key, &rb_seed);
37
+
38
+ // If a seed is provided, split it into two uint32_t parts for hashlittle2
39
+ if (!NIL_P(rb_seed)) {
40
+ Check_Type(rb_seed, T_FIXNUM);
41
+ uint64_t seed = NUM2ULL(rb_seed);
42
+ pb = (uint32_t)(seed >> 32); // High 32 bits
43
+ pc = (uint32_t)(seed & 0xFFFFFFFF); // Low 32 bits
42
44
  }
43
45
 
44
46
  Check_Type(rb_key, T_STRING);
45
47
  uint8_t *key = (uint8_t *)RSTRING_PTR(rb_key);
46
48
  long key_len = RSTRING_LEN(rb_key);
47
49
 
50
+ // Compute hash
48
51
  hashlittle2(key, key_len, &pc, &pb);
49
52
 
50
- if( RARRAY_LEN(rb_result) < 2 ){
51
- rb_ary_resize(rb_result, 2);
52
- }
53
-
54
- rb_ary_store(rb_result, 0, UINT2NUM(pc));
55
- rb_ary_store(rb_result, 1, UINT2NUM(pb));
53
+ // Combine the pc and pb into a single uint64_t result
54
+ result = ((uint64_t)pb << 32) | pc;
56
55
 
57
- return rb_result;
56
+ return ULL2NUM(result); // Return a single uint64 value
58
57
  }
59
58
 
60
59
  RUBY_FUNC_EXPORTED void
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Hashlittle
4
- VERSION = "0.1.0"
4
+ VERSION = "0.2.0"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hashlittle
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrey "Zed" Zaikin