xxhash 0.0.1 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.3
4
+ - rbx-19mode
@@ -0,0 +1,2 @@
1
+ ### 0.1.0 (May 16, 2013)
2
+ * xxHash updated to [r29](https://code.google.com/p/xxhash/source/detail?r=28)
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- ## xxHash
1
+ ## xxHash [![Build Status](https://travis-ci.org/nashby/xxhash.png?branch=master)](https://travis-ci.org/nashby/xxhash)
2
2
 
3
3
  Ruby wrapper for [xxHash](http://code.google.com/p/xxhash/)
4
4
 
@@ -17,6 +17,17 @@ seed = 12345
17
17
  XXhash.xxh32(text, seed) # => 3834992036
18
18
  ```
19
19
 
20
+ ### Supported Ruby versions
21
+
22
+ - MRI 1.9.3
23
+ - rbx-19mode
24
+
25
+ Note: It doesn't work on JRuby as it uses C extension.
26
+
27
+ ### Versioning
28
+
29
+ Version 0.1.0 is equal to [r29](https://code.google.com/p/xxhash/source/detail?r=29)
30
+
20
31
  ## Contributing
21
32
 
22
33
  1. Fork it
@@ -1,33 +1,33 @@
1
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/
2
+ xxHash - Fast Hash algorithm
3
+ Copyright (C) 2012-2013, 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
31
  */
32
32
 
33
33
 
@@ -35,14 +35,21 @@
35
35
  //**************************************
36
36
  // Tuning parameters
37
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.
38
+ // XXH_ACCEPT_NULL_INPUT_POINTER :
39
+ // If the input pointer is a null pointer, xxHash default behavior is to crash, since it is a bad input.
40
+ // If this option is enabled, xxHash output for null input pointers will be the same as a null-length input.
41
+ // This option has a very small performance cost (only measurable on small inputs).
42
+ // By default, this option is disabled. To enable it, uncomment below define :
43
+ //#define XXH_ACCEPT_NULL_INPUT_POINTER 1
44
+
45
+ // XXH_FORCE_NATIVE_FORMAT :
46
+ // By default, xxHash library provides endian-independant Hash values, based on little-endian convention.
47
+ // Results are therefore identical for little-endian and big-endian CPU.
41
48
  // This comes at a performance cost for big-endian CPU, since some swapping is required to emulate little-endian format.
42
49
  // Should endian-independance be of no importance to your application, you may uncomment the #define below
43
50
  // It will improve speed for Big-endian CPU.
44
51
  // This option has no impact on Little_Endian CPU.
45
- //#define FORCE_NATIVE_FORMAT 1
52
+ //#define XXH_FORCE_NATIVE_FORMAT 1
46
53
 
47
54
 
48
55
 
@@ -60,7 +67,7 @@
60
67
  //**************************************
61
68
  // Little Endian or Big Endian ?
62
69
  // You can overwrite the #define below if you know your architecture endianess
63
- #if defined(FORCE_NATIVE_FORMAT) && (FORCE_NATIVE_FORMAT==1)
70
+ #if defined(XXH_FORCE_NATIVE_FORMAT) && (XXH_FORCE_NATIVE_FORMAT==1)
64
71
  // Force native format. The result will be endian dependant.
65
72
  # define XXH_BIG_ENDIAN 0
66
73
  #elif defined (__GLIBC__)
@@ -71,9 +78,9 @@
71
78
  #elif (defined(__BIG_ENDIAN__) || defined(__BIG_ENDIAN) || defined(_BIG_ENDIAN)) && !(defined(__LITTLE_ENDIAN__) || defined(__LITTLE_ENDIAN) || defined(_LITTLE_ENDIAN))
72
79
  # define XXH_BIG_ENDIAN 1
73
80
  #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__)
81
+ || defined(__ppc__) || defined(_POWER) || defined(__powerpc__) || defined(_ARCH_PPC) || defined(__PPC__) || defined(__PPC) || defined(PPC) || defined(__powerpc__) || defined(__powerpc) || defined(powerpc) \
82
+ || defined(__hpux) || defined(__hppa) \
83
+ || defined(_MIPSEB) || defined(__s390__)
77
84
  # define XXH_BIG_ENDIAN 1
78
85
  #endif
79
86
 
@@ -83,6 +90,24 @@
83
90
  #endif
84
91
 
85
92
 
93
+ //**************************************
94
+ // Basic Types
95
+ //**************************************
96
+ #if defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L // C99
97
+ # include <stdint.h>
98
+ typedef uint8_t BYTE;
99
+ typedef uint16_t U16;
100
+ typedef uint32_t U32;
101
+ typedef int32_t S32;
102
+ typedef uint64_t U64;
103
+ #else
104
+ typedef unsigned char BYTE;
105
+ typedef unsigned short U16;
106
+ typedef unsigned int U32;
107
+ typedef signed int S32;
108
+ typedef unsigned long long U64;
109
+ #endif
110
+
86
111
 
87
112
  //**************************************
88
113
  // Compiler-specific Options & Functions
@@ -101,16 +126,14 @@
101
126
  #elif GCC_VERSION >= 403
102
127
  # define XXH_swap32 __builtin_bswap32
103
128
  #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
- }
129
+ static inline U32 XXH_swap32 (U32 x) {
130
+ return ((x << 24) & 0xff000000 ) |
131
+ ((x << 8) & 0x00ff0000 ) |
132
+ ((x >> 8) & 0x0000ff00 ) |
133
+ ((x >> 24) & 0x000000ff );}
110
134
  #endif
111
135
 
112
136
 
113
-
114
137
  //**************************************
115
138
  // Constants
116
139
  //**************************************
@@ -121,11 +144,10 @@ static inline unsigned int XXH_swap32 (unsigned int x) {
121
144
  #define PRIME32_5 374761393U
122
145
 
123
146
 
124
-
125
147
  //**************************************
126
148
  // Macros
127
149
  //**************************************
128
- #define XXH_LE32(p) (XXH_BIG_ENDIAN ? XXH_swap32(*(unsigned int*)(p)) : *(unsigned int*)(p))
150
+ #define XXH_LE32(p) (XXH_BIG_ENDIAN ? XXH_swap32(*(U32*)(p)) : *(U32*)(p))
129
151
 
130
152
 
131
153
 
@@ -133,65 +155,69 @@ static inline unsigned int XXH_swap32 (unsigned int x) {
133
155
  // Simple Hash Functions
134
156
  //****************************
135
157
 
136
- unsigned int XXH32(const void* input, int len, unsigned int seed)
158
+ U32 XXH32(const void* input, int len, U32 seed)
137
159
  {
138
160
  #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);
161
+ // Simple version, good for code maintenance, but unfortunately slow for small inputs
162
+ void* state = XXH32_init(seed);
163
+ XXH32_update(state, input, len);
164
+ return XXH32_digest(state);
143
165
  #else
144
166
 
145
- const unsigned char* p = (const unsigned char*)input;
146
- const unsigned char* const bEnd = p + len;
147
- unsigned int h32;
167
+ const BYTE* p = (const BYTE*)input;
168
+ const BYTE* const bEnd = p + len;
169
+ U32 h32;
170
+
171
+ #ifdef XXH_ACCEPT_NULL_INPUT_POINTER
172
+ if (p==NULL) { len=0; p=(const BYTE*)16; }
173
+ #endif
174
+
175
+ if (len>=16)
176
+ {
177
+ const BYTE* const limit = bEnd - 16;
178
+ U32 v1 = seed + PRIME32_1 + PRIME32_2;
179
+ U32 v2 = seed + PRIME32_2;
180
+ U32 v3 = seed + 0;
181
+ U32 v4 = seed - PRIME32_1;
182
+
183
+ do
184
+ {
185
+ v1 += XXH_LE32(p) * PRIME32_2; v1 = XXH_rotl32(v1, 13); v1 *= PRIME32_1; p+=4;
186
+ v2 += XXH_LE32(p) * PRIME32_2; v2 = XXH_rotl32(v2, 13); v2 *= PRIME32_1; p+=4;
187
+ v3 += XXH_LE32(p) * PRIME32_2; v3 = XXH_rotl32(v3, 13); v3 *= PRIME32_1; p+=4;
188
+ v4 += XXH_LE32(p) * PRIME32_2; v4 = XXH_rotl32(v4, 13); v4 *= PRIME32_1; p+=4;
189
+ } while (p<=limit);
190
+
191
+ h32 = XXH_rotl32(v1, 1) + XXH_rotl32(v2, 7) + XXH_rotl32(v3, 12) + XXH_rotl32(v4, 18);
192
+ }
193
+ else
194
+ {
195
+ h32 = seed + PRIME32_5;
196
+ }
197
+
198
+ h32 += (U32) len;
148
199
 
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;
200
+ while (p<=bEnd-4)
201
+ {
202
+ h32 += XXH_LE32(p) * PRIME32_3;
203
+ h32 = XXH_rotl32(h32, 17) * PRIME32_4 ;
204
+ p+=4;
205
+ }
156
206
 
157
- do
207
+ while (p<bEnd)
158
208
  {
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;
209
+ h32 += (*p) * PRIME32_5;
210
+ h32 = XXH_rotl32(h32, 11) * PRIME32_1 ;
211
+ p++;
212
+ }
213
+
214
+ h32 ^= h32 >> 15;
215
+ h32 *= PRIME32_2;
216
+ h32 ^= h32 >> 13;
217
+ h32 *= PRIME32_3;
218
+ h32 ^= h32 >> 16;
219
+
220
+ return h32;
195
221
 
196
222
  #endif
197
223
  }
@@ -203,140 +229,155 @@ unsigned int XXH32(const void* input, int len, unsigned int seed)
203
229
 
204
230
  struct XXH_state32_t
205
231
  {
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;
232
+ U32 seed;
233
+ U32 v1;
234
+ U32 v2;
235
+ U32 v3;
236
+ U32 v4;
237
+ U64 total_len;
238
+ char memory[16];
239
+ int memsize;
214
240
  };
215
241
 
216
242
 
217
- void* XXH32_init (unsigned int seed)
243
+ int XXH32_sizeofState() { return sizeof(struct XXH_state32_t); }
244
+
245
+
246
+ XXH_errorcode XXH32_resetState(void* state_in, unsigned int seed)
247
+ {
248
+ struct XXH_state32_t * state = (struct XXH_state32_t *) state_in;
249
+ state->seed = seed;
250
+ state->v1 = seed + PRIME32_1 + PRIME32_2;
251
+ state->v2 = seed + PRIME32_2;
252
+ state->v3 = seed + 0;
253
+ state->v4 = seed - PRIME32_1;
254
+ state->total_len = 0;
255
+ state->memsize = 0;
256
+ return OK;
257
+ }
258
+
259
+
260
+ void* XXH32_init (U32 seed)
218
261
  {
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;
262
+ struct XXH_state32_t * state = (struct XXH_state32_t *) malloc (sizeof(struct XXH_state32_t));
263
+ XXH32_resetState(state, seed);
264
+ return (void*)state;
229
265
  }
230
266
 
231
267
 
232
- int XXH32_feed (void* state_in, const void* input, int len)
268
+ XXH_errorcode XXH32_update (void* state_in, const void* input, int len)
233
269
  {
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);
270
+ struct XXH_state32_t * state = (struct XXH_state32_t *) state_in;
271
+ const BYTE* p = (const BYTE*)input;
272
+ const BYTE* const bEnd = p + len;
273
+
274
+ #ifdef XXH_ACCEPT_NULL_INPUT_POINTER
275
+ if (input==NULL) return XXH_ERROR;
276
+ #endif
277
+
278
+ state->total_len += len;
279
+
280
+ if (state->memsize + len < 16) // fill in tmp buffer
250
281
  {
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++;
282
+ memcpy(state->memory + state->memsize, input, len);
283
+ state->memsize += len;
284
+ return OK;
256
285
  }
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
286
 
268
- while (p<=limit)
287
+ if (state->memsize) // some data left from previous update
269
288
  {
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;
289
+ memcpy(state->memory + state->memsize, input, 16-state->memsize);
290
+ {
291
+ const U32* p32 = (const U32*)state->memory;
292
+ state->v1 += XXH_LE32(p32) * PRIME32_2; state->v1 = XXH_rotl32(state->v1, 13); state->v1 *= PRIME32_1; p32++;
293
+ state->v2 += XXH_LE32(p32) * PRIME32_2; state->v2 = XXH_rotl32(state->v2, 13); state->v2 *= PRIME32_1; p32++;
294
+ state->v3 += XXH_LE32(p32) * PRIME32_2; state->v3 = XXH_rotl32(state->v3, 13); state->v3 *= PRIME32_1; p32++;
295
+ state->v4 += XXH_LE32(p32) * PRIME32_2; state->v4 = XXH_rotl32(state->v4, 13); state->v4 *= PRIME32_1; p32++;
296
+ }
297
+ p += 16-state->memsize;
298
+ state->memsize = 0;
274
299
  }
275
300
 
276
- state->v1 = v1;
277
- state->v2 = v2;
278
- state->v3 = v3;
279
- state->v4 = v4;
280
- }
301
+ if (p <= bEnd-16)
302
+ {
303
+ const BYTE* const limit = bEnd - 16;
304
+ U32 v1 = state->v1;
305
+ U32 v2 = state->v2;
306
+ U32 v3 = state->v3;
307
+ U32 v4 = state->v4;
308
+
309
+ do
310
+ {
311
+ v1 += XXH_LE32(p) * PRIME32_2; v1 = XXH_rotl32(v1, 13); v1 *= PRIME32_1; p+=4;
312
+ v2 += XXH_LE32(p) * PRIME32_2; v2 = XXH_rotl32(v2, 13); v2 *= PRIME32_1; p+=4;
313
+ v3 += XXH_LE32(p) * PRIME32_2; v3 = XXH_rotl32(v3, 13); v3 *= PRIME32_1; p+=4;
314
+ v4 += XXH_LE32(p) * PRIME32_2; v4 = XXH_rotl32(v4, 13); v4 *= PRIME32_1; p+=4;
315
+ } while (p<=limit);
316
+
317
+ state->v1 = v1;
318
+ state->v2 = v2;
319
+ state->v3 = v3;
320
+ state->v4 = v4;
321
+ }
281
322
 
282
- if (p < bEnd)
283
- {
284
- memcpy(state->memory, p, bEnd-p);
285
- state->memsize = bEnd-p;
286
- }
323
+ if (p < bEnd)
324
+ {
325
+ memcpy(state->memory, p, bEnd-p);
326
+ state->memsize = (int)(bEnd-p);
327
+ }
287
328
 
288
- return 0;
329
+ return OK;
289
330
  }
290
331
 
291
332
 
292
- unsigned int XXH32_getIntermediateResult (void* state_in)
333
+ U32 XXH32_intermediateDigest (void* state_in)
293
334
  {
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;
335
+ struct XXH_state32_t * state = (struct XXH_state32_t *) state_in;
336
+ BYTE * p = (BYTE*)state->memory;
337
+ BYTE* bEnd = (BYTE*)state->memory + state->memsize;
338
+ U32 h32;
339
+
340
+
341
+ if (state->total_len >= 16)
342
+ {
343
+ h32 = XXH_rotl32(state->v1, 1) + XXH_rotl32(state->v2, 7) + XXH_rotl32(state->v3, 12) + XXH_rotl32(state->v4, 18);
344
+ }
345
+ else
346
+ {
347
+ h32 = state->seed + PRIME32_5;
348
+ }
349
+
350
+ h32 += (U32) state->total_len;
351
+
352
+ while (p<=bEnd-4)
353
+ {
354
+ h32 += XXH_LE32(p) * PRIME32_3;
355
+ h32 = XXH_rotl32(h32, 17) * PRIME32_4;
356
+ p+=4;
357
+ }
358
+
359
+ while (p<bEnd)
360
+ {
361
+ h32 += (*p) * PRIME32_5;
362
+ h32 = XXH_rotl32(h32, 11) * PRIME32_1;
363
+ p++;
364
+ }
365
+
366
+ h32 ^= h32 >> 15;
367
+ h32 *= PRIME32_2;
368
+ h32 ^= h32 >> 13;
369
+ h32 *= PRIME32_3;
370
+ h32 ^= h32 >> 16;
371
+
372
+ return h32;
332
373
  }
333
374
 
334
375
 
335
- unsigned int XXH32_result (void* state_in)
376
+ U32 XXH32_digest (void* state_in)
336
377
  {
337
- unsigned int h32 = XXH32_getIntermediateResult(state_in);
378
+ U32 h32 = XXH32_intermediateDigest(state_in);
338
379
 
339
- free(state_in);
380
+ free(state_in);
340
381
 
341
- return h32;
382
+ return h32;
342
383
  }
@@ -1,7 +1,7 @@
1
1
  /*
2
2
  xxHash - Fast Hash algorithm
3
3
  Header File
4
- Copyright (C) 2012, Yann Collet.
4
+ Copyright (C) 2012-2013, Yann Collet.
5
5
  BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php)
6
6
 
7
7
  Redistribution and use in source and binary forms, with or without
@@ -64,6 +64,13 @@ extern "C" {
64
64
  #endif
65
65
 
66
66
 
67
+ //****************************
68
+ // Type
69
+ //****************************
70
+ typedef enum { OK=0, XXH_ERROR } XXH_errorcode;
71
+
72
+
73
+
67
74
  //****************************
68
75
  // Simple Hash Functions
69
76
  //****************************
@@ -72,8 +79,9 @@ unsigned int XXH32 (const void* input, int len, unsigned int seed);
72
79
 
73
80
  /*
74
81
  XXH32() :
75
- Calculate the 32-bits hash of "input", of length "len"
76
- "seed" can be used to alter the result
82
+ Calculate the 32-bits hash of sequence of length "len" stored at memory address "input".
83
+ The memory between input & input+len must be valid (allocated and read-accessible).
84
+ "seed" can be used to alter the result predictably.
77
85
  This function successfully passes all SMHasher tests.
78
86
  Speed on Core 2 Duo @ 3 GHz (single thread, SMHasher benchmark) : 5.4 GB/s
79
87
  Note that "len" is type "int", which means it is limited to 2^31-1.
@@ -86,43 +94,66 @@ XXH32() :
86
94
  // Advanced Hash Functions
87
95
  //****************************
88
96
 
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);
97
+ void* XXH32_init (unsigned int seed);
98
+ XXH_errorcode XXH32_update (void* state, const void* input, int len);
99
+ unsigned int XXH32_digest (void* state);
92
100
 
93
101
  /*
94
102
  These functions calculate the xxhash of an input provided in several small packets,
95
103
  as opposed to an input provided as a single block.
96
104
 
97
- You must start with :
105
+ It must be started with :
98
106
  void* XXH32_init()
99
107
  The function returns a pointer which holds the state of calculation.
100
108
 
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.
109
+ This pointer must be provided as "void* state" parameter for XXH32_update().
110
+ XXH32_update() can be called as many times as necessary.
111
+ The user must provide a valid (allocated) input.
112
+ The function returns an error code, with 0 meaning OK, and any other value meaning there is an error.
104
113
  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.
114
+ If your data is larger, it is recommended to chunk your data into blocks
115
+ of size for example 2^30 (1GB) to avoid any "int" overflow issue.
107
116
 
108
- Finally, you can end the calculation anytime, by using XXH32_result().
117
+ Finally, you can end the calculation anytime, by using XXH32_digest().
109
118
  This function returns the final 32-bits hash.
110
119
  You must provide the same "void* state" parameter created by XXH32_init().
120
+ Memory will be freed by XXH32_digest().
121
+ */
122
+
111
123
 
112
- Memory will be freed by XXH32_result().
124
+ int XXH32_sizeofState();
125
+ XXH_errorcode XXH32_resetState(void* state_in, unsigned int seed);
126
+ /*
127
+ These functions are the basic elements of XXH32_init();
128
+ The objective is to allow user application to make its own allocation.
129
+
130
+ XXH32_sizeofState() is used to know how much space must be allocated by the application.
131
+ This space must be referenced by a void* pointer.
132
+ This pointer must be provided as 'state_in' into XXH32_resetState(), which initializes the state.
113
133
  */
114
134
 
115
135
 
116
- unsigned int XXH32_getIntermediateResult (void* state);
136
+ unsigned int XXH32_intermediateDigest (void* state);
117
137
  /*
118
- This function does the same as XXH32_result(), generating a 32-bit hash,
138
+ This function does the same as XXH32_digest(), generating a 32-bit hash,
119
139
  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().
140
+ This way, it becomes possible to generate intermediate hashes, and then continue feeding data with XXH32_update().
141
+ To free memory context, use XXH32_digest().
122
142
  */
123
143
 
124
144
 
125
145
 
146
+ //****************************
147
+ // Deprecated function names
148
+ //****************************
149
+ // The following translations are provided to ease code transition
150
+ // You are encouraged to no longer this function names
151
+ #define XXH32_feed XXH32_update
152
+ #define XXH32_result XXH32_digest
153
+ #define XXH32_getIntermediateResult XXH32_intermediateDigest
154
+
155
+
156
+
126
157
  #if defined (__cplusplus)
127
158
  }
128
159
  #endif
@@ -1,3 +1,3 @@
1
1
  module XXhash
2
- VERSION = "0.0.1"
2
+ VERSION = "0.1.0"
3
3
  end
Binary file
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: xxhash
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.1.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-12-23 00:00:00.000000000 Z
12
+ date: 2013-05-16 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: Ruby wrapper for xxHash lib
15
15
  email:
@@ -20,6 +20,8 @@ extensions:
20
20
  extra_rdoc_files: []
21
21
  files:
22
22
  - .gitignore
23
+ - .travis.yml
24
+ - CHANGELOG
23
25
  - Gemfile
24
26
  - LICENSE.txt
25
27
  - README.md
@@ -30,6 +32,7 @@ files:
30
32
  - ext/xxhash/xxhash.cc
31
33
  - lib/xxhash.rb
32
34
  - lib/xxhash/version.rb
35
+ - lib/xxhash/xxhash.bundle
33
36
  - test/test_helper.rb
34
37
  - test/xxhash_test.rb
35
38
  - xxhash.gemspec
@@ -47,7 +50,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
47
50
  version: '0'
48
51
  segments:
49
52
  - 0
50
- hash: -2742825382786216064
53
+ hash: 3604602094335288610
51
54
  required_rubygems_version: !ruby/object:Gem::Requirement
52
55
  none: false
53
56
  requirements:
@@ -56,7 +59,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
56
59
  version: '0'
57
60
  segments:
58
61
  - 0
59
- hash: -2742825382786216064
62
+ hash: 3604602094335288610
60
63
  requirements: []
61
64
  rubyforge_project:
62
65
  rubygems_version: 1.8.24