GithubHelp home page GithubHelp logo

Reproducible Hashes is 0.8? about ahash HOT 4 CLOSED

domenukk avatar domenukk commented on June 12, 2024
Reproducible Hashes is 0.8?

from ahash.

Comments (4)

rrichardson avatar rrichardson commented on June 12, 2024 1

@domenukk - digging into the code a bit farther, it seems that using RandomState::with_seeds should achieve the old new_with_keys functionality.

e.g.

let st = RandomState::with_seeds(42, 1, 0 5); 
let hasher = st.build_hasher(); 

build_hasher just calls (private) AHasher::from_random_state (https://docs.rs/ahash/latest/src/ahash/aes_hash.rs.html#73)

However, I still don't get consistency across multiple platforms (and I suspect 0.7 is the same)

from ahash.

rrichardson avatar rrichardson commented on June 12, 2024

I am in a similar boat. I've tried setting
default-features = false
then doing :

static HASH_KEY: usize = 12345;

lazy_static! {
    static ref HASH_STATE: RandomState = { 
        set_random_source(NotRandomState).expect("Setting hash state to not-random");
        RandomState::with_seed(HASH_KEY)
    };
}
struct NotRandomState;

impl RandomSource for NotRandomState {
    fn gen_hasher_seed(&self) -> usize {
        HASH_KEY
    }
}

fn hash_stuff(a: A, b: B) -> u64 {
    let mut hasher = HASH_STATE.build_hasher();
    a.hash(&mut hasher);
    b.hash(&mut hasher);
    hasher.finish().into()
}

This seems to produce self-consistent hashes between builds on the same platform.

However, on different platforms (e.g. aarch64) it produces different values.

Is there an easier or more reliable method of ensuring consistencency?

from ahash.

tkaitchuck avatar tkaitchuck commented on June 12, 2024

with_seeds is the method you are looking for.
However please note that aHash does not guarantee identical output across architectures, flags, or versions. For example when 0.8.1 is released, it will have performance improvements but the same data will hash to different values than it did in 0.8.0.

from ahash.

tkaitchuck avatar tkaitchuck commented on June 12, 2024

This is now better documented in 0.8.1:
https://docs.rs/ahash/0.8.1/ahash/random_state/struct.RandomState.html

from ahash.

Related Issues (20)

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.