Add RangeScan() support #160
Merged
prologic
merged 7 commits from range_scan
into master
2 years ago
Loading…
Reference in new issue
There is no content yet.
Delete Branch 'range_scan'
Deleting a branch is permanent. It CANNOT be undone. Continue?
Are keys stored in an ordered way? This implementation requires iterating over every key and checking if it lies in some range. If there are lots of keys this becomes expensive.
In any case it seems like this function is only useful for situations where keys are intrinsically ordered and have some kind of "meaning"? I may be wrong. What do you imagine the use-case to be?
The underlying trie is ordered AFAIK - yes. So does your comment still apply re the "expensve" Maybe this is better moved to a fork of go-adaptive-radix-tree?
@prologic Maybe it's possible to range over only those keys within the specified range? Since they are ordered.
I think it is; but not with the current API adaptive-radix-tree exports. As I said we would have to fork it and add the funcitonlity there. I'll look into doing that; but it may take some time :)
This Pull Request has gone stale and will be closed automatically.
If this is incorrect, please reopen and add the label
on hold
.Thank you.
Any reason to not have the
f func(key []byte)
consume a value?f func(key, value []byte)
Range can provide better performance when trying to capture many keys. It should be up to the user to decide which is better in their case.
Search for multiple keys:
Range = O(n)
Has/Get = O(k * log n) where k is the number of operations
throw error if end < start
Would be nice if we could avoid iterating the trie when our range exceeds the bounds. The trie API only offers a minimum/maximum for the value and not the key (in constant time) .
for example
(Very easy to make this change however)
Done
I'm not sure what's up with my test for this :/
I can see the usefulness of this. I'll take a look.
This PR is now ready too!
if commonPrefix == nil {
return ErrInvalidRange
}
Can we grab + defer() the RLock() here?
Ahh yes of course! Forgot about that ;)
}
b.trie.ForEachPrefix(commonPrefix, func(node art.Node) bool {
if bytes.Compare(node.Key(), start) >= 0 && bytes.Compare(node.Key(), end) <= 0 {
This might be a place where we can get some extra efficiency by skipping the tail end of the tries.
Something like:
Ahh yes brilliant!
Whoops, updated the snippet above. Don't use it as it was a minute ago. My bad.
All good! Should be right now :)
Hmm, I'm not seeing it updated.
Hang on... I'm slow ;)
d1f070b9e0
to0994438dc8
2 years agoLGTM
Wanna approve it? :D
Actually I have one update to this. I want to add a SiftRange(). Almost done.
Do it as a separate PR so you retain authorship :D
Approve and I'll merge this one!
Oh, whoops. I pushed to the wrong remote :|
It's a totally different feature though, so it can be in a different commit.
LGTM
I can't formally approve, I don't have permission (I don't think)
Pretty sure I gave you access to review/approve hmmm 🤔
9b0daa8a30
into master 2 years agoReviewers
9b0daa8a30
.