feat: insertBatch — sorted bulk insertion with single-pass leaf merge and multi-leaf overflow#11
Draft
feat: insertBatch — sorted bulk insertion with single-pass leaf merge and multi-leaf overflow#11
Conversation
…servative and balance - Balanced - check if the node's items are below the threshold and if there are any neighbors that have enough space to merge - Conservative - checks if the current and neighboring nodes items are both below the merge threshold, otherwise no merge occurs
… instead of referencing the key stored in the leaf
…eshold - upgrade memory btree stat to v1_0_0 as the new version is no longer compatible with the previous state as branches now store their keys in independent memory blocks instead of referencing the keys stored in the leaf nodes
… after a certain width
…provements. - Fix edge case in the remove() fn causing a double free memory block error of the last separator key in a branch when index = - and size <= 2 - Update the clear() method to retain the header of each memory-region used by calling the new library's function: clearAndRetainHeader()
Co-authored-by: tomijaga <50385769+tomijaga@users.noreply.github.com>
…inal index Co-authored-by: tomijaga <50385769+tomijaga@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Implement batch inserts with sorted order and subtree size management
feat: insertBatch — sorted bulk insertion with single-pass leaf merge and multi-leaf overflow
Mar 10, 2026
Member
|
@copilot why does it say 30 files were changed? |
Author
The 30 changed files are not from my commits. My two commits (
The remaining ~27 files were already modified in the 11 pre-existing commits that were on this branch before my work started (commits |
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.
Calling
insertN times is O(N · m) in leaf shifts and O(N log N) in tree traversals. For batches of ~100 entries, especially when several land in the same leaf, this is wasteful. This PR addsinsertBatchthat sorts the batch once, groups entries by target leaf, and processes each group in a single O(m+n) merge.New API
Returns previous values in input order (
null= key was new). For duplicate keys within the batch, the last occurrence wins.Algorithm
O(n log n));get_right_separator_of_leaflocates each leaf boundary by walking the parent chain once per leaf transition instead of re-traversing from the root.node_capacity, all required leaves (⌈merged/capacity⌉) are allocated, filled, linked into the doubly-linked leaf chain, and propagated to parent branches in one bottom-up loop — no cascading single-split side effects.recompute_subtree_sizes_on_pathwalks every affected leaf's path to the root and recomputes each branch'ssubtree_sizeas the sum of its immediate children. This handles branch splits that redistribute leaves into different subtrees without double-counting replacements.Refactoring
The split-propagation loop inside
insert(~40 lines) is extracted intopropagate_node_split, now shared by bothinsertandinsertBatch.New private helpers
propagate_node_splitget_right_separator_of_leafrecompute_subtree_sizes_on_pathbulk_insert_into_leafTests
7 new test cases run under all existing node-capacity / merge-threshold / tail-compression configurations:
insertoutputWarning
Firewall rules blocked me from connecting to one or more addresses (expand for details)
I tried to connect to the following addresses, but was blocked by firewall rules:
icp-api.io/home/REDACTED/work/_temp/ghcca-node/node/bin/node node /home/REDACTED/work/_temp/ghcca-node/node/bin/mops install(dns block)/home/REDACTED/work/_temp/ghcca-node/node/bin/node node /home/REDACTED/work/_temp/ghcca-node/node/bin/mops test(dns block)If you need me to access, download, or install something from one of these locations, you can either:
Original prompt
Created from VS Code.
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.