estokes / immutable-chunkmap

Fast cache efficient immutable map for rust
Apache License 2.0
25 stars 8 forks source link

Add a way to remove multiple keys at once #3

Closed kskalski closed 1 year ago

kskalski commented 1 year ago

Following the availability of insert/update many it would be nice to also have something like remove_many. Alternatively (or also) retain function (like in btree map) could be added to support such (and other) use-cases, though that one traverses the whole tree, so it could be too costly if removed set of keys is much smaller than overall keys in the tree.

In my specific use-case I actually need to remove a range of keys, which I imagine might have a fast specialized implementation possible, but I suppose this could as well be a specific scenario possible to exploit in remove_many (as docs mention insert_many being faster on sorted entries).

And thanks for this lib, it looks pretty solid and performs very well!

estokes commented 1 year ago

You can do that with update_many, just give it a function that always returns None

You can also implement retain with update_many, just pass the map itself as the elts and you'll visit every key in the map and have the option to remove it.

I'll consider adding convenience functions.

kskalski commented 1 year ago

Thanks, this seems to work, except for the bug (https://github.com/estokes/immutable-chunkmap/issues/4) that I stumbled upon

estokes commented 1 year ago

remove_many added as a wrapper around update_many in 1.0.5