Skip to content

Clarify Ord's requirement: what is needed for sort-order #8071

Closed
@omasanori

Description

@omasanori

AFAIK Ord is a trait "for values that can be compared for a sort-order" (quoted from doc) and is distinguished from total ordering (TotalOrd). Sometimes it seems to be regarded as partial ordering. (cf. @cmr's comment at #7765.)

However, some sort algorithms assume that x ~ z if x ~ y and y ~ z. (a ~ b here means !(a < b) && !(a > b). this relation is called equivalent or incomparable.) Without the assumption, in worst case O(N^2) comparison is needed to sort N elements. Strict partial ordering with this assumption is called strict weak ordering.

I think it is necessary to clarify what we require to impls for Ord: partial ordering (probably minimum requirement), weak ordering, or something else.

See also: #8360

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions