incremental iterative key scanning #37
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Inspired by the Redis SCAN command, this pull request introduces an incremental and iterative key scanning method for our map data structure. The goal is to allow for efficient iteration over the entire map without the need to maintain an open communication channel, enabling better handling of large datasets.
Changes Introduced
New Method:
Scan(cursor uint32, yield func(key K, value V) bool) (nextCursor uint32)cursor: A previously returned cursor from a call toScanor0to start from the beginning.yield: A function that processes each key-value pair. If it returnsfalse, the iteration stops.nextCursor: The cursor to use in the next call toScan.0indicates the iteration is complete.Implementation Details:
yieldfunction returnsfalse, allowing the implementation of a count limit similar to the Redis SCAN command.Example Usage
Here's an example demonstrating how to use the
Scanmethod to process keys in batches of 10:Motivation
The primary motivation behind this change is to provide a more flexible and scalable way to iterate over large maps. By implementing a SCAN-like method, we can handle partial iterations and avoid the overhead of maintaining a persistent connection. The iteration can be paused and resumed, making it easier to integrate with other processing workflows.