scalable-concurrent-containers icon indicating copy to clipboard operation
scalable-concurrent-containers copied to clipboard

Feature request: remove_all() returning all items.

Open beckend opened this issue 1 year ago • 5 comments

Can this be added for all containers?

Remove all items from all containers, return them Option<Vec<V>> or Option<Vec<(K, V)>>.

Scanning and copy key to remove using 2 loops is pain.

beckend avatar Jul 16 '24 01:07 beckend

Papaya offers keys() and then loop all keys to remove items, still a pain: https://docs.rs/papaya/latest/papaya/struct.HashMap.html#method.keys

beckend avatar Jul 16 '24 01:07 beckend

I'm thinking of HashMap::remove_all() -> Self, and HashMap::into_iter(self) -> Into, so the usage would be like,

let vet: Vec<K, V> = hash_map.remove_all().into().collect();

Would that be OK? -> For HashIndex, iter().map(|(k, v)| (k.clone(), v.clone())).collect() would work.

wvwwvwwv avatar Jul 16 '24 05:07 wvwwvwwv

Hash cache also need some love.

beckend avatar Jul 16 '24 05:07 beckend

https://docs.rs/scc/latest/scc/hash_map/struct.HashMap.html#method.first_entry Would something like remove_first() be possible? This would be the the replacement for into_iter().

beckend avatar Jul 16 '24 09:07 beckend

remove_first can be done by first_entry().unwrap().remove_entry() -> (K, V), but the current problem is, once the entry has been removed, moving to the next entry is impossible - I'll also address this as well.

ghost avatar Jul 16 '24 09:07 ghost

Now, it is possible to consuming/removing/draining entries while iterating over entries synchronously/asynchrnously through the entry API.

E.g.,

let first_entry = map.begin_async().await; // Or, begin_sync();

let some_async_code = async {
    // Do something.
};
some_async_code.await;

// Note: first_entry is `Send` if `(K, V): Send`, so the code compiles.

let (removed, next_entry) = first_entry.remove_and_async().await; // Or, remove_and_sync();

wvwwvwwv avatar Sep 03 '25 19:09 wvwwvwwv