Skip to content

fix(data-structures): support array-like inputs in BinarySearchTree.from() and RedBlackTree.from() - #7314

Open
tomas-zijdemans wants to merge 2 commits into
denoland:mainfrom
tomas-zijdemans:fix-red-black-tree-array-like
Open

fix(data-structures): support array-like inputs in BinarySearchTree.from() and RedBlackTree.from()#7314
tomas-zijdemans wants to merge 2 commits into
denoland:mainfrom
tomas-zijdemans:fix-red-black-tree-array-like

Conversation

@tomas-zijdemans

@tomas-zijdemans tomas-zijdemans commented Sep 8, 2026

Copy link
Copy Markdown
Contributor

Fix BinarySearchTree.from() and RedBlackTree.from() for array-like objects without a mapping function. Both accept ArrayLike<T> per their signatures, yet RedBlackTree.from({ 0: 42, length: 1 }) threw TypeError: values is not iterable. Same bug in both classes, since RedBlackTree overrides from() with a copy of the parent's logic.

Convert unmapped inputs with Array.from() before insertion. Three regression tests per class cover empty inputs, sorting and deduplication, and a custom comparator. All six previously failed.

Validation:

  • env -u NO_COLOR deno task ok on Deno 2.9.6: lint, formatting, browser compatibility, and all tests pass.
  • Type-checked and ran the four touched files on Deno 1.46.3 as well. CI's v1.x matrix rejected the earlier as ArrayLike<U> | Iterable<U> cast, so the fix now uses the as unknown as idiom already used elsewhere in these files.

@codecov

codecov Bot commented Sep 8, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 95.03%. Comparing base (ca58f94) to head (6c5286a).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #7314   +/-   ##
=======================================
  Coverage   95.03%   95.03%           
=======================================
  Files         617      617           
  Lines       51637    51637           
  Branches     9359     9359           
=======================================
  Hits        49075    49075           
  Misses       2021     2021           
  Partials      541      541           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@tomas-zijdemans tomas-zijdemans changed the title fix(data-structures): support array-like inputs in RedBlackTree.from() fix(data-structures): support array-like inputs in BinarySearchTree.from() and RedBlackTree.from() Sep 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant