Git Product home page Git Product logo

xxh3's Introduction

XXH3

CI build status Hex docs Hex Version License

Erlang NIF bindings for XXH3 hash functions implemented in Rust.

Introduction

XXH3 is a new speed-optimized hash algorithm of the xxHash family of non-cryptographic hash functions, featuring:

  • Improved speed for both small and large inputs
  • True 64-bit and 128-bit outputs
  • SIMD acceleration
  • Improved 32-bit viability

Speed analysis methodology is explained here.

Implementation

Erlang nif interface does not support passing bigints to the VM, so for 128-bit variants a 128-bit binary is passed, and then converted to a 128-bit integer in erlang.

Usage

Note that only binary data is accepted. For other types of data you can first convert them to a binary using erlang:term_to_binary/1.

In Erlang

Data = <<"Test Data">>,
Seed = 1,
Secret = crypto:strong_rand_bytes(136),

H64 = xxh3:hash64(Data),
H64WithSeed = xxh3:hash64(Data, Seed),
H64WithSecret = xxh3:hash64_with_secret(Data, Secret),

H128 = xxh3:hash128(Data),
H128WithSeed = xxh3:hash128(Data, Seed),
H128WithSecret = xxh3:hash128_with_secret(Data, Secret).

H64Stream = xxh3:new(),
xxh3:update(H64Stream, Data),
H64 = xxh3:digest(H64Stream)

In Elixir

data = "Test Data"
seed = 1
secret = :crypto.strong_rand_bytes(136)

h64 = :xxh3.hash64(data)
h64_with_seed = :xxh3.hash64(data, seed)
h64_with_secret = :xxh3.hash64_with_secret(data, secret)

h128 = :xxh3.hash128(data)
h128_with_seed = :xxh3.hash128(data, seed)
h128_with_secret = :xxh3.hash128_with_secret(data, secret)

h64_stream = :xxh3.new(),
:xxh3.update(h64_stream, data),
h64 = :xxh3.digest(h64_stream)

For more details, see the module documentation.

License

Copyright 2021, Ali Farhadi [email protected].

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.

xxh3's People

Contributors

doumanash avatar farhadi avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

xxh3's Issues

Could not compile dependency :xxh3 on Erlang/OTP 26

Hello, I think there is a problem with Erlang/OTP 26. I can’t compile xxh3 dependency anymore, I get the following error.
thread 'main' panicked at 'The NIF version from Erlang is not supported by Rustler: 2.17'

According to rusterlium/rustler#544, Rustler should be updated to 0.29

This is what I tried in local

# use local version of xxh3 in mix.exs
  defp deps do
    [
    # ...
      {:xxh3, "~> 0.3.3", path: "/path/to/local/xxh3"}
    ]
  end

In native/xxh3/Cargo.toml

[dependencies]
rustler = "0.29.1"

And now the dependency compiles, but I get this error when trying to call :xxh3
Could not load module :xxh3, got: on_load_failure

Can't compile xxh3, Erlang/OTP 26

error: could not compile xxh3 (lib) due to 2 previous errors

===> Uncaught error in rebar_core. Run with DIAGNOSTIC=1 to see stacktrace or consult rebar3.crashdump
===> When submitting a bug report, please include the output of rebar3 report "your command"

** (Mix) Could not compile dependency :xxh3, "/Users/ben/.mix/elixir/1-16/rebar3 bare compile --paths /Users/ben/oxen/OxenHub/_build/dev/lib/*/ebin" command failed. Errors may have been logged above. You can recompile this dependency with "mix deps.compile xxh3 --force", update it with "mix deps.update xxh3" or clean it with "mix deps.clean xxh3"

Looks possibly related to #2, let me know if there's any other output that's useful!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.