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.
- Host: GitHub
- URL: https://github.com/sequpt/ctl
- Owner: sequpt
- License: 0bsd
- Created: 2023-01-21T18:32:42.000Z (about 3 years ago)
- Default Branch: master
- Last Pushed: 2023-01-25T13:54:16.000Z (about 3 years ago)
- Last Synced: 2023-05-06T16:25:31.827Z (over 2 years ago)
- Topics: abstract-data-types, adt, c, c11, data-structures, generic, generic-programming, template
- Language: C
- Homepage:
- Size: 130 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
Awesome Lists containing this project
README
# ctl
[](https://gitlab.com/sequpt/ctl/-/commits/master)
[](LICENSE)
[](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)