Comments (6)
Yep. I like the idea of being able to only lock the single bin entry for the Entry API. In order to get the entry API working similar to Java implementation I was going to introduce BinEntry::Reservation(Mutex<()>)
but using Condvar
is a better option than a Mutex
and I like that you can then use this for mutating existing items as well so I'm thinking that going with your Mutating
variant might be a good idea for the Entry API. I haven't had the chance to properly study the Java code and understand why it holds a lock on the entire bin in the first place. We would need to be careful that we don't introduce subtle races into the code.
from flurry.
This seems similar to the Entry API mentioned in #12. The Java code has a concept called ReservationNode
, however @jonhoo points out in his comment that these are only used if the respective bin is empty at the time of reference. Nonetheless, I suggest that we try to find a unified solution for both issues.
With regard to rewriting the current function implementations, I'd say this is not such a big issue since such case distinctions will have to be added anyways for things like #13.
Overall I agree that your proposed solution is preferable over the "easy" one, in particular if we manage to use it for something like an Entry API as well.
from flurry.
I'm a little strapped for time these days, so won't have the time to give this quite the time it deserves, but my first instinct is that it seems unfortunate to hold the lock for the entire bin just to get mutable access to one value. Though admittedly, that is also what the proposed Entry
API would do.
My second instinct is that it's not clear how we can ever give out &mut V
, since reads never take the bin lock.
from flurry.
it seems unfortunate to hold the lock for the entire bin just to get mutable access to one value.
We won't need to, since every item in the bin is itself a BinEntry
and the Mutating
still contains a Node
with a next
My second instinct is that it's not clear how we can ever give out
&mut V
, since reads never take the bin lock.
We can't, so we need to clone the contents into our WriteGuard
and give out a &mut
to that data.
Then, once we drop the guard, we write that data back into the map. (Mutating
only makes writers wait, but allows reader to read the data that was in the BinEntry::Node
)
This seems similar to the Entry API
I'll look into that
from flurry.
The WriteGuard would have to:
store the cloned Node / V, mutably (deref to it) and allow mutating it.
Currently V
does not require Clone
, only K
is Clone
. Would this be desirable? Part of the Entry
API I proposed included an and_modify
method which uses uses a Fn(&V) -> V
function to modify the data. I considered making it Fn(&mut V)
and cloning internally in the method, but it seemed better from a Rust perspective to avoid the additional trait bound and allow the consumer of the flurry hashmap to determine if it is appropriate to .clone()
or use other means to construct the new value when modifying.
from flurry.
Hmm, you're right, requiring V: Clone
seems unfortunate.
Maybe we can apply the idea I had of using the BinEntry
variant as a kind of lock to the entry API, so that it does not have to lock the whole bin...
from flurry.
Related Issues (20)
- `#![deny(unsafe_op_in_unsafe_fn)]`
- Fails to build on arm HOT 1
- Memory usage in Flurry Hashmap HOT 16
- Hashmap lacks of get_mut API HOT 1
- Bump ahash dependency version to 0.8.5 HOT 4
- Allow use of pre-hashed keys HOT 1
- Tedious map constructors HOT 2
- Expose non-replacing `insert` HOT 17
- Implement Drain and IntoIterator HOT 2
- Replacing map elements incorrectly decrements the map's element count HOT 2
- Implement `HashSet::replace` HOT 3
- Optimize garbage collection HOT 4
- Run cargo audit in CI? HOT 2
- Racy test failure: treeifying a Moved entry HOT 8
- Racy test failure: segfault in map::tree_bins::concurrent_tree_bin HOT 5
- map::tree_bins::concurrent_tree_bin: attempt to subtract with overflow HOT 5
- HashMap enters unreachable code in try_insert HOT 2
- Miri CI invocation needs updating HOT 3
- Use of deprecated `compare_and_swap` and `spin_loop_hint` HOT 1
- Unsoundness in `HashMap::clear` HOT 2
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 flurry.