MyNixOS website logo
Description

Sort primitive arrays.

This library provides a stable sorting algorithm for primitive arrays. The algorithm currently uses mergesort on large chunks and switches to insertion sort on small chunks. There are also novel improvements to increase the performance if the input array is already mostly sorted.

primitive-sort

Sorting of contiguous data structures. Implementation uses mergesort and switches to insertion sort once the arrays are small. Some of the benchmark results on a Intel Xeon CPU E3-1505M v5 2.80GHz (GHC 8.10.4):

contiguous/Int8/unsorted/mini      time  91.59 ns  
contiguous/Int8/unsorted/tiny      time  1.236 μs  
contiguous/Int8/unsorted/small     time  40.68 μs  
contiguous/Int8/unsorted/medium    time  614.1 μs  
contiguous/Int8/unsorted/large     time  6.580 ms  
contiguous/Int8/unsorted/gigantic  time  68.16 ms  

Results may vary across processors, but you observe results that are 10x slower, it's probably an issue with the compiler, and please open an issue.

GHC Specialization Problems

Sadly, the most permissive signature for sort causes GHC's specialization to break. This permissive signature is:

sort :: (Contiguous arr, Element arr a, Ord a) => arr a -> arr a

And the less permissive variant used by this library is:

sort :: (Prim a, Ord a) => PrimArray a -> PrimArray a

The latter works nicely with SPECIALIZE and INLINEABLE, but the former does not work at all with these. The issue is believed to be related to the use of an associated constraint type Element, which introduced coercions that might confuse the specializer. However, this has not been confirmed.

Metadata

Version

0.1.2.4

Platforms (75)

    Darwin
    FreeBSD
    Genode
    GHCJS
    Linux
    MMIXware
    NetBSD
    none
    OpenBSD
    Redox
    Solaris
    WASI
    Windows
Show all
  • aarch64-darwin
  • aarch64-genode
  • aarch64-linux
  • aarch64-netbsd
  • aarch64-none
  • aarch64_be-none
  • arm-none
  • armv5tel-linux
  • armv6l-linux
  • armv6l-netbsd
  • armv6l-none
  • armv7a-darwin
  • armv7a-linux
  • armv7a-netbsd
  • armv7l-linux
  • armv7l-netbsd
  • avr-none
  • i686-cygwin
  • i686-darwin
  • i686-freebsd
  • i686-genode
  • i686-linux
  • i686-netbsd
  • i686-none
  • i686-openbsd
  • i686-windows
  • javascript-ghcjs
  • loongarch64-linux
  • m68k-linux
  • m68k-netbsd
  • m68k-none
  • microblaze-linux
  • microblaze-none
  • microblazeel-linux
  • microblazeel-none
  • mips-linux
  • mips-none
  • mips64-linux
  • mips64-none
  • mips64el-linux
  • mipsel-linux
  • mipsel-netbsd
  • mmix-mmixware
  • msp430-none
  • or1k-none
  • powerpc-netbsd
  • powerpc-none
  • powerpc64-linux
  • powerpc64le-linux
  • powerpcle-none
  • riscv32-linux
  • riscv32-netbsd
  • riscv32-none
  • riscv64-linux
  • riscv64-netbsd
  • riscv64-none
  • rx-none
  • s390-linux
  • s390-none
  • s390x-linux
  • s390x-none
  • vc4-none
  • wasm32-wasi
  • wasm64-wasi
  • x86_64-cygwin
  • x86_64-darwin
  • x86_64-freebsd
  • x86_64-genode
  • x86_64-linux
  • x86_64-netbsd
  • x86_64-none
  • x86_64-openbsd
  • x86_64-redox
  • x86_64-solaris
  • x86_64-windows