Skip to content

x/exp/slices: BinarySearchFunc slice sort undefined #59685

Closed
@crisman

Description

@crisman

While thinking about #59260 and #57348 (and #57433) there is now a problem with
BinarySearchFunc() (at least the documentation):

BinarySearchFunc works like BinarySearch, but uses a custom comparison
function. The slice must be sorted in increasing order, where "increasing" is
defined by cmp. cmp(a, b) is expected to return an integer comparing the two
parameters: 0 if a == b, a negative number if a < b and a positive number if
a > b.

"defined by cmp" is problematic after #57348, as to sort the slice both parameters
need to be of the same type as the slice elements. If code is using a cmp where E is
not T then the sort of x is not defined.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions