hashlittle 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +4 -4
- data/ext/hashlittle/hashlittle.c +17 -18
- data/lib/hashlittle/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fa6812f082b18d8adffae323ac2756b67d9bf7a3f024c294b3676d47191ad430
|
4
|
+
data.tar.gz: 24cad49766decd951421fc1caa3b19870ed63d88b9e6e035d1f5d6f021c23589
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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")
|
20
|
-
Hashlittle.hashlittle("test", 123)
|
19
|
+
Hashlittle.hashlittle("test") # 3188463954
|
20
|
+
Hashlittle.hashlittle("test", 123) # 1744958730 optional seed argument
|
21
21
|
|
22
|
-
Hashlittle.hashlittle2("test")
|
23
|
-
Hashlittle.hashlittle2("test",
|
22
|
+
Hashlittle.hashlittle2("test") # 7900098448711227730
|
23
|
+
Hashlittle.hashlittle2("test", 123) # 5719842420682781962 optional seed argument
|
24
24
|
|
25
25
|
## Development
|
26
26
|
|
data/ext/hashlittle/hashlittle.c
CHANGED
@@ -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,
|
32
|
-
uint32_t pb = 0;
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
Check_Type(
|
41
|
-
|
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
|
-
|
51
|
-
|
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
|
56
|
+
return ULL2NUM(result); // Return a single uint64 value
|
58
57
|
}
|
59
58
|
|
60
59
|
RUBY_FUNC_EXPORTED void
|
data/lib/hashlittle/version.rb
CHANGED