julia
07da71a2 - Recognize `Tuple` and `AbstractVector` as `Ordered` in `Base.OrderStyle` (#62485)

Commit
39 days ago
Recognize `Tuple` and `AbstractVector` as `Ordered` in `Base.OrderStyle` (#62485) As mentioned in issue #61959 `unique!` and `allunique` have a sorted fast path method gated on `Base.OrderStyle`, but the trait only applies to a short, obvious list(Real, AbstractString, Symbol and Union{}), leaving the fast path unreachable for any other valid case. Since Tuples and Vectors both famously have a total ordering which satisfies the contiguous requirement of `unique!` they should be included Added: - `OrderStyle(::Type{<:AbstractVector{T}})` : vector is Ordered iff T is - _tuple_ordering() : Recursively checks that every field type is Ordered ``` julia> b = @be sort!([(rand(1:20), rand(1:20)) for _ in 1:100]) unique! Benchmark: 4523 samples with 6 evaluations min 1.100 μs (11 allocs: 5.981 KiB) median 1.400 μs (11 allocs: 5.999 KiB) mean 2.611 μs (11 allocs: 5.999 KiB, 0.19% gc time) max 538.167 μs (11 allocs: 6.015 KiB, 99.52% gc time) ``` ``` julia> b = @be sort!([(rand(1:20), rand(1:20)) for _ in 1:100]) unique! Benchmark: 2390 samples with 337 evaluations min 76.558 ns median 88.131 ns mean 88.775 ns max 359.644 ns ``` The original issue also mentioned CartesianIndex and other user defined types that simply wrap tuples/vectors but I'd like maintainer input before tackling that --------- Co-authored-by: Andy Dienes <51664769+adienes@users.noreply.github.com>
Author
Parents
Loading