xxhash 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,7 @@
1
+ source "http://rubygems.org"
2
+
3
+ gemspec
4
+
5
+ gem 'rake'
6
+ gem 'rake-compiler'
7
+ gem 'minitest', '~> 4.1'
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Vasiliy Ermolovich
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,31 @@
1
+ ## xxHash
2
+
3
+ Ruby wrapper for [xxHash](http://code.google.com/p/xxhash/)
4
+
5
+ ### Install
6
+
7
+ gem install xxhash
8
+
9
+ ### Usage
10
+
11
+ ```ruby
12
+ require 'xxhash'
13
+
14
+ text = "test"
15
+ seed = 12345
16
+
17
+ XXhash.xxh32(text, seed) # => 3834992036
18
+ ```
19
+
20
+ ## Contributing
21
+
22
+ 1. Fork it
23
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
24
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
25
+ 4. Push to the branch (`git push origin my-new-feature`)
26
+ 5. Create new Pull Request
27
+
28
+ ### Copyright
29
+
30
+ Copyright (c) 2012 Vasiliy Ermolovich. See LICENSE.txt for
31
+ further details.
@@ -0,0 +1,20 @@
1
+ require "bundler/gem_tasks"
2
+
3
+ require 'rake/testtask'
4
+ require 'rake/clean'
5
+
6
+ Rake::TestTask.new do |t|
7
+ t.libs << 'test'
8
+ t.pattern = 'test/*_test.rb'
9
+ t.verbose = true
10
+ end
11
+
12
+ desc "Run tests"
13
+ task :default => :test
14
+
15
+ require 'rake/extensiontask'
16
+ Rake::ExtensionTask.new('xxhash') do |ext|
17
+ ext.lib_dir = 'lib/xxhash'
18
+ end
19
+
20
+ Rake::Task[:test].prerequisites << :compile
@@ -0,0 +1,8 @@
1
+ require 'mkmf'
2
+
3
+ %w{g O3 Wall}.each do |flag|
4
+ flag = "-#{flag}"
5
+ $CPPFLAGS += " #{flag}" unless $CPPFLAGS.split.include? flag
6
+ end
7
+
8
+ create_makefile('xxhash/xxhash')
@@ -0,0 +1,342 @@
1
+ /*
2
+ xxHash - Fast Hash algorithm
3
+ Copyright (C) 2012, Yann Collet.
4
+ BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php)
5
+
6
+ Redistribution and use in source and binary forms, with or without
7
+ modification, are permitted provided that the following conditions are
8
+ met:
9
+
10
+ * Redistributions of source code must retain the above copyright
11
+ notice, this list of conditions and the following disclaimer.
12
+ * Redistributions in binary form must reproduce the above
13
+ copyright notice, this list of conditions and the following disclaimer
14
+ in the documentation and/or other materials provided with the
15
+ distribution.
16
+
17
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18
+ "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19
+ LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20
+ A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21
+ OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22
+ SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23
+ LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24
+ DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25
+ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28
+
29
+ You can contact the author at :
30
+ - xxHash source repository : http://code.google.com/p/xxhash/
31
+ */
32
+
33
+
34
+
35
+ //**************************************
36
+ // Tuning parameters
37
+ //**************************************
38
+ // FORCE_NATIVE_FORMAT :
39
+ // By default, xxHash library provides endian-independant Hash values.
40
+ // Results are therefore identical for big-endian and little-endian CPU.
41
+ // This comes at a performance cost for big-endian CPU, since some swapping is required to emulate little-endian format.
42
+ // Should endian-independance be of no importance to your application, you may uncomment the #define below
43
+ // It will improve speed for Big-endian CPU.
44
+ // This option has no impact on Little_Endian CPU.
45
+ //#define FORCE_NATIVE_FORMAT 1
46
+
47
+
48
+
49
+ //**************************************
50
+ // Includes
51
+ //**************************************
52
+ #include <stdlib.h> // for malloc(), free()
53
+ #include <string.h> // for memcpy()
54
+ #include "libxxhash.h"
55
+
56
+
57
+
58
+ //**************************************
59
+ // CPU Feature Detection
60
+ //**************************************
61
+ // Little Endian or Big Endian ?
62
+ // You can overwrite the #define below if you know your architecture endianess
63
+ #if defined(FORCE_NATIVE_FORMAT) && (FORCE_NATIVE_FORMAT==1)
64
+ // Force native format. The result will be endian dependant.
65
+ # define XXH_BIG_ENDIAN 0
66
+ #elif defined (__GLIBC__)
67
+ # include <endian.h>
68
+ # if (__BYTE_ORDER == __BIG_ENDIAN)
69
+ # define XXH_BIG_ENDIAN 1
70
+ # endif
71
+ #elif (defined(__BIG_ENDIAN__) || defined(__BIG_ENDIAN) || defined(_BIG_ENDIAN)) && !(defined(__LITTLE_ENDIAN__) || defined(__LITTLE_ENDIAN) || defined(_LITTLE_ENDIAN))
72
+ # define XXH_BIG_ENDIAN 1
73
+ #elif defined(__sparc) || defined(__sparc__) \
74
+ || defined(__ppc__) || defined(_POWER) || defined(__powerpc__) || defined(_ARCH_PPC) || defined(__PPC__) || defined(__PPC) || defined(PPC) || defined(__powerpc__) || defined(__powerpc) || defined(powerpc) \
75
+ || defined(__hpux) || defined(__hppa) \
76
+ || defined(_MIPSEB) || defined(__s390__)
77
+ # define XXH_BIG_ENDIAN 1
78
+ #endif
79
+
80
+ #if !defined(XXH_BIG_ENDIAN)
81
+ // Little Endian assumed. PDP Endian and other very rare endian format are unsupported.
82
+ # define XXH_BIG_ENDIAN 0
83
+ #endif
84
+
85
+
86
+
87
+ //**************************************
88
+ // Compiler-specific Options & Functions
89
+ //**************************************
90
+ #define GCC_VERSION (__GNUC__ * 100 + __GNUC_MINOR__)
91
+
92
+ // Note : under GCC, it may sometimes be faster to enable the (2nd) macro definition, instead of using win32 intrinsic
93
+ #if defined(_WIN32)
94
+ # define XXH_rotl32(x,r) _rotl(x,r)
95
+ #else
96
+ # define XXH_rotl32(x,r) ((x << r) | (x >> (32 - r)))
97
+ #endif
98
+
99
+ #if defined(_MSC_VER) // Visual Studio
100
+ # define XXH_swap32 _byteswap_ulong
101
+ #elif GCC_VERSION >= 403
102
+ # define XXH_swap32 __builtin_bswap32
103
+ #else
104
+ static inline unsigned int XXH_swap32 (unsigned int x) {
105
+ return ((x << 24) & 0xff000000 ) |
106
+ ((x << 8) & 0x00ff0000 ) |
107
+ ((x >> 8) & 0x0000ff00 ) |
108
+ ((x >> 24) & 0x000000ff );
109
+ }
110
+ #endif
111
+
112
+
113
+
114
+ //**************************************
115
+ // Constants
116
+ //**************************************
117
+ #define PRIME32_1 2654435761U
118
+ #define PRIME32_2 2246822519U
119
+ #define PRIME32_3 3266489917U
120
+ #define PRIME32_4 668265263U
121
+ #define PRIME32_5 374761393U
122
+
123
+
124
+
125
+ //**************************************
126
+ // Macros
127
+ //**************************************
128
+ #define XXH_LE32(p) (XXH_BIG_ENDIAN ? XXH_swap32(*(unsigned int*)(p)) : *(unsigned int*)(p))
129
+
130
+
131
+
132
+ //****************************
133
+ // Simple Hash Functions
134
+ //****************************
135
+
136
+ unsigned int XXH32(const void* input, int len, unsigned int seed)
137
+ {
138
+ #if 0
139
+ // Simple version, good for code maintenance, but unfortunately slow for small inputs
140
+ void* state = XXH32_init(seed);
141
+ XXH32_feed(state, input, len);
142
+ return XXH32_result(state);
143
+ #else
144
+
145
+ const unsigned char* p = (const unsigned char*)input;
146
+ const unsigned char* const bEnd = p + len;
147
+ unsigned int h32;
148
+
149
+ if (len>=16)
150
+ {
151
+ const unsigned char* const limit = bEnd - 16;
152
+ unsigned int v1 = seed + PRIME32_1 + PRIME32_2;
153
+ unsigned int v2 = seed + PRIME32_2;
154
+ unsigned int v3 = seed + 0;
155
+ unsigned int v4 = seed - PRIME32_1;
156
+
157
+ do
158
+ {
159
+ v1 += XXH_LE32(p) * PRIME32_2; v1 = XXH_rotl32(v1, 13); v1 *= PRIME32_1; p+=4;
160
+ v2 += XXH_LE32(p) * PRIME32_2; v2 = XXH_rotl32(v2, 13); v2 *= PRIME32_1; p+=4;
161
+ v3 += XXH_LE32(p) * PRIME32_2; v3 = XXH_rotl32(v3, 13); v3 *= PRIME32_1; p+=4;
162
+ v4 += XXH_LE32(p) * PRIME32_2; v4 = XXH_rotl32(v4, 13); v4 *= PRIME32_1; p+=4;
163
+ } while (p<=limit) ;
164
+
165
+ h32 = XXH_rotl32(v1, 1) + XXH_rotl32(v2, 7) + XXH_rotl32(v3, 12) + XXH_rotl32(v4, 18);
166
+ }
167
+ else
168
+ {
169
+ h32 = seed + PRIME32_5;
170
+ }
171
+
172
+ h32 += (unsigned int) len;
173
+
174
+ while (p<=bEnd-4)
175
+ {
176
+ h32 += XXH_LE32(p) * PRIME32_3;
177
+ h32 = XXH_rotl32(h32, 17) * PRIME32_4 ;
178
+ p+=4;
179
+ }
180
+
181
+ while (p<bEnd)
182
+ {
183
+ h32 += (*p) * PRIME32_5;
184
+ h32 = XXH_rotl32(h32, 11) * PRIME32_1 ;
185
+ p++;
186
+ }
187
+
188
+ h32 ^= h32 >> 15;
189
+ h32 *= PRIME32_2;
190
+ h32 ^= h32 >> 13;
191
+ h32 *= PRIME32_3;
192
+ h32 ^= h32 >> 16;
193
+
194
+ return h32;
195
+
196
+ #endif
197
+ }
198
+
199
+
200
+ //****************************
201
+ // Advanced Hash Functions
202
+ //****************************
203
+
204
+ struct XXH_state32_t
205
+ {
206
+ unsigned int seed;
207
+ unsigned int v1;
208
+ unsigned int v2;
209
+ unsigned int v3;
210
+ unsigned int v4;
211
+ unsigned long long total_len;
212
+ char memory[16];
213
+ int memsize;
214
+ };
215
+
216
+
217
+ void* XXH32_init (unsigned int seed)
218
+ {
219
+ struct XXH_state32_t * state = (struct XXH_state32_t *) malloc ( sizeof(struct XXH_state32_t));
220
+ state->seed = seed;
221
+ state->v1 = seed + PRIME32_1 + PRIME32_2;
222
+ state->v2 = seed + PRIME32_2;
223
+ state->v3 = seed + 0;
224
+ state->v4 = seed - PRIME32_1;
225
+ state->total_len = 0;
226
+ state->memsize = 0;
227
+
228
+ return (void*)state;
229
+ }
230
+
231
+
232
+ int XXH32_feed (void* state_in, const void* input, int len)
233
+ {
234
+ struct XXH_state32_t * state = state_in;
235
+ const unsigned char* p = (const unsigned char*)input;
236
+ const unsigned char* const bEnd = p + len;
237
+
238
+ state->total_len += len;
239
+
240
+ if (state->memsize + len < 16) // fill in tmp buffer
241
+ {
242
+ memcpy(state->memory + state->memsize, input, len);
243
+ state->memsize += len;
244
+ return 0;
245
+ }
246
+
247
+ if (state->memsize) // some data left from previous feed
248
+ {
249
+ memcpy(state->memory + state->memsize, input, 16-state->memsize);
250
+ {
251
+ const unsigned int* p32 = (const unsigned int*)state->memory;
252
+ state->v1 += XXH_LE32(p32) * PRIME32_2; state->v1 = XXH_rotl32(state->v1, 13); state->v1 *= PRIME32_1; p32++;
253
+ state->v2 += XXH_LE32(p32) * PRIME32_2; state->v2 = XXH_rotl32(state->v2, 13); state->v2 *= PRIME32_1; p32++;
254
+ state->v3 += XXH_LE32(p32) * PRIME32_2; state->v3 = XXH_rotl32(state->v3, 13); state->v3 *= PRIME32_1; p32++;
255
+ state->v4 += XXH_LE32(p32) * PRIME32_2; state->v4 = XXH_rotl32(state->v4, 13); state->v4 *= PRIME32_1; p32++;
256
+ }
257
+ p += 16-state->memsize;
258
+ state->memsize = 0;
259
+ }
260
+
261
+ {
262
+ const unsigned char* const limit = bEnd - 16;
263
+ unsigned int v1 = state->v1;
264
+ unsigned int v2 = state->v2;
265
+ unsigned int v3 = state->v3;
266
+ unsigned int v4 = state->v4;
267
+
268
+ while (p<=limit)
269
+ {
270
+ v1 += XXH_LE32(p) * PRIME32_2; v1 = XXH_rotl32(v1, 13); v1 *= PRIME32_1; p+=4;
271
+ v2 += XXH_LE32(p) * PRIME32_2; v2 = XXH_rotl32(v2, 13); v2 *= PRIME32_1; p+=4;
272
+ v3 += XXH_LE32(p) * PRIME32_2; v3 = XXH_rotl32(v3, 13); v3 *= PRIME32_1; p+=4;
273
+ v4 += XXH_LE32(p) * PRIME32_2; v4 = XXH_rotl32(v4, 13); v4 *= PRIME32_1; p+=4;
274
+ }
275
+
276
+ state->v1 = v1;
277
+ state->v2 = v2;
278
+ state->v3 = v3;
279
+ state->v4 = v4;
280
+ }
281
+
282
+ if (p < bEnd)
283
+ {
284
+ memcpy(state->memory, p, bEnd-p);
285
+ state->memsize = bEnd-p;
286
+ }
287
+
288
+ return 0;
289
+ }
290
+
291
+
292
+ unsigned int XXH32_getIntermediateResult (void* state_in)
293
+ {
294
+ struct XXH_state32_t * state = state_in;
295
+ unsigned char * p = (unsigned char*)state->memory;
296
+ unsigned char* bEnd = (unsigned char*)state->memory + state->memsize;
297
+ unsigned int h32;
298
+
299
+
300
+ if (state->total_len >= 16)
301
+ {
302
+ h32 = XXH_rotl32(state->v1, 1) + XXH_rotl32(state->v2, 7) + XXH_rotl32(state->v3, 12) + XXH_rotl32(state->v4, 18);
303
+ }
304
+ else
305
+ {
306
+ h32 = state->seed + PRIME32_5;
307
+ }
308
+
309
+ h32 += (unsigned int) state->total_len;
310
+
311
+ while (p<=bEnd-4)
312
+ {
313
+ h32 += XXH_LE32(p) * PRIME32_3;
314
+ h32 = XXH_rotl32(h32, 17) * PRIME32_4 ;
315
+ p+=4;
316
+ }
317
+
318
+ while (p<bEnd)
319
+ {
320
+ h32 += (*p) * PRIME32_5;
321
+ h32 = XXH_rotl32(h32, 11) * PRIME32_1 ;
322
+ p++;
323
+ }
324
+
325
+ h32 ^= h32 >> 15;
326
+ h32 *= PRIME32_2;
327
+ h32 ^= h32 >> 13;
328
+ h32 *= PRIME32_3;
329
+ h32 ^= h32 >> 16;
330
+
331
+ return h32;
332
+ }
333
+
334
+
335
+ unsigned int XXH32_result (void* state_in)
336
+ {
337
+ unsigned int h32 = XXH32_getIntermediateResult(state_in);
338
+
339
+ free(state_in);
340
+
341
+ return h32;
342
+ }
@@ -0,0 +1,128 @@
1
+ /*
2
+ xxHash - Fast Hash algorithm
3
+ Header File
4
+ Copyright (C) 2012, Yann Collet.
5
+ BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php)
6
+
7
+ Redistribution and use in source and binary forms, with or without
8
+ modification, are permitted provided that the following conditions are
9
+ met:
10
+
11
+ * Redistributions of source code must retain the above copyright
12
+ notice, this list of conditions and the following disclaimer.
13
+ * Redistributions in binary form must reproduce the above
14
+ copyright notice, this list of conditions and the following disclaimer
15
+ in the documentation and/or other materials provided with the
16
+ distribution.
17
+
18
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19
+ "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20
+ LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21
+ A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22
+ OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23
+ SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24
+ LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25
+ DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26
+ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29
+
30
+ You can contact the author at :
31
+ - xxHash source repository : http://code.google.com/p/xxhash/
32
+ */
33
+
34
+ /* Notice extracted from xxHash homepage :
35
+
36
+ xxHash is an extremely fast Hash algorithm, running at RAM speed limits.
37
+ It also successfully passes all tests from the SMHasher suite.
38
+
39
+ Comparison (single thread, Windows Seven 32 bits, using SMHasher on a Core 2 Duo @3GHz)
40
+
41
+ Name Speed Q.Score Author
42
+ xxHash 5.4 GB/s 10
43
+ CrapWow 3.2 GB/s 2 Andrew
44
+ MumurHash 3a 2.7 GB/s 10 Austin Appleby
45
+ SpookyHash 2.0 GB/s 10 Bob Jenkins
46
+ SBox 1.4 GB/s 9 Bret Mulvey
47
+ Lookup3 1.2 GB/s 9 Bob Jenkins
48
+ SuperFastHash 1.2 GB/s 1 Paul Hsieh
49
+ CityHash64 1.05 GB/s 10 Pike & Alakuijala
50
+ FNV 0.55 GB/s 5 Fowler, Noll, Vo
51
+ CRC32 0.43 GB/s 9
52
+ MD5-32 0.33 GB/s 10 Ronald L. Rivest
53
+ SHA1-32 0.28 GB/s 10
54
+
55
+ Q.Score is a measure of quality of the hash function.
56
+ It depends on successfully passing SMHasher test set.
57
+ 10 is a perfect score.
58
+ */
59
+
60
+ #pragma once
61
+
62
+ #if defined (__cplusplus)
63
+ extern "C" {
64
+ #endif
65
+
66
+
67
+ //****************************
68
+ // Simple Hash Functions
69
+ //****************************
70
+
71
+ unsigned int XXH32 (const void* input, int len, unsigned int seed);
72
+
73
+ /*
74
+ XXH32() :
75
+ Calculate the 32-bits hash of "input", of length "len"
76
+ "seed" can be used to alter the result
77
+ This function successfully passes all SMHasher tests.
78
+ Speed on Core 2 Duo @ 3 GHz (single thread, SMHasher benchmark) : 5.4 GB/s
79
+ Note that "len" is type "int", which means it is limited to 2^31-1.
80
+ If your data is larger, use the advanced functions below.
81
+ */
82
+
83
+
84
+
85
+ //****************************
86
+ // Advanced Hash Functions
87
+ //****************************
88
+
89
+ void* XXH32_init (unsigned int seed);
90
+ int XXH32_feed (void* state, const void* input, int len);
91
+ unsigned int XXH32_result (void* state);
92
+
93
+ /*
94
+ These functions calculate the xxhash of an input provided in several small packets,
95
+ as opposed to an input provided as a single block.
96
+
97
+ You must start with :
98
+ void* XXH32_init()
99
+ The function returns a pointer which holds the state of calculation.
100
+
101
+ This pointer must be provided as "void* state" parameter for XXH32_feed().
102
+ XXH32_feed() can be called as many times as necessary.
103
+ The function returns an error code, with 0 meaning OK, and all other values meaning there is an error.
104
+ Note that "len" is type "int", which means it is limited to 2^31-1.
105
+ If your data is larger, it is recommended
106
+ to chunk your data into blocks of size 2^30 (1GB) to avoid any "int" overflow issue.
107
+
108
+ Finally, you can end the calculation anytime, by using XXH32_result().
109
+ This function returns the final 32-bits hash.
110
+ You must provide the same "void* state" parameter created by XXH32_init().
111
+
112
+ Memory will be freed by XXH32_result().
113
+ */
114
+
115
+
116
+ unsigned int XXH32_getIntermediateResult (void* state);
117
+ /*
118
+ This function does the same as XXH32_result(), generating a 32-bit hash,
119
+ but preserve memory context.
120
+ This way, it becomes possible to generate intermediate hashes, and then continue feeding data with XXH32_feed().
121
+ To free memory context, use XXH32_result().
122
+ */
123
+
124
+
125
+
126
+ #if defined (__cplusplus)
127
+ }
128
+ #endif
@@ -0,0 +1,19 @@
1
+ #include <ruby.h>
2
+ #include "libxxhash.h"
3
+
4
+ // Use this typedef to make the compiler happy when
5
+ // calling rb_define_method()
6
+ typedef VALUE (ruby_method)(...);
7
+
8
+ extern "C" VALUE xxhash_xxh32(VALUE mod, VALUE input, VALUE seed)
9
+ {
10
+ return ULL2NUM(XXH32(StringValuePtr(input), RSTRING_LEN(input), NUM2ULL(seed)));
11
+ }
12
+
13
+ extern "C" void Init_xxhash()
14
+ {
15
+ VALUE mXXhash = rb_define_module("XXhash");
16
+ VALUE mInternal = rb_define_module_under(mXXhash, "Internal");
17
+
18
+ rb_define_singleton_method(mInternal, "xxh32", (ruby_method*) &xxhash_xxh32, 2);
19
+ }
@@ -0,0 +1,8 @@
1
+ require 'xxhash/version'
2
+ require 'xxhash/xxhash'
3
+
4
+ module XXhash
5
+ def self.xxh32(input, seed)
6
+ Internal.xxh32(input, seed)
7
+ end
8
+ end
@@ -0,0 +1,3 @@
1
+ module XXhash
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,4 @@
1
+ require 'minitest/autorun'
2
+ require 'minitest/spec'
3
+
4
+ require 'xxhash'
@@ -0,0 +1,7 @@
1
+ require 'test_helper'
2
+
3
+ describe XXhash do
4
+ it 'returns hash' do
5
+ assert_equal 2758658570, XXhash.xxh32('test', 123)
6
+ end
7
+ end
@@ -0,0 +1,20 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'xxhash/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "xxhash"
8
+ gem.version = XXhash::VERSION
9
+ gem.authors = ["Vasiliy Ermolovich"]
10
+ gem.email = ["younash@gmail.com"]
11
+ gem.description = %q{Ruby wrapper for xxHash lib}
12
+ gem.summary = %q{Ruby wrapper for xxHash lib}
13
+ gem.homepage = "http://github.com/nashby/xxhash"
14
+
15
+ gem.files = `git ls-files`.split($/)
16
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
+ gem.require_paths = ["lib"]
19
+ gem.extensions = ["ext/xxhash/extconf.rb"]
20
+ end
metadata ADDED
@@ -0,0 +1,68 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: xxhash
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Vasiliy Ermolovich
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-12-23 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: Ruby wrapper for xxHash lib
15
+ email:
16
+ - younash@gmail.com
17
+ executables: []
18
+ extensions:
19
+ - ext/xxhash/extconf.rb
20
+ extra_rdoc_files: []
21
+ files:
22
+ - .gitignore
23
+ - Gemfile
24
+ - LICENSE.txt
25
+ - README.md
26
+ - Rakefile
27
+ - ext/xxhash/extconf.rb
28
+ - ext/xxhash/libxxhash.c
29
+ - ext/xxhash/libxxhash.h
30
+ - ext/xxhash/xxhash.cc
31
+ - lib/xxhash.rb
32
+ - lib/xxhash/version.rb
33
+ - test/test_helper.rb
34
+ - test/xxhash_test.rb
35
+ - xxhash.gemspec
36
+ homepage: http://github.com/nashby/xxhash
37
+ licenses: []
38
+ post_install_message:
39
+ rdoc_options: []
40
+ require_paths:
41
+ - lib
42
+ required_ruby_version: !ruby/object:Gem::Requirement
43
+ none: false
44
+ requirements:
45
+ - - ! '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ segments:
49
+ - 0
50
+ hash: -2742825382786216064
51
+ required_rubygems_version: !ruby/object:Gem::Requirement
52
+ none: false
53
+ requirements:
54
+ - - ! '>='
55
+ - !ruby/object:Gem::Version
56
+ version: '0'
57
+ segments:
58
+ - 0
59
+ hash: -2742825382786216064
60
+ requirements: []
61
+ rubyforge_project:
62
+ rubygems_version: 1.8.24
63
+ signing_key:
64
+ specification_version: 3
65
+ summary: Ruby wrapper for xxHash lib
66
+ test_files:
67
+ - test/test_helper.rb
68
+ - test/xxhash_test.rb