Hello Together C & C++ 🙂
I'd like to share my C generic data-structure library Convenient Containers (CC).
CC's main advantages are summarized in the Rationale section of its README. In short, using some novel techniques, the library is able to provide a range of fully typesafe data structures with a generic API agnostic to both container type and data types, without requiring the user to make any boilerplate pre-declarations for every container/data type combination. Hence, CC containers function much like containers in languages with native support for generics (such as C++):
#include <stdio.h>
#include "cc.h"
int main( void )
{
vec( int ) our_vec;
init( &our_vec );
push( &our_vec, 5 );
printf( "%d\n", *get( &our_vec, 0 ) );
cleanup( &our_vec );
map( int, float ) our_map;
init( &our_map );
insert( &our_map, 5, 0.5f );
printf( "%f\n", *get( &our_map, 5 ) );
cleanup( &our_map );
}
Besides ergonomics, performance is also important. CC's hash tables have performed very well in benchmarks both by me and by others. Its red-black trees have also benchmarked on par with their C++ STL counterparts.
Some of the techniques upon which CC relies are explained briefly in its FAQ and more thoroughly in a series of Reddit comments that I made back when the library was first released. I am working on articles to describe these techniques more systematically, the first of which I published earlier.
