You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This PR implements and integrates the C++ STL Algorithms Suite and the Binary Search Suite into PythonSTL. It exposes high-performance Rust-compiled backends using PyO3/Maturin and registers them as part of the public facade API, while introducing robust, optimized pure-Python fallback implementations.
nth_element: Quickselect implementation to find elements at a sorted index in $O(N)$ expected time.
partition: In-place array partitioning based on custom Python predicates.
Binary Search Suite
lower_bound: First element index not comparing less than target ($\ge$).
upper_bound: First element index comparing greater than target ($>$).
binary_search: $O(\log N)$ presence check in a sorted range.
equal_range: Returns (lower_bound, upper_bound) index bounds.
Performance Benchmarks & Systems Insights
Algorithms Benchmark Results
next_permutation: Achieved a 1.7x speedup over pure Python.
nth_element: Bypassed a severe Lomuto partition worst-case vulnerability ($O(N^2)$ taking 70.85s on reversed arrays) by introducing middle-pivot selection, reducing the runtime to 0.0028s (a 25,000x+ speedup).
partition: Shows 1.3x speedup; performance is dominated by FFI callback transitions to evaluate the Python predicate function.
Binary Search Benchmark Results (5,000 queries on 1,000,000 elements)
Standard (< comparison): 7.5x speedup (0.0028s vs 0.0214s).
Custom Comparator (lambda): 3.4x speedup (0.0074s vs 0.0251s).
Key Systems Design Decisions:
GIL-Bound Indexing Optimization: Rust implementations for binary search access elements directly using arr.get_item(mid) rather than copy-extracting the entire list. This preserves the $O(\log N)$ time and $O(1)$ space constraints.
FFI Callback vs. Compiled Loop Overhead: Custom lambdas require crossing the Python-Rust FFI boundary to evaluate comparison predicates. While this slows Rust down (from 0.0028s to 0.0074s), Rust's loop compiling easily overcomes Python's bytecode interpreter overhead, resulting in a 3.4x net speedup.
Verifications & Quality Gates
Unit Tests: Created comprehensive pytest suites in tests/test_algorithms.py and tests/test_binary_search.py covering duplicate elements, out-of-bounds inputs, empty lists, and custom comparators. All 81 package tests are passing.
Packaging: Configured and validated package distributions on PyPI (Twine validation: PASSED). Version 1.1.4 is live on PyPI.
We reviewed changes in 2bd671c...263431f on this pull request. Below is the summary for the review, and you can see the individual issues we found as inline review comments.
AI Review is run only on demand for your team. We're only showing results of static analysis review right now. To trigger AI Review, comment @deepsourcebot review on this thread.
The reason will be displayed to describe this comment to others. Learn more.
Starting a process with a partial executable path
Python possesses many mechanisms to invoke an external executable. If the desired executable path is not fully qualified relative to the filesystem root then this may present a potential security risk.
The reason will be displayed to describe this comment to others. Learn more.
Starting a process with a partial executable path
Python possesses many mechanisms to invoke an external executable. If the desired executable path is not fully qualified relative to the filesystem root then this may present a potential security risk.
The reason will be displayed to describe this comment to others. Learn more.
Access to a protected member _data of a client class
Accessing a protected member (a member prefixed with _) of a class from outside that class is not recommended, since the creator of that class did not intend this member to be exposed. If accesing this attribute outside of the class is absolutely needed, refactor it such that it becomes part of the public interface of the class.
The reason will be displayed to describe this comment to others. Learn more.
Access to a protected member _data of a client class
Accessing a protected member (a member prefixed with _) of a class from outside that class is not recommended, since the creator of that class did not intend this member to be exposed. If accesing this attribute outside of the class is absolutely needed, refactor it such that it becomes part of the public interface of the class.
The reason will be displayed to describe this comment to others. Learn more.
Access to a protected member _capacity of a client class
Accessing a protected member (a member prefixed with _) of a class from outside that class is not recommended, since the creator of that class did not intend this member to be exposed. If accesing this attribute outside of the class is absolutely needed, refactor it such that it becomes part of the public interface of the class.
The reason will be displayed to describe this comment to others. Learn more.
Access to a protected member _capacity of a client class
Accessing a protected member (a member prefixed with _) of a class from outside that class is not recommended, since the creator of that class did not intend this member to be exposed. If accesing this attribute outside of the class is absolutely needed, refactor it such that it becomes part of the public interface of the class.
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
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.
This PR implements and integrates the C++ STL Algorithms Suite and the Binary Search Suite into PythonSTL. It exposes high-performance Rust-compiled backends using PyO3/Maturin and registers them as part of the public facade API, while introducing robust, optimized pure-Python fallback implementations.
Key Features Added
Performance Benchmarks & Systems Insights
Verifications & Quality Gates