Repository navigation
fix: only treat a radix node that holds a value as a duplicate (closes #36) - #37
Merged
danielhuici merged 2 commits intoSep 1, 2026
Merged
Conversation
Author
|
Heads up: this PR will conflict with #27, same block in |
3 tasks done
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.
Summary
insert()decided whether a key was already present by checking only thatRadixNode::find()returned a node.find()also returns internal nodes that hold no value: splitting the tree on a shared prefix moves the existing value down into a child and leaves the parent as a branch point withdata: None. A record whose key matched one of those split points was reported as an existing key and silently discarded, even though nothing had ever been stored there.search()already got this right, checkingif let Some(Some(node_index)) = radix_node.data. Onlyinsert()conflated "a node exists at this path" with "a record is stored at this path".This affects variable-length keys, so the shipped
RadixKeyMapping for u32(integers encoded as decimal text) is vulnerable. TLSH keys are all the same length and an internal node path is always strictly shorter than a complete key, so the TLSH path was never affected.Changes
src/controllers/apotheosis.rs: the duplicate check becomesself.radix.find(key).is_some_and(|node| node.data.is_some()), so only a node actually holding an index counts as a duplicate. One line plus a comment explaining why the node alone is not enough.Test plan
Verified locally with the same commands CI runs:
cargo clippy --all-targets --all-features -- -D warningsclean,cargo fmt --checkclean, and all 44 tests passing.Beyond that, the behavior was exercised before and after the change with the scenarios recorded in #36: the
RadixNode-level mechanism, the minimal 12/13/1 case, insertion-order dependence, genuine duplicates, the TLSH path, and a 20,000-insert workload.Before the fix, 588 of 18175 unique records were dropped (3.24%), with the accounting closing exactly at 17587 indexed plus 588 falsely rejected. After the fix, all 18175 unique records are indexed and none are falsely rejected, while the same 1825 genuine duplicates are still rejected and 12/13/1 yields 3 records in either insertion order.