Coder Social home page Coder Social logo

veminovici / aabel-multihash-rs Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 22 KB

A rust crate which extends the Hasher trait. The added functionality allows the users to get multiple hash values for any given hashable item.

Rust 100.00%
hash probabilistic-data-structures

aabel-multihash-rs's Introduction

Simplee > Aabel > Multi-Hash

Crates.io CI GitHub top language License:MIT GitHub code size in bytes GitHub last commit GitHub watchers

A crate which extends Hasher and BuildHasher traits. These extensions can be used in algorithms, eg streaming ones, which require several hashing functions to be executed for each incoming item. As example, bloom filter and count-min use such hash values to represent the incoming items.

HasherExt Trait

The HasherExt trait extends the Hasher trait by adding capabilities to finalize the hashing operation and getting back an infinite sequest of hash values. The crate provides PairHasher which implements the HasherExt trait. The PairHasher is a combinator of two separate hashers, which are used to obtain the sequece of hash values, each value representing the result of an independent hashing function.

pub trait HasherExt: Hasher {
    fn finish_iter(self) -> impl Iterator<Item = u64>;
}

You can see the full definition of the HasherExt trait in the lib.hs file.

The crate provides PairHasher which implements the HasherExt trait. The implementation uses two hashers, which are used to obtain the sequence of the hash values. You can see the full definition at pairhasher.rs.

BuildHasherExt Trait

The BuildHasherExt trait extends the BuildHasher trait. It adds a cabapility to internally build an instance of the HasherExt trait which is used to generate the sequence of the hash values. The BuildHasherExt trait exposes the hashes_one function, which is the one that takes as input an item and returns the sequence of the hash values. You cann see the definition of the BuildHasher trait in the lib.hs file.

pub trait BuildHasherExt: BuildHasher {
    /// Generates the sequece of hash values for a given item.
    fn hashes_one<T: Hash>(&self, item: T) -> impl Iterator<Item = u64>;
}

The crate provides BuildPairHasher which implements the BuildHasherExt trait. The implementation uses two hashers builders, which are used to build internally a PairHasher instance. You can find the source of the BuildPairHasher in the pairhasher.rs.

The BuildPairHasher is the main entry point for the users who want to get sequences of hash values, see the example below.

Example

use aabel_multihash_rs::{BuildHasherExt, BuildPairHasher};
use std::hash::{BuildHasher, Hash};

// Create the hasher builder
let keys1 = (0, 0);
let keys2 = (1, 1);
let builder = BuildPairHasher::new_with_keys(keys1, keys2);

// The number of hash functions
const HASH_COUNT: usize = 10;

// Compute 10 hash values
let item = "Hello world!";
let hashes = builder
    .hashes_one(item)
    .take(HASHE_COUNT)
    .collect::<Vec<_>>();

assert_eq!(hashes.len(), HASHE_COUNT)

About

Code designed and written on the beautiful island of Saaremaa, Estonia.

aabel-multihash-rs's People

Contributors

veminovici 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.