attractivechaos/klib
FreeA standalone and lightweight C library
About attractivechaos/klib
Klib is a standalone, lightweight, and efficient generic library for the C programming language, distributed under the MIT/X11 license. It consists of a collection of independent components, each of which can be used by simply copying a few source files into a project, eliminating external library dependencies beyond the standard C library. Klib emphasizes performance and minimal memory footprint, with components such as khash.h (open-addressing hash table), kbtree.h (B-tree based search tree), kavl.h (intrusive AVL tree), ksort.h (various sorting algorithms including introsort and mergesort), kseq.h (stream buffer and FASTA/FASTQ parser), kvec.h (dynamic array), klist.h (linked list with memory pool), and kstring.h (string library). It also includes utilities for command-line parsing (ketopt.h), numerical routines, HMM, suffix array construction, Smith-Waterman alignment, and more. The library relies on C macros for generic programming, achieving type-specific efficiency without using void* pointers, unlike generic libraries such as Glib.
Key Features
Pros & Cons
- Standalone and lightweight: no external dependencies beyond the standard C library
- Components are independent; only need to copy the required files
- Highly efficient implementations, among the fastest in their class (e.g., khash, kbtree, ksort)
- Small memory footprint
- MIT license allows free use in both open-source and proprietary projects
- Macro-based generic containers achieve type-specific efficiency without type erasure overhead
- Well-suited for systems programming and bioinformatics applications
- Requires working knowledge of C macros; code can be difficult to read and debug
- No support for C++ directly (though may be usable with extern "C")
- Lack of dynamic memory safety guarantees inherent in languages with generics or managed memory
- Documentation is primarily in the README and a separate documentation page; no formal API reference beyond header comments
- Not a comprehensive standard library like Glib; focuses on a specific set of efficient components