Comments (6)
As you said, this is a very niche use case and I don't think that it is appropriate to support this API in hashbrown. Have you considered using IndexMap
which does support your use case?
from hashbrown.
cc @ms705
from hashbrown.
Another option is to keep a long lived fork of hashbrown, which I think would be much less painful than a fork of the standard library. The standard hashmap uses a ton of unstable features, including a couple compiler internal features. My fork could thus only run on nightly and even then frequently breaks without warning because of some compiler change. The only way I've stood a chance at keeping it working was to signup for notification emails any time there was a change to the hash_map directory in the main Rust repository.
To me this points to a broader point that the standard library is too tightly coupled to the compiler. hashbrown gets better performance despite not relying on these internal features.
from hashbrown.
@Amanieu unfortunately it's a little complicated by the fact that we are accessing the map through evmap
, and I don't think evmap
will want to switch from hashbrown
to IndexMap
... That said, maybe the trick will be to somehow make evmap
generic over the underlying map (if that doesn't require higher-kinded trait bounds that is)... Thanks anyway!
from hashbrown.
An alternative here I suppose is to emulate Python's dict::popitem
which just removes and returns an arbitrary (key, value)
. This has the added benefit that you can do things like:
while let Some((key, value)) = map.popitem() {
// ...
map.insert(key2, value2);
}
The downside though is that if it removes, say, the first item by hash value, it will always remove the same key if you re-insert it, which makes it a poor choice for eviction. One workaround for that might be to remove the first element following a random starting position.
from hashbrown.
Just for completeness and for others looking at this, this ties in to rust-lang/rust#27804 and rust-lang/rfcs#1800
from hashbrown.
Related Issues (20)
- Support fallible eq and hasher in raw API HOT 8
- ahash shouldn't be the default Hasher HOT 3
- UB on aarch64_be-unknown-linux-gnu_ilp32 HOT 1
- latest/recent rev appears to break ahash/compile-time-rng usage HOT 2
- Why the identity function can be used as unlikely function? HOT 3
- `hashbrown` fails to compile as a transitive dependency HOT 2
- allocator-api2 default-feature? HOT 2
- Compiling hashbrown 0.14.2 for aarch64-unknown-linux-gnu with "target-cpu=cortex-a53" generates illegal instructions HOT 2
- Switching to GxHash? HOT 9
- Feature: increase capacity according to the actual size returned by the allocator HOT 2
- Hashbrown crash due to bad malloc HOT 1
- 0.14.3 - no method named `clear` found for struct `HashMap` in the current scope HOT 5
- Benchmark biaised due to no fence around input
- assertion failed: buckets.is_power_of_two() HOT 8
- Build breaks on nightly due to use of `stdsimd` rust feature in ahash 0.8.6 HOT 2
- Was swap-remove behavior ever considered when removing entries? HOT 10
- Consider returning to 1.63.0 MSRV HOT 1
- How to calculate the size of the hashbrown::HashMap at runtime? HOT 1
- LLVM failed to use the knowledge from a never-overflow assumption HOT 13
- Library test `map::test_map::test_clone_from_memory_leaks` errors with using uninitialized data under valgrind and miri
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 hashbrown.