xxhash 0.5.0 → 0.7.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/.github/workflows/ruby.yml +4 -7
- data/CHANGELOG.md +8 -0
- data/README.md +4 -5
- data/ext/xxhash/libxxhash.c +36 -881
- data/ext/xxhash/libxxhash.h +5452 -173
- data/ext/xxhash/xxhash.c +58 -22
- data/ext/xxhash/xxhash.h +0 -2
- data/lib/xxhash/version.rb +1 -1
- metadata +3 -6
data/ext/xxhash/xxhash.c
CHANGED
@@ -67,13 +67,30 @@ VALUE xxhash_xxh32(VALUE mod, VALUE input, VALUE seed)
|
|
67
67
|
return ULL2NUM(XXH32(StringValuePtr(input), (size_t)RSTRING_LEN(input), (unsigned int)NUM2ULL(seed)));
|
68
68
|
}
|
69
69
|
|
70
|
-
void xxhash32_streaming_hash_free(
|
70
|
+
static void xxhash32_streaming_hash_free(void *ptr)
|
71
71
|
{
|
72
|
+
xxhash_xxh32_t* storage = (xxhash_xxh32_t*)ptr;
|
72
73
|
// Digest frees the memory.
|
73
74
|
XXH32_freeState(storage->state);
|
74
75
|
xfree(storage);
|
75
76
|
}
|
76
77
|
|
78
|
+
static size_t xxhash32_streaming_hash_memsize(const void *ptr)
|
79
|
+
{
|
80
|
+
// Ideally we'd include sizeof(XXH32_state_t) too, but the type is opaque.
|
81
|
+
return sizeof(xxhash_xxh32_t);
|
82
|
+
}
|
83
|
+
|
84
|
+
static const rb_data_type_t xxhash_xxh32_type = {
|
85
|
+
.wrap_struct_name = "xxhash/xxhash32_streaming_hash",
|
86
|
+
.function = {
|
87
|
+
.dmark = NULL,
|
88
|
+
.dfree = xxhash32_streaming_hash_free,
|
89
|
+
.dsize = xxhash32_streaming_hash_memsize,
|
90
|
+
},
|
91
|
+
.flags = RUBY_TYPED_WB_PROTECTED | RUBY_TYPED_FREE_IMMEDIATELY
|
92
|
+
};
|
93
|
+
|
77
94
|
VALUE xxhash32_streaming_hash_new(VALUE klass, VALUE seed)
|
78
95
|
{
|
79
96
|
XXH_errorcode code;
|
@@ -86,14 +103,14 @@ VALUE xxhash32_streaming_hash_new(VALUE klass, VALUE seed)
|
|
86
103
|
rb_raise(rb_eRuntimeError, "Error during reset.");
|
87
104
|
return Qnil;
|
88
105
|
}
|
89
|
-
return
|
106
|
+
return TypedData_Wrap_Struct(klass, &xxhash_xxh32_type, storage);
|
90
107
|
}
|
91
108
|
|
92
109
|
VALUE xxhash32_streaming_hash_reset(VALUE self)
|
93
110
|
{
|
94
111
|
XXH_errorcode code;
|
95
112
|
xxhash_xxh32_t* storage;
|
96
|
-
|
113
|
+
TypedData_Get_Struct(self, xxhash_xxh32_t, &xxhash_xxh32_type, storage);
|
97
114
|
|
98
115
|
code = XXH32_reset(storage->state, storage->seed);
|
99
116
|
if(code != XXH_OK) {
|
@@ -107,7 +124,7 @@ VALUE xxhash32_streaming_hash_update(VALUE self, VALUE data)
|
|
107
124
|
{
|
108
125
|
XXH_errorcode code;
|
109
126
|
xxhash_xxh32_t* storage;
|
110
|
-
|
127
|
+
TypedData_Get_Struct(self, xxhash_xxh32_t, &xxhash_xxh32_type, storage);
|
111
128
|
|
112
129
|
code = XXH32_update(storage->state, StringValuePtr(data), (size_t)RSTRING_LEN(data));
|
113
130
|
if(code != XXH_OK) {
|
@@ -119,7 +136,7 @@ VALUE xxhash32_streaming_hash_update(VALUE self, VALUE data)
|
|
119
136
|
VALUE xxhash32_streaming_hash_digest(VALUE self)
|
120
137
|
{
|
121
138
|
xxhash_xxh32_t* storage;
|
122
|
-
|
139
|
+
TypedData_Get_Struct(self, xxhash_xxh32_t, &xxhash_xxh32_type, storage);
|
123
140
|
|
124
141
|
// Do not free memory now.
|
125
142
|
return ULL2NUM(XXH32_digest(storage->state));
|
@@ -130,13 +147,30 @@ VALUE xxhash_xxh64(VALUE mod, VALUE input, VALUE seed)
|
|
130
147
|
return ULL2NUM(XXH64(StringValuePtr(input), (size_t)RSTRING_LEN(input), (unsigned int)NUM2ULL(seed)));
|
131
148
|
}
|
132
149
|
|
133
|
-
void xxhash64_streaming_hash_free(
|
150
|
+
static void xxhash64_streaming_hash_free(void *ptr)
|
134
151
|
{
|
152
|
+
xxhash_xxh64_t* storage = (xxhash_xxh64_t*)ptr;
|
135
153
|
// Digest frees the memory.
|
136
154
|
XXH64_freeState(storage->state);
|
137
155
|
xfree(storage);
|
138
156
|
}
|
139
157
|
|
158
|
+
static size_t xxhash64_streaming_hash_memsize(const void *ptr)
|
159
|
+
{
|
160
|
+
// Ideally we'd include sizeof(XXH64_state_t) too, but the type is opaque.
|
161
|
+
return sizeof(xxhash_xxh64_t);
|
162
|
+
}
|
163
|
+
|
164
|
+
static const rb_data_type_t xxhash_xxh64_type = {
|
165
|
+
.wrap_struct_name = "xxhash/xxhash64_streaming_hash",
|
166
|
+
.function = {
|
167
|
+
.dmark = NULL,
|
168
|
+
.dfree = xxhash64_streaming_hash_free,
|
169
|
+
.dsize = xxhash64_streaming_hash_memsize,
|
170
|
+
},
|
171
|
+
.flags = RUBY_TYPED_WB_PROTECTED | RUBY_TYPED_FREE_IMMEDIATELY
|
172
|
+
};
|
173
|
+
|
140
174
|
VALUE xxhash64_streaming_hash_new(VALUE klass, VALUE seed)
|
141
175
|
{
|
142
176
|
XXH_errorcode code;
|
@@ -150,14 +184,14 @@ VALUE xxhash64_streaming_hash_new(VALUE klass, VALUE seed)
|
|
150
184
|
rb_raise(rb_eRuntimeError, "Error during reset.");
|
151
185
|
return Qnil;
|
152
186
|
}
|
153
|
-
return
|
187
|
+
return TypedData_Wrap_Struct(klass, &xxhash_xxh64_type, storage);
|
154
188
|
}
|
155
189
|
|
156
190
|
VALUE xxhash64_streaming_hash_reset(VALUE self)
|
157
191
|
{
|
158
192
|
XXH_errorcode code;
|
159
193
|
xxhash_xxh64_t* storage;
|
160
|
-
|
194
|
+
TypedData_Get_Struct(self, xxhash_xxh64_t, &xxhash_xxh64_type, storage);
|
161
195
|
|
162
196
|
code = XXH64_reset(storage->state, storage->seed);
|
163
197
|
if(code != XXH_OK) {
|
@@ -170,7 +204,7 @@ VALUE xxhash64_streaming_hash_update(VALUE self, VALUE data)
|
|
170
204
|
{
|
171
205
|
XXH_errorcode code;
|
172
206
|
xxhash_xxh64_t* storage;
|
173
|
-
|
207
|
+
TypedData_Get_Struct(self, xxhash_xxh64_t, &xxhash_xxh64_type, storage);
|
174
208
|
|
175
209
|
code = XXH64_update(storage->state, StringValuePtr(data), (size_t)RSTRING_LEN(data));
|
176
210
|
if(code != XXH_OK) {
|
@@ -182,7 +216,7 @@ VALUE xxhash64_streaming_hash_update(VALUE self, VALUE data)
|
|
182
216
|
VALUE xxhash64_streaming_hash_digest(VALUE self)
|
183
217
|
{
|
184
218
|
xxhash_xxh64_t* storage;
|
185
|
-
|
219
|
+
TypedData_Get_Struct(self, xxhash_xxh64_t, &xxhash_xxh64_type, storage);
|
186
220
|
|
187
221
|
// Do not free memory now.
|
188
222
|
return ULL2NUM(XXH64_digest(storage->state));
|
@@ -203,22 +237,24 @@ void Init_xxhash(void)
|
|
203
237
|
mXXhash = rb_define_module("XXhash");
|
204
238
|
mInternal = rb_define_module_under(mXXhash, "XXhashInternal");
|
205
239
|
|
206
|
-
rb_define_singleton_method(mInternal, "xxh32",
|
207
|
-
rb_define_singleton_method(mInternal, "xxh32_file",
|
208
|
-
rb_define_singleton_method(mInternal, "xxh64",
|
209
|
-
rb_define_singleton_method(mInternal, "xxh64_file",
|
240
|
+
rb_define_singleton_method(mInternal, "xxh32", xxhash_xxh32, 2);
|
241
|
+
rb_define_singleton_method(mInternal, "xxh32_file", xxhash_xxh32_file, 2);
|
242
|
+
rb_define_singleton_method(mInternal, "xxh64", xxhash_xxh64, 2);
|
243
|
+
rb_define_singleton_method(mInternal, "xxh64_file", xxhash_xxh64_file, 2);
|
210
244
|
|
211
245
|
cStreamingHash = rb_define_class_under(mInternal, "StreamingHash32", rb_cObject);
|
246
|
+
rb_undef_alloc_func(cStreamingHash);
|
212
247
|
|
213
|
-
rb_define_singleton_method(cStreamingHash, "new",
|
214
|
-
rb_define_method(cStreamingHash, "update",
|
215
|
-
rb_define_method(cStreamingHash, "digest",
|
216
|
-
rb_define_method(cStreamingHash, "reset",
|
248
|
+
rb_define_singleton_method(cStreamingHash, "new", xxhash32_streaming_hash_new, 1);
|
249
|
+
rb_define_method(cStreamingHash, "update", xxhash32_streaming_hash_update, 1);
|
250
|
+
rb_define_method(cStreamingHash, "digest", xxhash32_streaming_hash_digest, 0);
|
251
|
+
rb_define_method(cStreamingHash, "reset", xxhash32_streaming_hash_reset, 0);
|
217
252
|
|
218
253
|
cStreamingHash64 = rb_define_class_under(mInternal, "StreamingHash64", rb_cObject);
|
254
|
+
rb_undef_alloc_func(cStreamingHash64);
|
219
255
|
|
220
|
-
rb_define_singleton_method(cStreamingHash64, "new",
|
221
|
-
rb_define_method(cStreamingHash64, "update",
|
222
|
-
rb_define_method(cStreamingHash64, "digest",
|
223
|
-
rb_define_method(cStreamingHash64, "reset",
|
256
|
+
rb_define_singleton_method(cStreamingHash64, "new", xxhash64_streaming_hash_new, 1);
|
257
|
+
rb_define_method(cStreamingHash64, "update", xxhash64_streaming_hash_update, 1);
|
258
|
+
rb_define_method(cStreamingHash64, "digest", xxhash64_streaming_hash_digest, 0);
|
259
|
+
rb_define_method(cStreamingHash64, "reset", xxhash64_streaming_hash_reset, 0);
|
224
260
|
}
|
data/ext/xxhash/xxhash.h
CHANGED
@@ -19,14 +19,12 @@ typedef VALUE (ruby_method)();
|
|
19
19
|
|
20
20
|
VALUE xxhash_xxh32(VALUE mod, VALUE input, VALUE seed);
|
21
21
|
VALUE xxhash_xxh32_file(VALUE mod, VALUE filename, VALUE seed);
|
22
|
-
void xxhash32_streaming_hash_free(xxhash_xxh32_t* state);
|
23
22
|
VALUE xxhash32_streaming_hash_new(VALUE klass, VALUE seed);
|
24
23
|
VALUE xxhash32_streaming_hash_update(VALUE self, VALUE data);
|
25
24
|
VALUE xxhash32_streaming_hash_reset(VALUE self);
|
26
25
|
VALUE xxhash32_streaming_hash_digest(VALUE self);
|
27
26
|
VALUE xxhash_xxh64(VALUE mod, VALUE input, VALUE seed);
|
28
27
|
VALUE xxhash_xxh64_file(VALUE mod, VALUE filename, VALUE seed);
|
29
|
-
void xxhash64_streaming_hash_free(xxhash_xxh64_t* state);
|
30
28
|
VALUE xxhash64_streaming_hash_new(VALUE klass, VALUE seed);
|
31
29
|
VALUE xxhash64_streaming_hash_update(VALUE self, VALUE data);
|
32
30
|
VALUE xxhash64_streaming_hash_reset(VALUE self);
|
data/lib/xxhash/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: xxhash
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.7.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Vasiliy Ermolovich
|
8
|
-
autorequire:
|
9
8
|
bindir: bin
|
10
9
|
cert_chain: []
|
11
|
-
date:
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
12
11
|
dependencies: []
|
13
12
|
description: Ruby wrapper for xxHash lib
|
14
13
|
email:
|
@@ -39,7 +38,6 @@ homepage: http://github.com/nashby/xxhash
|
|
39
38
|
licenses:
|
40
39
|
- MIT
|
41
40
|
metadata: {}
|
42
|
-
post_install_message:
|
43
41
|
rdoc_options: []
|
44
42
|
require_paths:
|
45
43
|
- lib
|
@@ -54,8 +52,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
54
52
|
- !ruby/object:Gem::Version
|
55
53
|
version: '0'
|
56
54
|
requirements: []
|
57
|
-
rubygems_version: 3.
|
58
|
-
signing_key:
|
55
|
+
rubygems_version: 3.7.1
|
59
56
|
specification_version: 4
|
60
57
|
summary: Ruby wrapper for xxHash lib
|
61
58
|
test_files:
|