Comments (2)
@ahornby This is due to a combination of two factors:
- Your implementation is not overriding all of the methods of Hasher and delegating them. So some are being implemented via their default implementation.
- The very unfortunate implementation of string's hashcode in the standard library.
String's hash function is does a double deref to get a [u8] and delegates to that.
The hash for [u8] is here: https://doc.rust-lang.org/beta/src/core/hash/mod.rs.html#667-672
as you can see it is explicitly passing in the length as a separate parameter. This is extremely unfortunate because it causes a loss in performance, because the Hasher implementations have to assume that such a call is not made and incorporate the length, because this is done in other types including arrays. (The specialization feature of aHash works around this, but requires nightly)
So this method is going to call write_usize(). aHash overrides this method, but your wrapping hasher does not, so it will instead call the default implementation here: https://doc.rust-lang.org/src/core/hash/mod.rs.html#322 which is different from how it is implemented in aHash.
So you can make your test pass if you have NewTypeHasher override every method on Hasher and delegate all of them.
That would work and I would expect it to continue to work. However it is worth noting that it is fragile. If a method is added to the Hash interface with a default provided, (as has happened in the past) then your code would not be broken. But then aHash could override that new method and suddenly you would be in the situation you are in now where the hashes don't match.
from ahash.
@tkaitchuck thanks for the great explanation! Yep, difference goes away once all methods wrapped.
from ahash.
Related Issues (20)
- Using with neither `compile-time-rng` or `runtime-rng` features. HOT 2
- Simple, Non-DOS-resistent seed HOT 14
- 0.8.0 requires "resolver" due to Cargo bug HOT 6
- Make once_cell optional to meet reasonable MSRV HOT 8
- Question: Callhasher is removed from public interface HOT 1
- Reproducible Hashes is 0.8? HOT 4
- `random_state::RandomState: Default` not implemented when using neither `compile-time-rng` nor `runtime-rng` features HOT 2
- Fails to compile on no-std
- ahash features are non-additive HOT 5
- Cannot compile to wasm without wasm-bindgen with v0.8.1 HOT 5
- 0.8.1 fails to compile for no-std HOT 2
- ahash: 0.8.1: Failed to parse expression HOT 1
- SMHasher Sparse Test Failure HOT 2
- adding ability to build HashMap from rayon parallel iterator HOT 1
- Please disable feature `runtime-rng` by default HOT 3
- one test failure on s390x-unknown-linux-gnu (big endian) HOT 4
- c++ version? HOT 2
- const function for `HashMap::new` HOT 1
- no_std support HOT 9
- aHash changed TypeId HOT 1
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.