Repository navigation
Conversation
This branch has not been deployed
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Describe your change
data_structures/trie/radix_tree.py::RadixNode.deletemerges a node with its only child once the node has lost all but one edge and is not a word itself. The same code also runs whenselfis the tree root (empty prefix), so deleting a word from a tree whose root then has one edge folds that edge into the root: the root gets the child's prefix andfindcan no longer reach it. Reproducer onmaster:insert_many(["c", "abcd"]),delete("c")returnsTrue, thenfind("abcd")isFalse. The merge now only applies to nodes that have a prefix, which excludes the root.I added a doctest with that sequence to
delete; it fails onmaster, and I kept it in this PR as the regression evidence for this one-condition fix. I also ran 1500 random insert, delete and find sequences over ten short words against a Python set, checking every word after each operation: with the change there are no mismatches over three seeds, and onmasterseed 1 produced 206 wrongfindresults. The existing tests in the file still pass.ruff check,ruff format --checkandpython -m doctestpass.This is unrelated to #15673 (empty-string handling in
findanddelete); the two touch neighbouring lines ofdelete, so whichever lands second may need a trivial rebase.Written with the help of Claude Code (Claude Sonnet 5.5).
Checklist