xxhash 0.4.0 → 0.5.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 +5 -5
- data/.github/workflows/ruby.yml +38 -0
- data/CHANGELOG.md +5 -1
- data/Gemfile +1 -1
- data/README.md +10 -4
- data/ext/xxhash/xxhash.c +68 -0
- data/ext/xxhash/xxhash.h +3 -0
- data/lib/xxhash/version.rb +1 -1
- data/lib/xxhash.rb +8 -0
- data/test/xxhash_test.rb +31 -0
- metadata +4 -5
- data/.travis.yml +0 -9
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
|
-
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: b9e0c970d797503c0fd848023fbf5c4ac64d17744417e990d7d638cbe4447fd2
|
|
4
|
+
data.tar.gz: 41814924ceba3ab4647fc24e22cec307ea03c4f4076f0f91af7872b60f3807f7
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 2512c453f3ca7d14e70d2b64ac54daa76efaf36bb8da9a713462aea1f404cbb20953adbd59d4c96375ea08ddf2edd93cdcb9280ffc02cd5a06ff6a47365a8867
|
|
7
|
+
data.tar.gz: 143dda9ce66c0f980d78d79550f0fd4cebe9b64fd48533f6ea3af2d78300fb063cf8430013dd5f53f4a6379323d40966556642df08a74cb6cd95fa037c1f3a2e
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
# This workflow uses actions that are not certified by GitHub.
|
|
2
|
+
# They are provided by a third-party and are governed by
|
|
3
|
+
# separate terms of service, privacy policy, and support
|
|
4
|
+
# documentation.
|
|
5
|
+
# This workflow will download a prebuilt Ruby version, install dependencies and run tests with Rake
|
|
6
|
+
# For more information see: https://github.com/marketplace/actions/setup-ruby-jruby-and-truffleruby
|
|
7
|
+
|
|
8
|
+
name: Ruby
|
|
9
|
+
|
|
10
|
+
on:
|
|
11
|
+
push:
|
|
12
|
+
branches: [ "master" ]
|
|
13
|
+
pull_request:
|
|
14
|
+
branches: [ "master" ]
|
|
15
|
+
|
|
16
|
+
permissions:
|
|
17
|
+
contents: read
|
|
18
|
+
|
|
19
|
+
jobs:
|
|
20
|
+
test:
|
|
21
|
+
|
|
22
|
+
runs-on: ubuntu-latest
|
|
23
|
+
strategy:
|
|
24
|
+
matrix:
|
|
25
|
+
ruby-version: ['2.6', '2.7', '3.0']
|
|
26
|
+
|
|
27
|
+
steps:
|
|
28
|
+
- uses: actions/checkout@v3
|
|
29
|
+
- name: Set up Ruby
|
|
30
|
+
# To automatically get bug fixes and new Ruby versions for ruby/setup-ruby,
|
|
31
|
+
# change this to (see https://github.com/ruby/setup-ruby#versioning):
|
|
32
|
+
# uses: ruby/setup-ruby@v1
|
|
33
|
+
uses: ruby/setup-ruby@2b019609e2b0f1ea1a2bc8ca11cb82ab46ada124
|
|
34
|
+
with:
|
|
35
|
+
ruby-version: ${{ matrix.ruby-version }}
|
|
36
|
+
bundler-cache: true # runs 'bundle install' and caches installed gems automatically
|
|
37
|
+
- name: Run tests
|
|
38
|
+
run: bundle exec rake
|
data/CHANGELOG.md
CHANGED
|
@@ -1,4 +1,8 @@
|
|
|
1
|
-
### 0.
|
|
1
|
+
### 0.5.0 (July 28, 2022)
|
|
2
|
+
* Mark extension as Ractor-safe (by [@kreynolds](https://github.com/kreynolds))
|
|
3
|
+
* Add ability to hash files by path directly with `XXhash.xxh32_file` and `XXhash.xxh64_file` (by [@kreynolds](https://github.com/kreynolds))
|
|
4
|
+
|
|
5
|
+
### 0.4.0 (December 11, 2016)
|
|
2
6
|
* Add xxHash to `Digest` module and make it more compatieble
|
|
3
7
|
with another hash functions from `Digest`. (by [@justinwsmith](https://github.com/justinwsmith))
|
|
4
8
|
* Add a `StreamingHash` class that's externally instantiatable. (by [@justinwsmith](https://github.com/justinwsmith))
|
data/Gemfile
CHANGED
data/README.md
CHANGED
|
@@ -25,20 +25,26 @@ You can use it with `IO` objects too:
|
|
|
25
25
|
XXhash.xxh32_stream(StringIO.new('test'), 123) # => 2758658570
|
|
26
26
|
```
|
|
27
27
|
|
|
28
|
+
You can use it with file path directly, avoiding costly ruby-related operations.
|
|
29
|
+
|
|
30
|
+
```ruby
|
|
31
|
+
XXhash.xxh32_file(__FILE__)
|
|
32
|
+
```
|
|
33
|
+
|
|
28
34
|
Note that you can also pass a chunk size as third param (it's 32 bytes by default)
|
|
29
35
|
|
|
30
|
-
XXH64 is also supported: you can use `xxh64
|
|
36
|
+
XXH64 is also supported: you can use `xxh64`, `xxh64_stream`, `.xxh64_file`.
|
|
31
37
|
|
|
32
38
|
### Supported Ruby versions
|
|
33
39
|
|
|
34
|
-
- MRI
|
|
40
|
+
- MRI 2.3+
|
|
35
41
|
- rbx-19mode
|
|
36
42
|
|
|
37
43
|
Note: It doesn't work on JRuby as it uses C extension.
|
|
38
44
|
|
|
39
45
|
### Versioning
|
|
40
46
|
|
|
41
|
-
Version 0.
|
|
47
|
+
Version 0.5.0 is equal to [0.6.2](https://github.com/Cyan4973/xxHash/tree/v0.6.2)
|
|
42
48
|
|
|
43
49
|
## Contributing
|
|
44
50
|
|
|
@@ -50,5 +56,5 @@ Version 0.4.0 is equal to [0.6.2](https://github.com/Cyan4973/xxHash/tree/v0.6.2
|
|
|
50
56
|
|
|
51
57
|
### Copyright
|
|
52
58
|
|
|
53
|
-
Copyright (c)
|
|
59
|
+
Copyright (c) 2022 Vasiliy Ermolovich. See LICENSE.txt for
|
|
54
60
|
further details.
|
data/ext/xxhash/xxhash.c
CHANGED
|
@@ -1,5 +1,67 @@
|
|
|
1
1
|
#include "xxhash.h"
|
|
2
2
|
|
|
3
|
+
VALUE xxhash_xxh32_file(VALUE mod, VALUE filename, VALUE seed)
|
|
4
|
+
{
|
|
5
|
+
StringValue(filename);
|
|
6
|
+
|
|
7
|
+
XXH32_state_t* state = XXH32_createState();
|
|
8
|
+
if (state == NULL) {
|
|
9
|
+
rb_raise(rb_eRuntimeError, "%s", "Cannot create state, out of memory");
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
XXH32_reset(state, NUM2INT(seed));
|
|
13
|
+
|
|
14
|
+
char buffer[16384];
|
|
15
|
+
size_t count;
|
|
16
|
+
FILE *fp = fopen(RSTRING_PTR(filename), "rb");
|
|
17
|
+
if (fp == NULL) {
|
|
18
|
+
XXH32_freeState(state);
|
|
19
|
+
VALUE error = INT2FIX(errno);
|
|
20
|
+
rb_exc_raise(rb_class_new_instance(1, &error, rb_eSystemCallError));
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
while ((count = fread(buffer, 1, sizeof(buffer), fp)) != 0) {
|
|
24
|
+
XXH32_update(state, buffer, count);
|
|
25
|
+
}
|
|
26
|
+
fclose(fp);
|
|
27
|
+
|
|
28
|
+
XXH32_hash_t result = XXH32_digest(state);
|
|
29
|
+
|
|
30
|
+
XXH32_freeState(state);
|
|
31
|
+
return ULL2NUM(result);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
VALUE xxhash_xxh64_file(VALUE mod, VALUE filename, VALUE seed)
|
|
35
|
+
{
|
|
36
|
+
StringValue(filename);
|
|
37
|
+
|
|
38
|
+
XXH64_state_t* state = XXH64_createState();
|
|
39
|
+
if (state == NULL) {
|
|
40
|
+
rb_raise(rb_eRuntimeError, "%s", "Cannot create state, out of memory");
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
XXH64_reset(state, NUM2INT(seed));
|
|
44
|
+
|
|
45
|
+
char buffer[16384];
|
|
46
|
+
size_t count;
|
|
47
|
+
FILE *fp = fopen(RSTRING_PTR(filename), "rb");
|
|
48
|
+
if (fp == NULL) {
|
|
49
|
+
XXH64_freeState(state);
|
|
50
|
+
VALUE error = INT2FIX(errno);
|
|
51
|
+
rb_exc_raise(rb_class_new_instance(1, &error, rb_eSystemCallError));
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
while ((count = fread(buffer, 1, sizeof(buffer), fp)) != 0) {
|
|
55
|
+
XXH64_update(state, buffer, count);
|
|
56
|
+
}
|
|
57
|
+
fclose(fp);
|
|
58
|
+
|
|
59
|
+
XXH64_hash_t result = XXH64_digest(state);
|
|
60
|
+
|
|
61
|
+
XXH64_freeState(state);
|
|
62
|
+
return ULL2NUM(result);
|
|
63
|
+
}
|
|
64
|
+
|
|
3
65
|
VALUE xxhash_xxh32(VALUE mod, VALUE input, VALUE seed)
|
|
4
66
|
{
|
|
5
67
|
return ULL2NUM(XXH32(StringValuePtr(input), (size_t)RSTRING_LEN(input), (unsigned int)NUM2ULL(seed)));
|
|
@@ -129,6 +191,10 @@ VALUE xxhash64_streaming_hash_digest(VALUE self)
|
|
|
129
191
|
|
|
130
192
|
void Init_xxhash(void)
|
|
131
193
|
{
|
|
194
|
+
#ifdef HAVE_RB_EXT_RACTOR_SAFE
|
|
195
|
+
rb_ext_ractor_safe(true);
|
|
196
|
+
#endif
|
|
197
|
+
|
|
132
198
|
VALUE cStreamingHash;
|
|
133
199
|
VALUE cStreamingHash64;
|
|
134
200
|
VALUE mXXhash;
|
|
@@ -138,7 +204,9 @@ void Init_xxhash(void)
|
|
|
138
204
|
mInternal = rb_define_module_under(mXXhash, "XXhashInternal");
|
|
139
205
|
|
|
140
206
|
rb_define_singleton_method(mInternal, "xxh32", (ruby_method*) &xxhash_xxh32, 2);
|
|
207
|
+
rb_define_singleton_method(mInternal, "xxh32_file", (ruby_method*) &xxhash_xxh32_file, 2);
|
|
141
208
|
rb_define_singleton_method(mInternal, "xxh64", (ruby_method*) &xxhash_xxh64, 2);
|
|
209
|
+
rb_define_singleton_method(mInternal, "xxh64_file", (ruby_method*) &xxhash_xxh64_file, 2);
|
|
142
210
|
|
|
143
211
|
cStreamingHash = rb_define_class_under(mInternal, "StreamingHash32", rb_cObject);
|
|
144
212
|
|
data/ext/xxhash/xxhash.h
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
#include <stdlib.h>
|
|
2
|
+
#include <errno.h>
|
|
2
3
|
#include <ruby.h>
|
|
3
4
|
#include "libxxhash.h"
|
|
4
5
|
|
|
@@ -17,12 +18,14 @@ typedef struct {
|
|
|
17
18
|
typedef VALUE (ruby_method)();
|
|
18
19
|
|
|
19
20
|
VALUE xxhash_xxh32(VALUE mod, VALUE input, VALUE seed);
|
|
21
|
+
VALUE xxhash_xxh32_file(VALUE mod, VALUE filename, VALUE seed);
|
|
20
22
|
void xxhash32_streaming_hash_free(xxhash_xxh32_t* state);
|
|
21
23
|
VALUE xxhash32_streaming_hash_new(VALUE klass, VALUE seed);
|
|
22
24
|
VALUE xxhash32_streaming_hash_update(VALUE self, VALUE data);
|
|
23
25
|
VALUE xxhash32_streaming_hash_reset(VALUE self);
|
|
24
26
|
VALUE xxhash32_streaming_hash_digest(VALUE self);
|
|
25
27
|
VALUE xxhash_xxh64(VALUE mod, VALUE input, VALUE seed);
|
|
28
|
+
VALUE xxhash_xxh64_file(VALUE mod, VALUE filename, VALUE seed);
|
|
26
29
|
void xxhash64_streaming_hash_free(xxhash_xxh64_t* state);
|
|
27
30
|
VALUE xxhash64_streaming_hash_new(VALUE klass, VALUE seed);
|
|
28
31
|
VALUE xxhash64_streaming_hash_update(VALUE self, VALUE data);
|
data/lib/xxhash/version.rb
CHANGED
data/lib/xxhash.rb
CHANGED
|
@@ -11,6 +11,14 @@ module XXhash
|
|
|
11
11
|
XXhashInternal.xxh64(input.to_s, seed.to_i)
|
|
12
12
|
end
|
|
13
13
|
|
|
14
|
+
def self.xxh32_file(filename, seed = 0)
|
|
15
|
+
XXhashInternal.xxh32_file(filename.to_s, seed.to_i)
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def self.xxh64_file(filename, seed = 0)
|
|
19
|
+
XXhashInternal.xxh64_file(filename.to_s, seed.to_i)
|
|
20
|
+
end
|
|
21
|
+
|
|
14
22
|
def self.xxh32_stream(io, seed = 0, chunk_size = 32)
|
|
15
23
|
seed = seed.to_i
|
|
16
24
|
chunk_size = chunk_size.to_i
|
data/test/xxhash_test.rb
CHANGED
|
@@ -2,19 +2,50 @@ require_relative 'test_helper'
|
|
|
2
2
|
require 'stringio'
|
|
3
3
|
|
|
4
4
|
describe XXhash do
|
|
5
|
+
it 'is marked as ractor-safe' do
|
|
6
|
+
skip("Ractorrs are not supported in this version of ruby(#{RUBY_VERSION})") unless defined?(Ractor)
|
|
7
|
+
|
|
8
|
+
ractor = Ractor.new do
|
|
9
|
+
Ractor.yield XXhash.xxh32(Ractor.receive)
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
ractor.send('test')
|
|
13
|
+
assert_equal ractor.take, XXhash.xxh32('test')
|
|
14
|
+
end
|
|
15
|
+
|
|
5
16
|
it 'returns 32-bit hash' do
|
|
6
17
|
assert_equal 2758658570, XXhash.xxh32('test', 123)
|
|
7
18
|
end
|
|
8
19
|
|
|
20
|
+
it 'returns 32-bit hash from a file' do
|
|
21
|
+
assert_equal XXhash.xxh32(File.read(__FILE__)), XXhash.xxh32_file(__FILE__)
|
|
22
|
+
assert_equal XXhash.xxh32(File.read(__FILE__), 123), XXhash.xxh32_file(__FILE__, 123)
|
|
23
|
+
end
|
|
24
|
+
|
|
9
25
|
it 'returns 64-bit hash' do
|
|
10
26
|
assert_equal 3134990500624303823, XXhash.xxh64('test', 123)
|
|
11
27
|
end
|
|
12
28
|
|
|
29
|
+
it 'returns 64-bit hash from a file' do
|
|
30
|
+
assert_equal XXhash.xxh64(File.read(__FILE__)), XXhash.xxh64_file(__FILE__)
|
|
31
|
+
assert_equal XXhash.xxh64(File.read(__FILE__), 123), XXhash.xxh64_file(__FILE__, 123)
|
|
32
|
+
end
|
|
33
|
+
|
|
13
34
|
it 'uses 0 (default value) if seed is not specified' do
|
|
14
35
|
assert_equal 1042293711, XXhash.xxh32('test')
|
|
15
36
|
assert_equal 5754696928334414137, XXhash.xxh64('test')
|
|
16
37
|
end
|
|
17
38
|
|
|
39
|
+
it 'raises an Errno exception for invalid file' do
|
|
40
|
+
assert_raises Errno::ENOENT do
|
|
41
|
+
XXhash.xxh32_file('nonexistent-file')
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
assert_raises Errno::ENOENT do
|
|
45
|
+
XXhash.xxh64_file('nonexistent-file')
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
|
|
18
49
|
describe 'XXhashInternal::StreamingHash32' do
|
|
19
50
|
|
|
20
51
|
it 'rises ArgumentError if first argument is not IO object' do
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: xxhash
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.5.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Vasiliy Ermolovich
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date:
|
|
11
|
+
date: 2022-07-28 00:00:00.000000000 Z
|
|
12
12
|
dependencies: []
|
|
13
13
|
description: Ruby wrapper for xxHash lib
|
|
14
14
|
email:
|
|
@@ -18,8 +18,8 @@ extensions:
|
|
|
18
18
|
- ext/xxhash/extconf.rb
|
|
19
19
|
extra_rdoc_files: []
|
|
20
20
|
files:
|
|
21
|
+
- ".github/workflows/ruby.yml"
|
|
21
22
|
- ".gitignore"
|
|
22
|
-
- ".travis.yml"
|
|
23
23
|
- CHANGELOG.md
|
|
24
24
|
- Gemfile
|
|
25
25
|
- LICENSE.txt
|
|
@@ -54,8 +54,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
54
54
|
- !ruby/object:Gem::Version
|
|
55
55
|
version: '0'
|
|
56
56
|
requirements: []
|
|
57
|
-
|
|
58
|
-
rubygems_version: 2.5.1
|
|
57
|
+
rubygems_version: 3.0.9
|
|
59
58
|
signing_key:
|
|
60
59
|
specification_version: 4
|
|
61
60
|
summary: Ruby wrapper for xxHash lib
|