quality audit: fix dsu_weighted precision loss; doc typo#227
Merged
Conversation
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.
Full audit of every
.hppunderlibrary/(144 files), prioritizing correctness > efficiency > readability. Every candidate finding was verified with a compiled repro before being accepted or rejected. The result is deliberately small: only two changes survived triage.Changes
1.
dsu/dsu_weighted.hpp— correctness: sentinel round-trips throughdouble1e18is adouble, so the ternary's common type isdouble— meaning thed[v] - d[u]branch (the real answer, not just the sentinel) is convertedll → double → ll. Any difference with|w| > 2^53silently loses precision.Compiled repro (weight
2^53 + 1 = 9007199254740993):Tests compare against
ll(1e18), whose value is unchanged (10^18 is exactly representable), sodsu_weighted_lib_checker/dsu_weighted_aizubehavior is identical for the sentinel path.2.
data_structures_[l,r)/uncommon/deque_op.hpp— doc typoammortized→amortized. Comment-only.Findings investigated and rejected (with verification)
Six parallel reviewers flagged ~20 candidates; each was checked against the actual code/semantics. Notable false positives, so they don't get re-reported later:
implicit.hpp"UB on leaf nodes" —pushon a leaf can't reach theapply(lazy, lch)path: a leaf is only ever fully covered or disjoint, solazyis consumed by the full-coverapplyand children are never touched.distinct_query.hpp"inverted query" —pst.query(0, l+1, r) - pst.query(0, l+1, l)is the standard persistent-tree distinct count (versions indexed by right endpoint); verified against the Library Checker test.longest_palindrome_query.hpp"RMQ bounds violation at x = r-l-1" — substituting x givesquery(l+r-1, l+r), which satisfiesl < r. The reviewer's algebra was off by one.binary_search.hpp"UB dereferencing end()" —*end()of aniota_viewis well-defined (returns the bound); the doc comment explicitly documents returninghiwhen no element qualifies.gcd/lcm_convolution"signed underflow UB" — values are in[0, mod); worst case0 - (mod-1)is far fromINT_MIN.(x -= y) < 0 ? x += modis well-defined and is the codebase-standard reduction.count_paths_triangle.hpp"syntax errorvl(mid + all(bottom))" —all(x)expands tobegin(x), end(x), so this isvl(mid + begin(bottom), end(bottom)): valid, and it compiles in CI today.lcs_dp.hpp"storeconst T&instead of copyingt" — rejected as a lifetime trap:lcs_dp lcs(t)inlcs_querieswould be fine today, but the copy is O(m) once vs an O(n·m) algorithm, and a dangling-reference footgun isn't worth it in a hackpack.pass-by-valueparams (bit_rurq,bit_rupq,wavelet_matrix,compress_tree,xor_conv,get_right_and_top) — all intentional: each function mutates its copy in place (adjacent_differencein-place,fwhtin-place, sort+dedup,swap(left, bottom)).solve_linear_mod"silent failure on inconsistent system" —solstaying empty is the documented no-solution signal; the test checksempty(info.sol).mod"link-time conflicts" — headers are single-TU by construction (hackpack), non-issue.Validation
g++ -std=c++20 -O2 -Wall -Wextraandclang++compile all 6 affected test files (2 dsu_weighted, 4 deque) cleanlytests/scripts/grep_clangformat_cppcheck.shpasses (clang-format + cppcheck, no new suppressions)