Skip to content

Radix sort can be unsafe for custom types #26

@nalimilan

Description

@nalimilan

In theory, custom types defined in packages can implement any semantics for comparison and equality operators. This means that radix sort can be incorrect even for isbits types, if the comparison operators are inconsistent with the sorting of the bit pattern.

This is particularly dangerous since package authors do not necessarily consider the possibility of using RadixSort on their types, but users may do so naively without knowing the implementation details. AFAICT the only solution to prevent potentially problematic bugs is to throw an error by default when using RadixSort on a type which is not known to support it. A trait-like function SortingAlgorithms.radixsortsafe(::Type{T}) would have to be overridden to return true for types that support it. The error message could explain this, so that it is relatively easy to fix when users know what they are doing.

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