wvwwvwwv / scalable-concurrent-containers

High performance containers and utilities for concurrent and asynchronous programming
Apache License 2.0
319 stars 16 forks source link

request: OccupiedEntry as reference #140

Closed gituser-rs closed 5 months ago

gituser-rs commented 5 months ago

Thanks for such a good project.

There is one thing that could make it better. Dashmap gives access to struct fields in the same way as references (through Ref struct).

Here is how it works in dashmap:

let client = clients.get(&ip_addr).ok_or(StatusCode::FORBIDDEN)?
client.fingerprint; 

Same but using scc:

let client = clients.get(&ip_addr).ok_or(StatusCode::FORBIDDEN)?
let client = client.get();
client.fingerprint;

It's not very convenient to use it like this. Would be nice to have the same usage as in dashmap

wvwwvwwv commented 5 months ago

I briefly looked into https://doc.rust-lang.org/std/collections/hash_map/struct.OccupiedEntry.html, and found that std didn't implement any deref* methods. Unlike dashmap, the entry API of SCC is almost identical to that of std, and I'm reluctant to add a Deref implementation to OccupiedEntry of scc::HashMap. Let me think about this and look into other crates for a couple of days, and get back to you.

gituser-rs commented 5 months ago

I briefly looked into https://doc.rust-lang.org/std/collections/hash_map/struct.OccupiedEntry.html, and found that std didn't implement any deref* methods. Unlike dashmap, the entry API of SCC is almost identical to that of std, and I'm reluctant to add a Deref implementation to OccupiedEntry of scc::HashMap. Let me think about this and look into other crates for a couple of days, and get back to you.

How about making it as an optional feature? std HashMap::get returns reference to value but SCC HashMap::get returns OccupiedEntry, so you need to call get() again.

wvwwvwwv commented 5 months ago

Hm... HashMap::get returning Option<V> justifies your request to some extent.

wvwwvwwv commented 5 months ago

OK, it looks to be reasonable to add a deref impl to OccupiedEntry. The PR will be approved after tests.