Skip to content

Can isless be defined for everything? #34815

Open
@tkf

Description

@tkf

I thought my comment #34744 (comment) may be distracting the original issue so I open it as a separate issue. My questions are:

  1. Is it possible to define isless for everything?
  2. Can it have practically fast enough implementation?
  3. Is it reasonable to use an arbitrary ordering for isless?

I think the answer to point 1 is yes, since I can do isless(a, b) = isless(objectid(a), objectid(b)). This is stupid, but I think it's OK as a proof of possibility. In particular, this means that, if we define equivalence by mapping to an integer, we get a total ordering "for free."

For point 2, I think there are cases where optimization is trivial and covers a wide range of practical use. For example, we can lower isless(a::T, b::T) with struct type T to isless on the tuples of field values.

If the philosophy behind the compatibility between hasing and sorting is to support consistent behavior of hash-based and comparison-based containers, I think the answer to point 3 is yes too. But I don't think I have thought enough about it so maybe I'm missing something. In particular, it may be impossible to avoid ordering that changes julia process to process (like how hash behaves).

Metadata

Metadata

Assignees

No one assigned

    Labels

    featureIndicates new feature / enhancement requestssortingPut things in order

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions