Git Product home page Git Product logo

xxhash-rust's Introduction

xxhash-rust

Rust Crates.io Documentation

Implementation of xxHash in Rust

Each algorithm is implemented via feature, allowing precise control over code size.

Example

  • Cargo.toml
[dependencies.xxhash-rust]
version = "0.8.5"
features = ["xxh3", "const_xxh3"]
  • main.rs
use xxhash_rust::const_xxh3::xxh3_64 as const_xxh3;
use xxhash_rust::xxh3::xxh3_64;

const TEST: u64 = const_xxh3(b"TEST");

fn test_input(text: &str) -> bool {
    match xxh3_64(text.as_bytes()) {
        TEST => true,
        _ => false
    }
}

assert!(!test_input("tEST"));
assert!(test_input("TEST"));

Features:

By default all features are off.

  • xxh32 - Enables 32bit algorithm. Suitable for x86 targets
  • const_xxh32 - const fn version of xxh32 algorithm
  • xxh64 - Enables 64 algorithm. Suitable for x86_64 targets
  • const_xxh64 - const fn version of xxh64 algorithm
  • xxh3 - Enables xxh3 family of algorithms, superior to xxh32 and xxh64 in terms of performance.
  • const_xxh3 - const fn version of xxh3 algorithm

HW acceleration

Similar to reference implementation, crate implements various SIMDs in xxh3 depending on provided flags. All checks are performed only at compile time, hence user is encouraged to enable these accelerations (for example via -C target_cpu=native)

Used SIMD acceleration:

  • SSE2 - widely available, can be safely enabled in 99% of cases. Enabled by default in x86_64 targets.
  • AVX2;

Streaming vs One-shot

For performance reasons one-shot version of algorithm does not re-use streaming version. Unless needed, user is advised to use one-shot version which tends to be more optimal.

const fn version

While const fn provides compile time implementation, it does so at performance cost. Hence you should only use it at compile time.

To guarantee that something is computed at compile time make sure to initialize hash output as const or static variable, otherwise it is possible function is executed at runtime, which would be worse than regular algorithm.

const fn is implemented in best possible way while conforming to limitations of Rust const fn, but these limitations are quite strict making any high performance code impossible.

Version note

  • 0.8.* corresponds to C's 0.8.*

In order to keep up with original implementation version I'm not planning to bump major/minor until C implementation does so.

Comparison with twox-hash

Refer to my comment

xxhash-rust's People

Contributors

doumanash avatar farhadi avatar arthurprs avatar dylan-dpc avatar decathorpe avatar lompik avatar ghostd avatar

Watchers

 avatar

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.