xxhash 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,56 +0,0 @@
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 xxhash_streaming_hash_free(void* state)
14
- {
15
- // Digest frees the memory.
16
- (void) XXH32_digest(state);
17
- }
18
-
19
- extern "C" VALUE xxhash_streaming_hash_new(VALUE klass, VALUE seed)
20
- {
21
- void* state = XXH32_init(NUM2ULL(seed));
22
- return Data_Wrap_Struct(klass, 0, xxhash_streaming_hash_free, state);
23
- }
24
-
25
- extern "C" VALUE xxhash_streaming_hash_update(VALUE self, VALUE data)
26
- {
27
- void* state;
28
- Data_Get_Struct(self, void, state);
29
-
30
- XXH32_update(state, StringValuePtr(data), RSTRING_LEN(data));
31
- return Qnil;
32
- }
33
-
34
- extern "C" VALUE xxhash_streaming_hash_digest(VALUE self)
35
- {
36
- void* state;
37
- Data_Get_Struct(self, void, state);
38
-
39
- // Do not free memory now.
40
- return ULL2NUM(XXH32_intermediateDigest(state));
41
- }
42
-
43
- extern "C" void Init_xxhash()
44
- {
45
- VALUE mXXhash = rb_define_module("XXhash");
46
- VALUE mInternal = rb_define_module_under(mXXhash, "Internal");
47
-
48
- rb_define_singleton_method(mInternal, "xxh32", (ruby_method*) &xxhash_xxh32, 2);
49
-
50
- VALUE cStreamingHash = rb_define_class_under(mInternal, "StreamingHash", rb_cObject);
51
-
52
- rb_define_singleton_method(cStreamingHash, "new", (ruby_method*) &xxhash_streaming_hash_new, 1);
53
- rb_define_method(cStreamingHash, "update", (ruby_method*) &xxhash_streaming_hash_update, 1);
54
- rb_define_method(cStreamingHash, "digest", (ruby_method*) &xxhash_streaming_hash_digest, 0);
55
- rb_define_method(cStreamingHash, "intermediate_digest", (ruby_method*) &xxhash_streaming_hash_digest, 0);
56
- }