MIT-licensed C header library of efficient containers, sorts, parsers, and utilities copied into your tree without heavy dependencies.
Overview
Klib is a lightweight C library made of mostly header-only components you copy into your project. Pieces are independent of each other and of external libraries aside from the standard C library, which keeps integration simple for embedded or scientific codebases.
Common modules include open-addressing hash tables, B-tree and AVL search trees, sorting and shuffling routines, dynamic arrays, linked lists, string helpers, pseudo-random and small numerical routines, command-line parsing, FASTA/FASTQ parsing, remote HTTP/FTP file access, HMM helpers, and Smith-Waterman alignment helpers.
Generic containers are implemented with C macros so instantiations are type-specific at compile time rather than void-pointer based. That yields speed and memory use comparable to hand-written structures for each type, at the cost of more awkward source and debugging.
Documentation is primarily in the headers, with examples under test/ and additional notes on the project site. Benchmark posts compare khash, kbtree, and sorting components against other implementations.
Key features
- Header-only hash table khash
- B-tree and AVL search trees
- Introsort merge sort heap sort
- Dynamic array kvec
- FASTA FASTQ stream parser
- Command-line ketopt parser
- Macro-instantiated generic types
- Minimal external dependencies
Use cases
- Embed fast C containers
- Bioinformatics string parsing
- Single-file algorithm utilities
- Projects avoiding heavy C frameworks