Generic collections for C.
libmcc
is built using meson:
meson setup build
cd build
ninja
Docs are generated during build via Doxygen. They are placed under build/docs
.
For examples on usage, see src/samples.
There are multiple collection libraries for C out there, all with different approaches and pros/cons.
libmcc
is an experiment at an approach that's easy to maintain ( i.e. no specializations generated via. preprocessor ) and use.
The core of libmcc
is the vector
, an array that resizes itself as more elements are added.
This is done using a fat pointer - the data is prepended with a header struct, and the client code only receives a pointer to the actual data.
Consider the following:
int* vector = mcc_vector_create();
+--------+------+------+------+------+------+
| header | item | item | item | item | ... |
+--------+------+------+------+------+------+
^
int* vector
All other implemented collections are either directly or indirectly backed by vectors:
treeset.h
- A vector with elements ordered based on comparator; looking up items is done via binary searchhashset.h
- A vector segmented into logical buckets; addition and search is done by hashing and looking up appropriate buckettreemap.h
- Keys are stored in a treeset, values are stored in a vector, in the same order as keyshashmap.h
- Keys are stored in a hashset, values are stored in a vector, in the same order as keys
This leads to a neat feature - easy iteration and item access. No matter what kind of collection:
- it can be treated as a simple array
- it can be iterated as a simple array
libmcc
is licensed under the MIT license.
See LICENSE.