Skip to content

fix: handle empty and constant interpolation ranges - #3260

Open
devam007 wants to merge 1 commit into
TheAlgorithms:masterfrom
devam007:codex/interpolation-boundary-inputs
Open

devam007 wants to merge 1 commit into
TheAlgorithms:masterfrom
devam007:codex/interpolation-boundary-inputs

Conversation

@devam007

Copy link
Copy Markdown

Description of Change

Guard empty vectors before constructing the unsigned high index. Handle equal
endpoint values before calculating an interpolation denominator: [7,7,7] with
target 7 previously divided by zero. Preserve the existing return type and
not-found sentinel, and add assertions for empty, singleton and constant inputs.

Validation

GCC 15.2 / C++17: 14,761 reference comparisons pass against std::binary_search
on sorted inputs with duplicates. Found indices are checked to contain the
target without imposing an undocumented first-occurrence requirement. The
constant-input reproduction fails on the base. Warning-enabled compilation with
libstdc++ assertions, the CMake/Ninja target, source assertions and whitespace
checks pass. Remote CI, clang-format and clang-tidy were not run locally.

  • Read contribution guidelines and kept the change to one algorithm file
  • Added regression assertions and preserved the existing example
  • Kept the sorted-input precondition and return contract unchanged

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant