This repository was archived by the owner on Sep 24, 2026. It is now read-only.
Honest partial-order support + explicit empty ranges - #10
Merged
Merged
Conversation
adriendellagaspera
force-pushed
the
partial-rcmp
branch
2 times, most recently
from
November 8, 2023 12:56
f9d5c9f to
bd07b70
Compare
The crate previously returned an arbitrary, representation-dependent answer for empty ranges, and PR10's `partial_rcmp -> Option<RangeOrdering>` collapsed a poset position into a single ambiguous verdict, conflating "incomparable with the whole range" with "comparable with one bound, incomparable with the other". Both issues are addressed with a single core idea: represent a value's position as the *pair* of its relationships to the lower and upper bounds. - Add `BoundOrdering` (Within / Outside / Incomparable) and `RangePosition` (the lower/upper pair), with `RangePosition::ordering()` collapsing to a simple verdict when both bounds are comparable, and `is_inside()`. - `RangeOrdering` gains an `Empty` variant. `rcmp` (Ord) now detects empty ranges from their bounds and reports `Empty` instead of a bogus Below/Above, and never falsely reports `Inside` for an empty range. - Introduce `PartialRangeOrd::partial_rcmp -> RangePosition` for `PartialOrd` types, preserving per-bound information instead of losing it in an `Option`. - Tests: convert the partial suite to the new type, complete the previously empty stubs, and add the comparable-to-one-bound-only cases that the old design lost. Fix the README/code name drift (`RangeComparable`/`range_cmp`). This is a breaking change; bump to 0.3.0. https://claude.ai/code/session_01CTKxSkrLTyauoiGSFo2dVS
adriendellagaspera
force-pushed
the
partial-rcmp
branch
from
May 31, 2026 22:54
bd07b70 to
4d4946b
Compare
PartialOrd
adriendellagaspera
marked this pull request as ready for review
May 31, 2026 22:58
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
Motivation
This PR started as "introduce range comparison for
PartialOrd(partial_rcmp)". Whilereviewing it, two issues surfaced:
rcmp: the result was an arbitrary,representation-dependent
Below/Above(e.g.30.rcmp(45..35)→Belowbut30.rcmp(25..15)→Above).partial_rcmp -> Option<RangeOrdering>is leaky:Below/Inside/Aboveis a total-order notion. Over a poset, a value can be incomparable with one or both
bounds, and
Optioncollapses "incomparable with the whole range" together with"comparable with one bound, incomparable with the other" — losing information and
sometimes giving a misleading partial answer.
Both problems are solved by a single idea: represent a value's position as the pair of
its relationships to the lower and upper bounds.
Changes
BoundOrdering—Within/Outside/Incomparable(the last only occurs forPartialOrdtypes).RangePosition— the{ lower, upper }pair, with:ordering() -> Option<RangeOrdering>to collapse into a simple verdict when bothbounds are comparable;
is_inside().RangeOrderinggains anEmptyvariant.rcmp(forOrd) nowdetects empty ranges from their bounds and returns
Empty, and never falsely returnsInsidefor an empty range. Emptiness is judged from the bounds, not the population ofthe type (so
..0u32stays a regular range).PartialRangeOrdtrait withpartial_rcmp -> RangePositionfor everyPartialOrdtype, preserving per-boundinformation instead of discarding it in an
Option.stubs are filled in, and the comparable-to-one-bound-only cases (the ones the old
Optiondesign lost) are added explicitly.README (
RangeComparable/range_cmp) and the code (RangeOrd/rcmp).Notes
0.3.0.RangeOrderinggainingEmptybreaksexhaustive matches (intentional: it forces callers to consider emptiness).
rcmp(total order) detects emptiness explicitly, whereaspartial_rcmpdoes not attempt it — over a poset, "is this range empty?" can beundecidable (the bounds themselves may be incomparable). For the partial case,
Emptyonly surfaces via the
(Outside, Outside)witness throughordering().https://claude.ai/code/session_01CTKxSkrLTyauoiGSFo2dVS