Prime Headers is (aiming to be) a headers-only, easy to use, type-safe way to use generic data structures and algorithms in C Projects.
It aims to have each data structure and algorithm thoroughly tested with primitive and pointer-to-structs examples.
It works primarily by abusing the C preprocessor to a scale hitherto undreamt of (I have later realised that this scale was indeed dreamt to).
It uses macros with arguments to generate the appropriate structs and functions at the preprocessing stage, leading to no runtime overhead. However, this approach has definite drawbacks, which are clarified further.
It uses CMake as the build system, Valgrind for checking memory safety and GitHub Ations for checking cross-platform compatibility.
- Header-only, generic, type-safe data structures and algorithms.
- Build tested on multiple platforms and compilers using CMake and GitHub actions.
- Unit tested using CTest.
- Memory profiled using Valgrind and CTest memcheck.
- Supports primitive data structures as well as pointer-to-structs.
- Windows
- cl (MSVC)
- Look into GitHub actions based testing
- Valgrind testing?
- How can I integrate CMake, CTest, GitHub actions and Valgrind?
- AddressSanitizer too?
- Write primitive as well as pointer-to-structs examples
- [Technical Debt] Use constant pointers, pointers to constants and constant pointers to constant wherever applicable.
- Each function, with pointer params, should check for NULL for each pointer param.
- Have a thorough deletion mechanism for each data structure.
- Library functions in snake_case_##ANY_SUFFIX()..
- All reallocs need to be first assigned to temp variables, so as to not lose access to data.
After ensuring you have the prerequisite dependencies (CMake and Valgrind). run these commands in the root directory of the repository.
$ mkdir build
$ cd build
$ cmake ..
$ cmake --build .
$ ctest
The project is a work in progress, with an emphasis on getting things working first. Apologies for the ugly/(currently wrong) code.
- Vector
- Stack using Vector
- Stack using Linked List
- Queue using Vector
- Queue using Linked List
- Deque (Double Ended Queue) using Vector (using existing vector interface)
- Deque (Double Ended Queue) using Doubly Linked List
- Singly Linked List
- Set
- Unordered Set
- Map
- Unordered Map (Hashmap)
- Circular Singly Linked List
- Doubly Linked List
- Circular Doubly Linked List
- Generalized Linked List
- Heap
- Binary Tree (Generation using 2 traversals left)
- Binary Search Tree (Done recursively, TODO delete for all 3 cases)
- AVL Tree
- RB Tree
- Linear Search in Vector
- Linear Search in SLL
- Binary Search
- Bubble Sort
- Selection Sort
- Insertion Sort
- Merge Sort
- Quick sort
- Relatively easy use of generic data structures and algorithms while being type-safe.
- Is cool, I mean what is cooler than preprocessor hijinks.
- This method is optimised for ease of use (probably for beginners/learners because it primarily works with pointers to structs), however, defining multiple data structures in the same file may (read WILL) lead to slower compilation times due to large compilation units because of the coupling of interfaces (headers & prototypes) and the actual functionality (function definitions) itself.
- Poor support (slow) for Intellisense and similar code intelligence and autocompletion tools.
- As all the functions are defined in the macro, with everything being in C, there is no way to apply access modifiers to helper functions for a cleaner interface.
This project is a side-effect of trying to develop a command-line tool for easier use of generic data structures for C, which splits the interface and the function definitions, leading to better compilation times.
-
Thought this was an original idea, but this repository I found later implemented this already - https://github.com/mystborn/GenericDataStructures
-
I got the idea for the need of type-safe data structures by seeing this repository, otherwise it is perfect, especially the error handling is chef's kiss - https://github.com/MostafaTwfiq/C-DataStructures-And-Algorithms