Kwker

Swift API reference

Every public function of the Kwker Swift package (macOS, iOS and Linux, over the C library), with its parameters and results (Kwker 0.1.0).

Kwker for Swift: in-place sorting, selection, partial sort, argsort and top-k of contiguous numeric collections through Kwker's C library (the engine chosen at run time: AVX-512, AVX2, NEON, portable), and strings in a collation. Floats in total order: -0.0 before +0.0, NaNs last unless .nansFirst; argsort / top-k are stable (equal keys by index).

SwiftAdd the Kwker Swift package (SwiftPM).
var a: [Double] = ...
a.kwkSort()                                  // like a.sort(), in place
a.kwkSort(order: .descending)
let ix = a.kwkArgsort()                      // the stable sorting permutation
let (v, i) = a.kwkTopK(10)                   // the 10 smallest and their indices
let s = Kwker.sorted(strings: names, collation: .naturalCaseless)

Types

KwkerOrder Page

SwiftAdd the Kwker Swift package (SwiftPM).
public struct KwkerOrder: OptionSet, Sendable

Sort order flags: ascending (the default), .descending, .nansFirst (floats). (Not "SortOrder": Foundation has one.)

KwkerOrder.ascending Page

SwiftAdd the Kwker Swift package (SwiftPM).
public static let ascending: KwkerOrder = []

Smallest first (the default: an empty set).

KwkerOrder.descending Page

SwiftAdd the Kwker Swift package (SwiftPM).
public static let descending = KwkerOrder(rawValue: 1)

Largest first.

KwkerOrder.nansFirst Page

SwiftAdd the Kwker Swift package (SwiftPM).
public static let nansFirst = KwkerOrder(rawValue: 2)

NaNs before every number (floats; without it they come last).

Kwkerable Page

SwiftAdd the Kwker Swift package (SwiftPM).
public protocol Kwkerable

A key type Kwker sorts natively (the C library's entry points for it).

Collation Page

SwiftAdd the Kwker Swift package (SwiftPM).
public enum Collation: Sendable

String orders: plain bytes (UTF-8: code point order, as Swift's < on String's unicodeScalars), ASCII letters without case, digit runs by numeric value ("file2" before "file10"), both, or a collating sequence of 256 byte weights.

Collation.bytes, Collation.caseless, Collation.natural, Collation.naturalCaseless Page

SwiftAdd the Kwker Swift package (SwiftPM).
case bytes, caseless, natural, naturalCaseless

Collation.ebcdic037 Page

SwiftAdd the Kwker Swift package (SwiftPM).
case ebcdic037

IBM EBCDIC 037 order for ASCII / Latin-1 text (space, punctuation, lowercase, uppercase, digits)

Collation.weights Page

SwiftAdd the Kwker Swift package (SwiftPM).
case weights([UInt8])

256 byte weights: strings compare as their UTF-8 bytes' weights, a prefix first; equal weights = equal characters

Kwker Page

SwiftAdd the Kwker Swift package (SwiftPM).
public enum Kwker

Kwker's functions that are not collection methods: strings in a collation, the version and the engine in use.

Kwker.version Page

SwiftAdd the Kwker Swift package (SwiftPM).
public static var version: String

The library's version (for example "0.1.0").

Kwker.isa Page

SwiftAdd the Kwker Swift package (SwiftPM).
public static var isa: String

The engine chosen for this CPU ("avx512", "avx2", "sse42", "neon", "portable", ...).

Kwker.argsort Page

SwiftAdd the Kwker Swift package (SwiftPM).
public static func argsort(strings: [String], collation: Collation = .bytes) -> [Int]

The stable order of strings under a collation (positions in sorted order).

Kwker.sorted Page

SwiftAdd the Kwker Swift package (SwiftPM).
public static func sorted(strings: [String], collation: Collation = .bytes) -> [String]

The strings sorted under a collation (stable).