Skip to content

Introduction

Collection is a modern generic data structures and algorithms library for C, inspired by C++ STL. It provides essential data structures like dynamic arrays, heap, linked lists, hash tables, and efficient algorithms with a clean, type-safe API.

  • Generic Design - Type-agnostic implementation using void pointers
  • Memory Safe - Automatic memory management with custom destructor support
  • Modern C - Clean API following C11 standards and best practices
  • STL-Inspired - Familiar interface for developers coming from C++

Build Dependencies

  • C Compiler: GCC or Clang with C11 support
  • Make: GNU Make 3.81 or later
  • Standard C Library: glibc or compatible
Terminal window
git clone <repository-url>
cd collection

Build the static library:

Terminal window
make lib

This creates a static library at lib/libcollection.a.

Build the library, then compile and run the full test suite:

Terminal window
make test

Or build the library and run all tests in one step:

Terminal window
make all

Module-scoped tests use the test-% pattern (replace NAME with the module name), for example:

Terminal window
make test-vector

Include the library in your project:

Terminal window
gcc -I./include your_program.c -L./lib -lcollection -o your_program

The build system is configured via config/config.mk:

  • C Standard: c11
  • Build Method: static or dynamic
  • Library Name: collection

To build as a dynamic library, edit config/config.mk:

BUILD_METHOD := dynamic

Then rebuild:

Terminal window
make clean
make lib

For a consistent development environment across different platforms, you can use Docker:

Terminal window
make docker

This command will:

  • Check if the Docker image exists, and build it if needed (Ubuntu-based with GCC and C development tools)
  • Remove any existing container with the same name
  • Start an interactive container with your project directory mounted at /workspace

The Docker image includes:

  • Ubuntu Linux
  • GCC (GNU Compiler Collection)
  • Make and build-essential tools

Once inside the container, you can build and test the library:

Terminal window
make lib
make test

Running make with no target defaults to help and prints the same usage as make help.

TargetDescription
make helpShow available commands
make allBuild the library and run all tests
make libBuild the library
make testBuild and run all tests
make test-NAMEBuild and run tests for a specific module
make cleanClean the build artifacts
make flagsShow the compile and link flags
make clangRun clang to generate compile commands
make formatFormat the code
make dockerRun Docker container with development environment

Contributions are welcome! Whether it’s:

  • Bug reports
  • Feature requests
  • Documentation improvements
  • Code contributions

Please feel free to:

  • Open an issue to discuss proposed changes
  • Fork the repository
  • Submit a pull request

The documentation is built using Astro and Starlight.

Terminal window
cd doc
npm install
npm run dev
npm run build

This project is licensed under the GNU General Public License v3.0 or later.

  • Documentation: Full API Reference
  • Issues: Report bugs or request features via GitHub Issues
  • Discussions: Ask questions in GitHub Discussions
  • Inspired by C++ Standard Template Library (STL)
  • Test framework: utest
  • Documentation: Astro Starlight