Fix wavelet tree get_segment crash for alphabet_size=1#60
Open
kilo-code-bot[bot] wants to merge 1 commit into
Open
Fix wavelet tree get_segment crash for alphabet_size=1#60kilo-code-bot[bot] wants to merge 1 commit into
kilo-code-bot[bot] wants to merge 1 commit into
Conversation
When alphabet_size == 1, the wavelet tree has no internal nodes (root_ == npos). The get_segment_impl method unconditionally called copy_segment_content(root_, ...) which accessed nodes_[npos], causing an out-of-bounds access since nodes_ is empty. rank_impl and select_impl already handled root_ == npos correctly (the traversal loop simply does not execute), but get_segment_impl had no guard for this degenerate case. Fix: add an early return in get_segment_impl when root_ == npos. In this case all symbols are identical, so the result is the single symbol (inverse_permutation_.front()) repeated (end - begin) times. Also add edge-case test coverage: - AlphabetSizeOne: rank, select, and get_segment for single-symbol alphabets (both Standard and Huffman builds) - AlphabetSizeZero: empty alphabet edge case - EmptyData: non-empty alphabet with no data - SymbolWithZeroOccurrences: symbols present in the alphabet but absent from the data - AllSameSymbolLargeAlphabet: one symbol repeated with a large alphabet where most symbols have zero occurrences
|
Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits. |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #60 +/- ##
==========================================
+ Coverage 90.10% 90.21% +0.11%
==========================================
Files 39 39
Lines 8735 8783 +48
Branches 1418 1433 +15
==========================================
+ Hits 7871 7924 +53
+ Misses 447 443 -4
+ Partials 417 416 -1
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Owner
|
This kind of things should probably be handled in constructor, the case of alphabet size 1 is indeed of no use |
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
Fixes a crash in
WaveletTreeIndex::get_segment_implwhenalphabet_size == 1(or any case whereroot_ == nposwithdata_size_ > 0).Related to #41 (Wavelet tree implementation with general rank/select).
Bug
When
alphabet_size == 1, the wavelet tree has no internal nodes (root_ == npos). Theget_segment_implmethod unconditionally calledcopy_segment_content(root_, ...), which accessednodes_[npos]— an out-of-bounds index sincenodes_is empty.rank_implandselect_implalready handledroot_ == nposcorrectly (the traversal loop simply does not execute), butget_segment_implhad no guard for this degenerate case.Fix
Add an early return in
get_segment_implwhenroot_ == npos. In this case all symbols are identical, so the result isinverse_permutation_.front()repeated(end - begin)times.Test coverage additions
Files changed
include/pixie/wavelet_tree/index.h: 5-line fix inget_segment_implsrc/tests/wavelet_tree_tests.cpp: 4 new test cases covering edge cases