Comments (5)
In other words, the feature compile-time-rng means the lack of randomness.
It does not. You misunderstand the design. The flag merely indicates the source of the seed for the generator of the random keys used in the maps. If your map is created by HashMap::default()
it will always (regardless of flags) have a unique set of keys. So even if there were no other flags anywhere on your path, each hashmap would have a unique set of keys.
You can alter this behavior, but not using flags. See the documentation here:
https://docs.rs/ahash/0.8.1/ahash/random_state/struct.RandomState.html
and here:
https://docs.rs/ahash/0.8.1/ahash/random_state/trait.RandomSource.html
from ahash.
We want to use just the AHasher
to create unique identifiers for some data deterministically across multiple machines. We came across this issue as well that compile-time-rng
has no effect.
It seems like me & some other people are getting confused between keys, seeds, & src.
If I'm correct, keys are the final thing this is stored & used for hashing. Seeds are the compile time or runtime randomness controlled using the feature flags & src is a random number generator which operates on top of seeds. So keys are created based on seeds & src. It does not help that the API is with_seed
when it actually means with_key
.
So, it is true that if the compile-time-rng is enabled & runtime-rng is disabled, then the AHashMap would still've different keys. But this is not true for the AHasher. The solution for us is to use the https://docs.rs/ahash/latest/ahash/random_state/struct.RandomState.html#method.with_seeds API to create AHashers with fixed keys, but it is not very convenient.
I think either new APIs for this should be added or this distinction should be properly explained in the docs at least.
from ahash.
I have recently been hit by this.
I have specified default-features = false
and compile-time-rng
for ahash
, only to find that it didn't work. After a lot of trouble-shooting, I discovered that another dependency crate has ahash
deep down its dependency tree (I used cargo tree
to find it), and that ahash
has default. Which means the default features get merged into my ahash
.
There is no easy solution to this. Even renaming the crate to, say, ahash2
doesn't prevent this merging of features. It must be separated into different source repo's in order to bypass this.
from ahash.
I am not sure how this can be observed externally, or in what sense it violates policies.
To clarify the difference between either of the flags being set or neither is just where the fixed random seeds come from. If runtime-rng
is on they are statically initialized to values from getrandom
. If compile-time-rng
is enabled they are from constants embedded at compile time. If neither are enabled, fixed constants are used. There are two apis which are enabled if either compile-time-rng
or runtime-rng
are enabled. So if runtime-rng
is turned on by another package, there is no change to the API surface.
Depending on which flag is set it will either use getrandom
or a random constant for the fixed seeds. But that is an internal implementation detail that can't be observed in any way. (How could you tell the difference between two sources of random numbers?)
This could be noticed because getrandom
is downloaded a dependency. But that would happen no matter what if there is another package depending on the runtime-rng
feature.
So, @schungx I am not sure what you mean by "only to find that it didn't work". What didn't work?
In theory if both flags are enabled I could have the compile-time-rng
generated fixed constants in the code, but then at runtime immediately replace them with values from getrandom
. But what would be the point? It would just embed random constants into the binary that are never used.
from ahash.
So, @schungx I am not sure what you mean by "only to find that it didn't work". What didn't work?
What I mean is that the features are not strictly additive. As one overrides the other. That's not additive.
In other words, the feature compile-time-rng
means the lack of randomness. Remember the lack of functionality is by itself a functionality, if that lack is depended upon. You cannot merge a "minus", so that makes it non-additive.
I have seen a crate being very careful to only specify compile-time-rng
because it needs one and won't work without a random generator. Yes, this is a niche use case.
However, some dependency down the tree also uses ahash
with default, which is runtime-rng
. This overrides the other feature when cargo merges them.
So that crate no longer works properly and this is very hard to debug. In fact, many non-additive cargo feature issues are hard to debug .
from ahash.
Related Issues (20)
- Deterministic hash value HOT 2
- error[E0635]: unknown feature `stdsimd` HOT 19
- Significant bump in MSRV from 0.8.7 to 0.8.8 HOT 9
- No link to crates.io HOT 1
- RandomState has too many collisions in low order bits when hashing a u64 HOT 29
- Hashing `&T` yields different results compared to `T`
- Fragile build script: crate automatically enables "specialize" feature HOT 14
- ahash 0.8.11 breaks hashbrown? HOT 6
- Work around `swap_bytes` on WebAssembly HOT 3
- git source unaligned with crates.io release HOT 5
- Linking Errors with Specific Optimization Levels When Running Test Cases HOT 1
- rust v1.78 std simd feature removed HOT 1
- `set_random_source` never returns `Err(false)`
- Replace atomic-polyfill with portable-atomic
- Mismatch between published version on crates.io and tagged version in git repo for v0.8.11 HOT 8
- Suggestion: Alternative wrapper HOT 1
- AES not enabled on AArch64
- Hash output is different when using target-cpu=native
- Hashing `&T` yields different results compared to `T` in **nightly** channel HOT 1
- Require an opt-in for enabling `min_specialization` rustc feature
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ahash.