plar / go-adaptive-radix-tree

Adaptive Radix Trees implemented in Go

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Support for deletion of node inside of ForEach

taigrr opened this issue · comments

Hello,

I've been working with @prologic to try to bring bitcask up to version 1.0.

One of the things we've been struggling with is allowing a user to iterate over all keys in the tree and allow deletion by value, rather than by key (i.e. delete a key from within the ForEach callback function). The current implementation causes the ForEach to skip a node that would have been iterated over at some point after the deleted node (sometimes the next node, sometimes the one after that, etc.)

Would you consider letting us modify the iterator to pull the "next" value before the callback so that no nodes get skipped? Or would this be better done in a fork?

Sorry if my ask here is not clear, let me know if you need any further clarification.

Will that work for you?

  1. Сollect the keys to be deleted into a temporary slice (filter by value)
  2. Delete all the keys.

Will that work for you?

  1. Сollect the keys to be deleted into a temporary slice (filter by value)
  2. Delete all the keys.

Yeah we could do that; something like this:

https://git.mills.io/prologic/bitcask/pulls/229#issuecomment-5058

keysToDelete can be potentially pretty huge if there are a lot of repeated values in the tree. (Use a new temp art.Tree instead of slice? :))

To avoid memory allocation in case if you don't have any matched values you can define
keysToDelete := [][]byte{}
as
var keysToDelete [][]byte and append will allocate a new slice automatically.

keysToDelete can be potentially pretty huge if there are a lot of repeated values in the tree. (Use a new temp art.Tree instead of slice? :))

This is why we used an ART in the first place! 🤣

thanks, @plar.

Just wanted to bring this back up, would it be possible to support calling Delete() within ForEach() without requiring an additional slice/tree to keep track of entries to be deleted?