Background
In FFF 2.0 the strategies all accept an order::Base.Order.Ordering keyword, but
several of them only have a fast path for Base.Order.Forward. When a caller
passes Base.Order.Reverse (or any non-Forward ordering), these strategies
fall back to BinaryBracket() — which is correct but throws away the
hint-based speedup the caller was expecting.
Specifically:
InterpolationSearch falls back to BinaryBracket for non-Forward
orderings. The linear-extrapolation guess is direction-aware in principle
but currently only implemented for the forward polarity.
ExpFromLeft falls back to Base.searchsorted{first,last} (bounded
binary) for non-Forward orderings — same direction-aware reasoning.
SIMDLinearScan falls back to scalar LinearScan for non-Forward
orderings. The LLVM IR is hardcoded to the forward comparison polarity
(icmp sgt / fcmp ogt / etc.).
BitInterpolationSearch falls back to BinaryBracket for non-Forward
orderings.
BracketGallop, LinearScan, and the various BinaryBracket paths already
work natively under any ordering — they pass order through to
Base.Order.lt for every compare.
What would change
For each affected strategy, add a backward-direction implementation that
mirrors the forward one with the comparison polarity flipped. The
algorithm doesn't change — only the comparison.
For SIMDLinearScan specifically, this would mean two more IR templates
(icmp slt/sle for Int64, fcmp olt/ole for Float64) generated by the
existing _simd_scan_ir(t, pred) helper. The dispatch would branch on
order === Forward vs order === Reverse (with Reverse going through the
new IR).
For InterpolationSearch / ExpFromLeft / BitInterpolationSearch, the
guess-and-refine arithmetic flips sign in the right places — short patches
per strategy, ~20-30 lines each.
Why not in 2.0
Reverse-ordering workflows are niche (Base.Order.Reverse is rarely the right
shape for sorted-search workloads — most callers reverse the vector itself
instead). The current fallback paths are correct, just slower than necessary.
Filing this as a 2.x followup rather than blocking the 2.0 release.
Acceptance
For each affected strategy:
Bonus:
Background
In FFF 2.0 the strategies all accept an
order::Base.Order.Orderingkeyword, butseveral of them only have a fast path for
Base.Order.Forward. When a callerpasses
Base.Order.Reverse(or any non-Forwardordering), these strategiesfall back to
BinaryBracket()— which is correct but throws away thehint-based speedup the caller was expecting.
Specifically:
InterpolationSearchfalls back toBinaryBracketfor non-Forwardorderings. The linear-extrapolation guess is direction-aware in principle
but currently only implemented for the forward polarity.
ExpFromLeftfalls back toBase.searchsorted{first,last}(boundedbinary) for non-Forward orderings — same direction-aware reasoning.
SIMDLinearScanfalls back to scalarLinearScanfor non-Forwardorderings. The LLVM IR is hardcoded to the forward comparison polarity
(
icmp sgt/fcmp ogt/ etc.).BitInterpolationSearchfalls back toBinaryBracketfor non-Forwardorderings.
BracketGallop,LinearScan, and the variousBinaryBracketpaths alreadywork natively under any ordering — they pass
orderthrough toBase.Order.ltfor every compare.What would change
For each affected strategy, add a backward-direction implementation that
mirrors the forward one with the comparison polarity flipped. The
algorithm doesn't change — only the comparison.
For
SIMDLinearScanspecifically, this would mean two more IR templates(
icmp slt/slefor Int64,fcmp olt/olefor Float64) generated by theexisting
_simd_scan_ir(t, pred)helper. The dispatch would branch onorder === Forwardvsorder === Reverse(withReversegoing through thenew IR).
For
InterpolationSearch/ExpFromLeft/BitInterpolationSearch, theguess-and-refine arithmetic flips sign in the right places — short patches
per strategy, ~20-30 lines each.
Why not in 2.0
Reverse-ordering workflows are niche (Base.Order.Reverse is rarely the right
shape for sorted-search workloads — most callers reverse the vector itself
instead). The current fallback paths are correct, just slower than necessary.
Filing this as a 2.x followup rather than blocking the 2.0 release.
Acceptance
For each affected strategy:
Base.searchsorted{first,last}underReverseordering across the same fuzz harness used for the forward path
Bonus:
Reverseto any user-suppliedBase.Order.Orderingwhose
ltfunction can be flipped. (CurrentlyReverseis the onlynon-
Forwardordering with a well-defined inverse comparison.)