TinyGenericC
Tiny C Libraries that exploits undefined behaviors to achieve generic programming. Requires C99 support.
Inspired by rxi/map and rxi/vec and attractivechaos/klib
WARNING
You are summoning the horrific nasal demons. Multiple nasal demons. You should never recall them unless you are steer-clear of knowing what you are doing.
Compile-time type checking is virtually and practically disabled here by the side effect of pointer rewiring.
I'm planning to import static_assert but it didn't really worked out on MSVC, only the IDE will show the type error.
Documents and comments are not completed.
THREAD-UNSAFE EVEN WITH LOCKS PLEASE DO NOT USE IT IN PRODUCTION.
Index
Currently undergoing development:
- vector(T): Dynamic array. Header-only.
- vector_view(T): Like vector but using a static memory location. Header-only.
- linked_list(T) and singly_linked_list(T): (Type-unsafe) Linked List. Header-only.
- hash_table(K, V): Hash table using FNV-1a and separate chaining with list head cells. Custom hash has to be done by user.
- binary_tree(T): Binary tree (WIP)
- ref_count(T): Manual reference counting (WIP). Header-only.
- mempool: Memory pool (WIP). Hopefully header-only.
- tagged_mem: Linear memory with a pre-defined size (just like sds) (WIP)
A toy JSON library is also included here to demonstrate TinyGenericC. However the deserializer part is not started (I'm still learning parser sorry).
Note
Unfortunately, this is not truly-generic programming. Instead, it's more like Java-ish type erasure that defined a certain bound on object/struct size beforehand, and the program is pretending to not writing beyond the memory by asserting the size in run-time.
The sentinel objects to operate on the generic object (e.g. iterator, index) however, is user-defined, and so highly dangerous since type-aliasings are most likely or unintentionally violated.
Therefore, types are not retified and validated. You are responsible for correcting the types in case you shot yourself in the foot.
TODO
- Implement mempool first to support a memory allocator (useful for MCUs)
- Rewrite all containers to utilize mempool
- Make vector_view able to use local buffer
- Fix the god-damn documentation!