summaryrefslogtreecommitdiff
path: root/src/exxhash/c_src/exxhash.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/exxhash/c_src/exxhash.c')
-rw-r--r--src/exxhash/c_src/exxhash.c31
1 files changed, 31 insertions, 0 deletions
diff --git a/src/exxhash/c_src/exxhash.c b/src/exxhash/c_src/exxhash.c
new file mode 100644
index 000000000..cb498c419
--- /dev/null
+++ b/src/exxhash/c_src/exxhash.c
@@ -0,0 +1,31 @@
+// Licensed under the Apache License, Version 2.0 (the "License"); you may not
+// use this file except in compliance with the License. You may obtain a copy of
+// the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+// License for the specific language governing permissions and limitations under
+// the License.
+
+#include "erl_nif.h"
+#include "xxhash.h"
+
+static ERL_NIF_TERM xxhash128_nif(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[])
+{
+ ErlNifBinary bin;
+ if(!enif_inspect_binary(env, argv[0], &bin)) {
+ return enif_make_badarg(env);
+ }
+ XXH128_hash_t h = XXH3_128bits((const char*) bin.data, (const size_t) bin.size);
+ return enif_make_tuple2(env, enif_make_uint64(env, h.high64), enif_make_uint64(env, h.low64));
+}
+
+static ErlNifFunc funcs[] = {
+ {"xxhash128_plain_nif", 1, xxhash128_nif},
+ {"xxhash128_dirty_nif", 1, xxhash128_nif, ERL_NIF_DIRTY_JOB_CPU_BOUND}
+};
+
+ERL_NIF_INIT(exxhash, funcs, NULL, NULL, NULL, NULL);