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 resolves the behavioral inconsistency and benchmarking discrepancy between the C++ (Rust-compiled) backend and the pure Python fallback backend for sorted containers (stl_set and stl_map).
Problem
Previously, the Python implementations wrapped built-in set and dict objects. Because Python's built-ins are hash tables, they offered O(1) complexity and unordered iteration, whereas the Rust/C++ implementations used B-Trees with O(log n) complexity and sorted iteration. This resulted in behavioral inconsistencies (elements were sorted when Rust was compiled, but unsorted when it fell back to Python) and an unequal "apples-to-oranges" benchmark comparison.
Solution
AVL Tree Implementation: Created a core self-balancing AVL Tree in pure Python to serve as the fallback backend for both set and map containers.
Backend Unification: Modified the private set and map implementation wrappers to use this AVL tree, ensuring O(log n) time complexity and sorted iteration on both Rust and Python backends.
3-Way Benchmark: Expanded the benchmark script to support a three-way comparison (Rust Backend vs. Pure Python Backend vs. Native Python Built-ins) to clearly document FFI boundary crossing costs and algorithmic tradeoffs.
README FAQ: Updated the README to address common myths regarding project utility (competitive programming compatibility) and the systems design benefits of the hybrid Rust-Python architecture.
Version Bump: Bumped versioning to 1.1.7 across configuration files.
We reviewed changes in dfd1cb2...623d428 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.
Implementing __eq__ without also implementing __hash__
In order to conform to the object model, classes that define their own equality method should also define their own hash method, or be unhashable. If the hash method is not defined then the hash of the super class is used. This is unlikely to result in the expected behavior. A class can be made unhashable by setting its __hash__ attribute to None.
The reason will be displayed to describe this comment to others. Learn more.
Method doesn't use the class instance and could be converted into a static method
The method doesn't use its bound instance. Decorate this method with @staticmethod decorator, so that Python does not have to instantiate a bound method for every instance of this class thereby saving memory and computation. Read more about staticmethods here.
The reason will be displayed to describe this comment to others. Learn more.
Method doesn't use the class instance and could be converted into a static method
The method doesn't use its bound instance. Decorate this method with @staticmethod decorator, so that Python does not have to instantiate a bound method for every instance of this class thereby saving memory and computation. Read more about staticmethods here.
The reason will be displayed to describe this comment to others. Learn more.
`AVLTree._insert` has a cyclomatic complexity of 16 with "high" risk
A function with high cyclomatic complexity can be hard to understand and
maintain. Cyclomatic complexity is a software metric that measures the number of
independent paths through a function. A higher cyclomatic complexity indicates
that the function has more decision points and is more complex.
The reason will be displayed to describe this comment to others. Learn more.
Method doesn't use the class instance and could be converted into a static method
The method doesn't use its bound instance. Decorate this method with @staticmethod decorator, so that Python does not have to instantiate a bound method for every instance of this class thereby saving memory and computation. Read more about staticmethods here.
The reason will be displayed to describe this comment to others. Learn more.
Method doesn't use the class instance and could be converted into a static method
The method doesn't use its bound instance. Decorate this method with @staticmethod decorator, so that Python does not have to instantiate a bound method for every instance of this class thereby saving memory and computation. Read more about staticmethods here.
The reason will be displayed to describe this comment to others. Learn more.
Method doesn't use the class instance and could be converted into a static method
The method doesn't use its bound instance. Decorate this method with @staticmethod decorator, so that Python does not have to instantiate a bound method for every instance of this class thereby saving memory and computation. Read more about staticmethods here.
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
bugSomething isn't workingenhancementNew feature or request
1 participant
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.
Description
This PR resolves the behavioral inconsistency and benchmarking discrepancy between the C++ (Rust-compiled) backend and the pure Python fallback backend for sorted containers (
stl_setandstl_map).Problem
Previously, the Python implementations wrapped built-in
setanddictobjects. Because Python's built-ins are hash tables, they offered O(1) complexity and unordered iteration, whereas the Rust/C++ implementations used B-Trees with O(log n) complexity and sorted iteration. This resulted in behavioral inconsistencies (elements were sorted when Rust was compiled, but unsorted when it fell back to Python) and an unequal "apples-to-oranges" benchmark comparison.Solution
Changes
Verification