items(): support iterating over a key-prefix partition - #50
Merged
Conversation
Add optional prefix_bits / prefix arguments to HashTable.items() and HashTableNT.items() to iterate only over the items whose key starts with the given bit prefix (first 4 key bytes interpreted big-endian, like _get_index does, so a partition is a contiguous range of the sorted key space). Non-matching entries are skipped at C level without creating Python objects for them, so scanning the table once per partition is cheap. As the keys are random bytes, this partitions the items into 2 ** prefix_bits roughly equally sized, disjoint sets, e.g. to process a huge hash table in batches with a small memory footprint (see borgbackup/borg#9886). Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Fixes #49.
Add optional
prefix_bits/prefixarguments toHashTable.items()andHashTableNT.items()to iterate only over the items whose key starts with the given bit prefix._get_indexalready does), so each partition is a contiguous range of the sorted key space.prefix_bits=0is the default (no filtering), so existing callers are unaffected.As the keys are random bytes, this partitions the items into
2 ** prefix_bitsroughly equally sized, disjoint sets, e.g. to process a huge hash table in batches with a small memory footprint — needed for borgbackup/borg#9886 (bounded-memorywrite_chunkindex_to_repo).🤖 Generated with Claude Code