MCPcopy Index your code
hub / github.com/TanStack/db / tryMerge

Method tryMerge

packages/db/src/utils/btree.ts:958–973  ·  view source on GitHub ↗

Merges child i with child i+1 if their combined size is not too large

(i: index, maxSize: number)

Source from the content-addressed store, hash-verified

956
957 /** Merges child i with child i+1 if their combined size is not too large */
958 tryMerge(i: index, maxSize: number): boolean {
959 const children = this.children
960 if (i >= 0 && i + 1 < children.length) {
961 if (children[i]!.keys.length + children[i + 1]!.keys.length <= maxSize) {
962 if (children[i]!.isShared)
963 // cloned already UNLESS i is outside scan range
964 children[i] = children[i]!.clone()
965 children[i]!.mergeSibling(children[i + 1]!, maxSize)
966 children.splice(i + 1, 1)
967 this.keys.splice(i + 1, 1)
968 this.keys[i] = children[i]!.maxKey()!
969 return true
970 }
971 }
972 return false
973 }
974
975 /**
976 * Move children from `rhs` into this.

Callers 2

forRangeMethod · 0.95
mergeSiblingMethod · 0.95

Calls 3

cloneMethod · 0.80
mergeSiblingMethod · 0.45
maxKeyMethod · 0.45

Tested by

no test coverage detected