Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/lemire/cbitset
A simple bitset library in C
https://github.com/lemire/cbitset
bitset bitset-library c
Last synced: 12 days ago
JSON representation
A simple bitset library in C
- Host: GitHub
- URL: https://github.com/lemire/cbitset
- Owner: lemire
- License: apache-2.0
- Created: 2016-05-02T22:54:03.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2024-09-30T19:28:45.000Z (about 1 month ago)
- Last Synced: 2024-10-12T21:28:41.583Z (26 days ago)
- Topics: bitset, bitset-library, c
- Language: C
- Homepage:
- Size: 78.1 KB
- Stars: 125
- Watchers: 10
- Forks: 17
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# cbitset
![Ubuntu 20.04 CI (GCC 9)](https://github.com/lemire/cbitset/workflows/Ubuntu%2020.04%20CI%20(GCC%209)/badge.svg)
![MSYS2-CI](https://github.com/lemire/cbitset/workflows/MSYS2-CI/badge.svg)
![Visual Studio-CI](https://github.com/lemire/cbitset/workflows/VS16-CI/badge.svg)Simple bitset library in C. It includes fast functions
to compute cardinalities, unions, intersections...- It is tiny: it is made of three files (two header files and one source file).
- It is tested.
- It is fast.
- It is straight C.Usage in C:
```C
bitset_t * b = bitset_create();
bitset_set(b,10);
bitset_get(b,10);// returns true
bitset_free(b); // frees memory
```Advanced example:
```C
bitset_t *b = bitset_create();
for (int k = 0; k < 1000; ++k) {
bitset_set(b, 3 * k);
}
// We have bitset_count(b) == 1000.
// We have bitset_get(b, 3) is true
// You can iterate through the values:
size_t k = 0;
for (size_t i = 0; bitset_next_set_bit(b, &i); i++) {
// You will have i == k
k += 3;
}
// We support a wide range of operations on two bitsets such as
// bitset_inplace_symmetric_difference(b1,b2);
// bitset_inplace_symmetric_difference(b1,b2);
// bitset_inplace_difference(b1,b2);// should make no difference
// bitset_inplace_union(b1,b2);
// bitset_inplace_intersection(b1,b2);
// bitsets_disjoint
// bitsets_intersect
```## CMake
```
mkdir build
cd build
cmake ..
cmake --build . --config Release
ctest .
```The cmake build also supports installation. The header files will be installed in a distinct subdirectory (cbitset).
## Old-school Makefiles
To run tests:
```bash
make
./unit
```## Prerequisites
C11-compatible compiler.
Visual Studio now supports the [C11 and C17 standards](https://devblogs.microsoft.com/cppblog/c11-and-c17-standard-support-arriving-in-msvc/).