Kwker

Use Kwker from C and C++

The C package holds kwker.h (C11, also valid C++), the header-only C++17 API kwker.hpp, static and shared libraries, a pkg-config file and a CMake package. Unpack the release archive for your platform; <prefix> below is that directory (Installation).

The project file

CMakeRuns on your machine.
cmake_minimum_required(VERSION 3.16)
project(latency C CXX)
set(CMAKE_CXX_STANDARD 17)

find_package(Kwker 0.1 REQUIRED)
add_executable(latency main.cpp)
target_link_libraries(latency PRIVATE Kwker::kwker)        # or Kwker::kwker_static

The program

The three slowest requests, without sorting the whole array:

CInclude kwker.h; link with -lkwker_c.
#include <inttypes.h>
#include <stdio.h>
#include <kwker.h>

int main(void) {
    const double latency_ms[] = {12.1, 250.4, 8.9, 97.0, 310.2, 15.5, 260.0};
    double values[3];
    uint64_t positions[3];
    kwker_f64_top_k(latency_ms, 7, 3, KWKER_DESCENDING, 1, values, positions);
    for (int i = 0; i < 3; i++) printf("%g at %" PRIu64 "\n", values[i], positions[i]);
    return 0;
}
Output
310.2 at 4
260 at 6
250.4 at 1

Build and run

ShellOn your machine.
cmake -B build -DCMAKE_PREFIX_PATH=<prefix>
cmake --build build
./build/latency

Without CMake, pkg-config gives the flags: c++ -std=c++17 main.cpp $(pkg-config --cflags --libs kwker) -o latency, with PKG_CONFIG_PATH=<prefix>/lib/pkgconfig when the archive is outside the standard places.

Errors

Next steps