An open API service indexing awesome lists of open source software.

https://github.com/sequpt/ctl

A C11 library providing generic type-safe data structures compiling to actual structures and functions.
https://github.com/sequpt/ctl

abstract-data-types adt c c11 data-structures generic generic-programming template

Last synced: 5 days ago
JSON representation

A C11 library providing generic type-safe data structures compiling to actual structures and functions.

Awesome Lists containing this project

README

          

# ctl

[![pipeline status](https://gitlab.com/sequpt/ctl/badges/master/pipeline.svg)](https://gitlab.com/sequpt/ctl/-/commits/master)
[![license](https://img.shields.io/badge/license-0BSD-blue)](LICENSE)
[![doxygen](https://img.shields.io/badge/doc-doxygen-blue)](https://sequpt.gitlab.io/ctl)

A `C11` library of generic data structures providing type safety at compile
time.

## Table of Contents

- [Quick overview](#quick-overview)
- [Getting Started](#getting-started)
- [Prerequisites](#prerequisites)
- [Installation](#installation)
- [Documentation](#documentation)
- [Changelog](#changelog)
- [Contributing](#contributing)
- [License](#license)
- [Interesting links](#interesting-links)
- [Thanks](#thanks)

## Quick overview

```c
#include
#include "ctl_darray.h"
#include "ctl_stack.h"

#define CTL_DARRAY_TYPES int, char
CTL_DARRAY_DECLARE(CTL_DARRAY_TYPES);
CTL_DARRAY_DEFINE(CTL_DARRAY_TYPES)

int main(void)
{
CTL_DARRAY(int) * foo = ctl_create(foo);
CTL_DARRAY(char) * bar = ctl_create(bar);
ctl_push(foo, 1);
ctl_push(foo, 2);
ctl_push(bar, 'a');
ctl_push(bar, 'b');
printf("Last element in foo = %d\n", ctl_back(foo));
printf("First element in bar = %c\n", ctl_front(bar));
printf("Removing last element from bar = %c\n", ctl_pop(bar));
printf("Removing last element from bar = %c\n", ctl_pop(bar));
printf("foo size = %zu\n", ctl_size(foo));
printf("bar size = %zu\n", ctl_size(bar));
ctl_destroy(foo);
ctl_destroy(bar);
return 0;
}
```

**Output**:

```text
Last element in foo = 2
First element in bar = a
Removing last element from bar = b
Removing last element from bar = a
foo size = 2
bar size = 0
```

## Getting Started

### Prerequisites

A `C11` or above compliant compiler is needed due to the use of `_Generic`.

### Installation

[Download](https://gitlab.com/sequpt/ctl/-/archive/master/ctl-master.zip) or
clone the repository:

```text
git clone https://gitlab.com/sequpt/ctl.git
```

Optionally run the tests:

```text
cd ctl
make check
```

Data structures are self-contained in their own header and are independent from
each other. You can just drag-and-drop the one you need in your project and
`#include` it.

## Documentation

Documentation is available here:

## Changelog

See the [CHANGELOG.md](CHANGELOG.md) file.

## Contributing

See the [CONTRIBUTING.md](CONTRIBUTING.md) file.

## License

This project is licensed under the _very_ permissive [BSD Zero Clause License](LICENSE).

More information on the 0BSD license:

- [The 0BSD's creator website](https://landley.net/toybox/license.html)
- [BSD Zero Clause License | Software Package Data Exchange (SPDX)](https://spdx.org/licenses/0BSD.html)
- [Zero-Clause BSD (0BSD) | Open Source Initiative](https://opensource.org/licenses/0BSD)
- [BSD Zero Clause License | Choose a License](https://choosealicense.com/licenses/0bsd/)

## Interesting links

Here are a few generic data structure libraries in C:

- [stb_ds.h](https://github.com/nothings/stb/blob/master/stb_ds.h): _This is a single-header-file library that provides easy-to-use
dynamic arrays and hash tables for C (also works in C++)._
- Part of the well known [stb library](https://github.com/nothings/stb) by Sean Barrett.
- [Klib](https://github.com/attractivechaos/klib): _A standalone and lightweight C library_
- [Collections-C](https://github.com/srdja/Collections-C): _A library of generic data structures for the C language._

## Thanks

- [tnorth](https://gitlab.com/thno)