Skip to content

Conversation

@taylorsw04
Copy link
Collaborator

@taylorsw04 taylorsw04 commented Nov 14, 2025

This PR adds advanced set operations to the extended/ library:

  • Union (merge two trees)
  • Intersect (keys present in both trees)
  • Subtract (keys in a tree that are not present in another tree)
    Note: symmetric difference (merge minus intersection) can be computed via union + combineFn that excludes all shared keys.

Each of the above methods returns a new tree. To avoid the allocation overhead (e.g. if the result is only to be enumerated), iteration/callback flavors of each have been added (intersect -> forEachKeyInBoth, subtract -> forEachKeyNotIn).

Finally, a bulk loading algorithm has been exposed allowing consumers to build a BTree from a sorted list of entries in O(N) time.

All of the above has been added to BTreeEx as well as exposed via standalone methods for optimal tree-shaking.

Size report:

Entry Raw Size Minified Gzipped
btree 71.43 KB 19.49 KB 5.50 KB
extended/bulkLoad 4.96 KB 1.95 KB 932 B
extended/decompose 34.15 KB 8.01 KB 2.80 KB
extended/diffAgainst 12.75 KB 2.47 KB 1.05 KB
extended/forEachKeyInBoth 3.59 KB 1.09 KB 455 B
extended/forEachKeyNotIn 4.25 KB 1.23 KB 484 B
extended/index 11.02 KB 2.78 KB 987 B
extended/intersect 2.06 KB 732 B 403 B
extended/parallelWalk 6.59 KB 1.92 KB 935 B
extended/shared 4.28 KB 1.60 KB 606 B
extended/subtract 2.14 KB 532 B 328 B
extended/union 1.92 KB 472 B 294 B
BTreeEx total 87.71 KB 22.75 KB 9.15 KB

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant