Kwker

Kwker for Objective-C

The class Kwker (Sources/KwkerObjC: include/Kwker/Kwker.h, Kwker.m) over Kwker's C ABI (libkwker_c). C buffers of u8 .. f64 keys are sorted in place without copies; NSMutableData of raw keys and NSArray of NSNumber have conveniences. Run-time engine dispatch (AVX-512, AVX2, NEON, portable) comes from the C library.

Objective-CAdd the KwkerObjC package (SwiftPM or CocoaPods).
#import "Kwker/Kwker.h"
[Kwker sortDouble:values count:n order:SSOrderAscending];                 // -0.0 before +0.0, NaNs last
[Kwker sortInt32:keys count:n order:SSOrderDescending];                   // SSOrderNaNsFirst puts NaNs first
[Kwker selectUInt64:keys count:n k:k order:SSOrderAscending];             // the k-th key at keys[k]
[Kwker partialSortFloat:scores count:n k:100 order:SSOrderDescending];    // the 100 largest, in order, in front
[Kwker argsortInt64:keys count:n order:SSOrderAscending indices:ix];      // the stable permutation (uint64_t)
[Kwker topKFloat:scores count:n k:10 order:SSOrderDescending sorted:YES values:top indices:topIx];
[Kwker sortData:data type:SSKeyTypeInt16 order:SSOrderAscending];         // NSMutableData of raw keys
NSArray *sorted = [Kwker sortedNumbers:numbers order:SSOrderAscending];  // int64 if all integers, else doubles

Every method returns NO (or nil) on a bad argument and then leaves the data unchanged. The header uses lightweight generics where the compiler has them (clang) and plain NSArray under GCC; the implementation avoids clang-only syntax (boxed literals, subscripts), so it builds with Apple's clang and with GCC's Objective-C.

Build by hand: compile Sources/KwkerObjC/Kwker.m with the C package's include directory (ss capi --install <prefix> from rust/, or a release tarball) and link -lkwker_c and Foundation. Import the wrapper as "Kwker/Kwker.h" with Sources/KwkerObjC/include on the search path, never its Kwker subdirectory itself: on a case-insensitive file system (macOS) Kwker.h and the C library's kwker.h are the same name, and whichever directory comes first would answer for both.

Tested on Linux with GCC 13's Objective-C and GNUstep base 1.29, by ss native --lang objc from rust/. The test checks every key type against qsort / a stable reference for sort, descending sort, select, partialSort, argsort and topK, then the NSData / NSArray conveniences. It ends with 1M-key timings against qsort and -[NSMutableArray sortUsingSelector:]. The header is also checked with clang.

Packages