Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tree: Refactor RangeMap to use a B-tree #23497

Merged
merged 5 commits into from
Jan 9, 2025

Conversation

alex-pardes
Copy link
Contributor

Description

Reimplemented RangeMap to store entries in a B-tree instead of an array to improve asymptotic performance.

@github-actions github-actions bot added base: main PRs targeted against main branch area: dds Issues related to distributed data structures area: dds: tree labels Jan 8, 2025
Comment on lines 20 to 21
* Retrieves all entries from the rangeMap.
* @returns An array of RangeEntryResult objects, each containing the start index, length, and value of a contiguous range.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* Retrieves all entries from the rangeMap.
* @returns An array of RangeEntryResult objects, each containing the start index, length, and value of a contiguous range.
* Retrieves all entries from the rangeMap.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't think that the @return comment had a lot of value: it't not saying anything that the signature doesn't convey.

@@ -147,73 +105,66 @@ export class RangeMap<T> {
* @param length - The length of the range to delete.
*/
public delete(start: number, length: number): void {
Copy link
Contributor

@yann-achard-MS yann-achard-MS Jan 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking at the code in get and delete, I wonder if there's some intermediate interface that is begging to be born.
This might be something like getInternalEntries(start: number, length: number): Iterable<[number, RangeEntry<T>]> where the first element of the iterator may represent a range that starts before start and the last element of the iterator may represent a range that ends after start + length.
Such a function would in part be based on the BTree's getRange function.
The implementation for get would only read the first entry from the iterable and return a potentially truncated version of it.
The implementation for delete would read all entries, splitting the first and last if needed. (Splitting might be another internal helper that makes sense)

I'm happy to chat about this. I don't take it for granted that the motivation for this is high especially now that you've written this code.
I do wonder whether it would then enable us to expose a variant of get that returns all relevant entries for a range (with an implementation that is faster than repeatedly calling the current get).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree about making a variant that returns all entries and was planning to do that soon. I'll try refactoring the implementation as suggested.

@alex-pardes alex-pardes marked this pull request as ready for review January 8, 2025 23:03
@alex-pardes alex-pardes requested a review from a team as a code owner January 8, 2025 23:03
@alex-pardes alex-pardes enabled auto-merge (squash) January 8, 2025 23:03
@alex-pardes alex-pardes disabled auto-merge January 8, 2025 23:18
@alex-pardes alex-pardes enabled auto-merge (squash) January 8, 2025 23:19
@alex-pardes alex-pardes merged commit a9232b2 into microsoft:main Jan 9, 2025
26 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: dds: tree area: dds Issues related to distributed data structures base: main PRs targeted against main branch
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants