wvwwvwwv / scalable-concurrent-containers

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

Implement retain on HashIndex? #93

Closed novacrazy closed 1 year ago

novacrazy commented 1 year ago

Would it be possible to implement retain/retain_async on HashIndex?

Otherwise I'll have to use HashMap or iterate and create a list of keys to remove.

wvwwvwwv commented 1 year ago

Definitely possible. I'll implement them (+ any/any_async) next week.

In the meantime, you can try following if your code allows blocking code:

// No locks are acquired during iteration over entries, however `HashIndex` iterators cannot be sent across `awaits`.
hashindex.iter(&barrier).for_each(|(k, v)| {
    if !retain_cond(k, v) {
        // IT IS A BLOCKING METHOD; the corresponding bucket will be locked during entry removal.
        hashindex.remove(k);
        // Or, if you need to double-check the state the value with a lock acquired on the bucket,
        // hashindex.remove_if(k, |v| !retain_cond(k, v));
   }
}
wvwwvwwv commented 1 year ago

Well, easier than I thought, though some code is repeated here and there (need to refactor the code once async_fn_in_trait gets stabilized). I'll upload 1.6.2 in an hour.

novacrazy commented 1 year ago

Phenomenal response time! Hopefully I can get scc up and running in my server today.

wvwwvwwv commented 1 year ago

Done (v1.6.2)! Hope that the new methods work as expected.