Skip to content

feat(data-structures/unstable): add BinarySearchTree methods ceiling, floor, higher, lower #6544

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

Merged
merged 6 commits into from
Apr 30, 2025

Conversation

WWRS
Copy link
Contributor

@WWRS WWRS commented Mar 31, 2025

closes #3069

May break custom binary trees that reimplement BinarySearchTree.#findNode(). I think it's unlikely that anyone is doing that given that #findNode() should work on all child data structures of binary search trees. As pointed out, this is not a problem.

The new methods have the same time complexity as find().

@WWRS WWRS requested a review from kt3k as a code owner March 31, 2025 17:04
Copy link

codecov bot commented Mar 31, 2025

Codecov Report

Attention: Patch coverage is 98.78049% with 1 line in your changes missing coverage. Please review.

Project coverage is 94.74%. Comparing base (096f0be) to head (1271a7a).
Report is 3 commits behind head on main.

Files with missing lines Patch % Lines
data_structures/unstable_binary_search_tree.ts 98.78% 1 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main    #6544   +/-   ##
=======================================
  Coverage   94.74%   94.74%           
=======================================
  Files         583      584    +1     
  Lines       46478    46560   +82     
  Branches     6523     6539   +16     
=======================================
+ Hits        44036    44114   +78     
- Misses       2399     2402    +3     
- Partials       43       44    +1     

☔ View full report in Codecov by Sentry.
📢 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.

@lionel-rowe
Copy link
Contributor

May break custom binary trees that reimplement BinarySearchTree.#findNode()

It's not possible to reimplement #private methods in derived classes. Implementing a method with the same name in the derived class creates a new method that's only accessible within the derived class, rather than overriding the method in the parent.

class A {
    #private() {
        return 'A'
    }

    foo() {
        console.log(this.#private())
    }
}

class B extends A {
    #private() {
        return 'B'
    }

    bar() {
        console.log(this.#private())
    }
}

new A().foo() // logs 'A'
new B().foo() // still logs 'A'
new B().bar() // logs 'B'

@WWRS
Copy link
Contributor Author

WWRS commented Apr 1, 2025

Ah, I see where I got confused. There's a change to an export in _binary_search_tree_internals and that gets used by RedBlackTree. I thought this meant RedBlackTree used some sort of extension of internals, but that's just exported to allow RedBlackTree access to those private methods. So the type change cannot cause any problems.

@kt3k
Copy link
Member

kt3k commented Apr 30, 2025

@WWRS Sorry for the delay in review.

BinarySearchTree is part of stable API and we prefer to not mix stable features and unstable features.

Can you create an unstable version of BinarySearchTree in unstable_binary_search_tree.ts (probably by subclassing the stable one) and move the new methods there? (and also can you move the test cases of them in unstable_binary_search_tree_test.ts?)

@WWRS
Copy link
Contributor Author

WWRS commented Apr 30, 2025

@kt3k Moved to unstable_binary_search_tree.ts 👍

@kt3k kt3k changed the title feat(data-structures): add BinarySearchTree methods ceiling, floor, higher, lower feat(data-structures/unstable): add BinarySearchTree methods ceiling, floor, higher, lower Apr 30, 2025
Copy link
Member

@kt3k kt3k left a comment

Choose a reason for hiding this comment

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

Thanks for updating!

LGTM

@kt3k kt3k merged commit 5ae11c2 into denoland:main Apr 30, 2025
19 checks passed
@WWRS WWRS deleted the bst-ceil branch April 30, 2025 14:10
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.

add method "higher" "lower" "floor" "ceiling" to BinarySearchTree
3 participants