Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/barrust/set
Simple Set implementation in C
https://github.com/barrust/set
c set
Last synced: 16 days ago
JSON representation
Simple Set implementation in C
- Host: GitHub
- URL: https://github.com/barrust/set
- Owner: barrust
- License: mit
- Created: 2016-05-06T14:46:11.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2021-06-07T14:24:19.000Z (over 3 years ago)
- Last Synced: 2024-10-10T12:11:34.002Z (28 days ago)
- Topics: c, set
- Language: C
- Homepage:
- Size: 60.5 KB
- Stars: 64
- Watchers: 6
- Forks: 22
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# set
[![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT)
[![GitHub release](https://img.shields.io/github/v/release/barrust/set.svg)](https://github.com/barrust/set/releases)
[![C/C++ CI](https://github.com/barrust/set/workflows/C/C++%20CI/badge.svg?branch=master)](https://github.com/barrust/set/actions)
[![codecov](https://codecov.io/gh/barrust/set/branch/master/graph/badge.svg)](https://codecov.io/gh/barrust/set)A simple set implementation in **C**
Sets allow for quick checks for inclusion and exclusion
This implementation provides a simple and generally quick method to get set functionality into a C program quickly. It was developed to provide a basis for testing and benchmarking performance along with providing a purposeful, low overhead library. Currently only supports strings.
To use the library, copy the `src/set.h` and `src/set.c` files into your project and include it where needed.
## License
MIT 2016# Main Features
* Union, intersection, difference, and semantic difference
* Standard and Strict subset and superset checks
* Simple method to change the hashing function if desired
* Add, check, and remove elements in a the set## Future Enhancements
* In place union - add to an already created Set
* Print statistics about the set## Usage:
``` c
#include "set.h"
#includeint main(int argc, char** argv) {
SimpleSet set;
set_init(&set);
set_add(&set, "orange");
set_add(&set, "blue");
set_add(&set, "red");
set_add(&set, "green");
set_add(&set, "yellow");if (set_contains(&set, "yellow") == SET_TRUE) {
printf("Set contains 'yellow'!\n");
} else {
printf("Set does not contains 'yellow'!\n");
}if (set_contains(&set, "purple") == SET_TRUE) {
printf("Set contains 'purple'!\n");
} else {
printf("Set does not contains 'purple'!\n");
}set_destroy(&set);
}
```## Thread safety
Due to the the overhead of enforcing thread safety, it is up to the user to
ensure that each thread has controlled access to the set. For **OpenMP** code,
the following should suffice.``` c
#include "set.h"
#includeint main(int argc, char** argv) {
SimpleSet set;
set_init(&set);
int i;
#pragma omp parallel for private(i)
for (i = 0; i < 500000; i++) {
char key[KEY_LEN] = {0};
sprintf(key, "%d", i);
#pragma omp critical (set_lock)
{
set_add(&set, key);
}
}
set_destroy(&set);
}
```All but `set_contains` needs to be guarded against race conditions as the set
will grow as needed. Set comparison functions (union, intersect, etc.) should
be done on non-changing sets.## Required Compile Flags:
None