Giter VIP home page Giter VIP logo

Comments (6)

Amanieu avatar Amanieu commented on July 21, 2024 1

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.

jonhoo avatar jonhoo commented on July 21, 2024

cc @ms705

from hashbrown.

fintelia avatar fintelia commented on July 21, 2024

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.

jonhoo avatar jonhoo commented on July 21, 2024

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

jonhoo avatar jonhoo commented on July 21, 2024

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.

jonhoo avatar jonhoo commented on July 21, 2024

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)

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.