While looking for something else to do, I realized how much I missed writing C code. I really enjoy how the C language allows me, as a programmer, to communicate almost directly with the machine, specifying exactly what and how to execute tasks.
In C, structures are fairly easy to understand, and you can use the built-in primitives provided by the language. However, when dealing with larger structures, libraries, or applications, or when it's impractical to know the dimensions of your dataset at compile time, using malloc and similar functions becomes an invaluable tool. The challenge here is that with this flexibility comes the responsibility of carefully managing memory allocation yourself. Do I really need to reinvent the wheel every time I require a dynamically allocated list with attached operations, or when I need a simple queue?
I've compiled some of the C code I've written and created a library that includes three data structures I believe are essential for most applications:
Vectorvector_t also known as a list, which can also be used as a tuple.
Matrixmatrix_t a set of operations that manipulates a 1D vector, virtually transforming it into a matrix.
Linked Listnode_t a simple linked list structure where the list is a pointer to the head and tail nodes.
Vector operations
Matrix operations
Examples
Vector
Matrix
Node (Linked List)
Building a Queue or Stack with a Linked List
You can leverage the node_t structure to build an efficient queue or stack by maintaining a reference to the head of the stack, or in the case of a queue, both the head and tail. The operations on node_t simplify the implementation of these structures.
Thread-Safe Queue System
Creating a simple thread-safe queue system can be beneficial for many queuing operations. This can be accomplished using the POSIX pthreads module.
While very rudimentary, I hope this can be useful for someone too.