wvwwvwwv / scalable-concurrent-containers

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

Feature request: remove_all() returning all items. #151

Open beckend opened 3 months ago

beckend commented 3 months ago

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 commented 3 months ago

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

wvwwvwwv commented 3 months ago

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.

beckend commented 3 months ago

Hash cache also need some love.

beckend commented 3 months ago

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().

changgyoopark-db commented 3 months ago

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.