1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 | #include <stdint.h>
|
7 | #include <stdlib.h>
|
8 | #include <node.h>
|
9 | #include <nan.h>
|
10 |
|
11 | #include "murmur3.h"
|
12 | #include "mrmr.h"
|
13 |
|
14 | NAN_METHOD(murmur3_sum) {
|
15 | if (info.Length() < 2)
|
16 | return Nan::ThrowError("murmur3.sum() requires arguments.");
|
17 |
|
18 | v8::Local<v8::Object> buf = info[0].As<v8::Object>();
|
19 |
|
20 | if (!node::Buffer::HasInstance(buf))
|
21 | return Nan::ThrowTypeError("First argument must be a buffer.");
|
22 |
|
23 | if (!info[1]->IsNumber())
|
24 | return Nan::ThrowTypeError("Second argument must be a number.");
|
25 |
|
26 | const uint8_t *data = (const uint8_t *)node::Buffer::Data(buf);
|
27 | size_t len = node::Buffer::Length(buf);
|
28 | uint32_t seed = info[1]->Uint32Value();
|
29 |
|
30 | info.GetReturnValue().Set(
|
31 | Nan::New<v8::Uint32>(mrmr_murmur3_sum(data, len, seed)));
|
32 | }
|
33 |
|
34 | NAN_METHOD(murmur3_tweak) {
|
35 | if (info.Length() < 3)
|
36 | return Nan::ThrowError("murmur3.tweak() requires arguments.");
|
37 |
|
38 | v8::Local<v8::Object> buf = info[0].As<v8::Object>();
|
39 |
|
40 | if (!node::Buffer::HasInstance(buf))
|
41 | return Nan::ThrowTypeError("First argument must be a buffer.");
|
42 |
|
43 | if (!info[1]->IsNumber())
|
44 | return Nan::ThrowTypeError("Second argument must be a number.");
|
45 |
|
46 | if (!info[2]->IsNumber())
|
47 | return Nan::ThrowTypeError("Third argument must be a number.");
|
48 |
|
49 | const uint8_t *data = (const uint8_t *)node::Buffer::Data(buf);
|
50 | size_t len = node::Buffer::Length(buf);
|
51 | uint32_t n = info[1]->Uint32Value();
|
52 | uint32_t tweak = info[2]->Uint32Value();
|
53 |
|
54 | info.GetReturnValue().Set(
|
55 | Nan::New<v8::Uint32>(mrmr_murmur3_tweak(data, len, n, tweak)));
|
56 | }
|
57 |
|
58 | NAN_MODULE_INIT(init) {
|
59 | Nan::Export(target, "murmur3_sum", murmur3_sum);
|
60 | Nan::Export(target, "murmur3_tweak", murmur3_tweak);
|
61 | }
|
62 |
|
63 | NODE_MODULE(mrmr, init)
|