---
name: "Bitset.h"
section: "3"
platform: "linux"
package: "libzycore-doc"
version: "1.5.2-1"
release: "Debian 13 (Trixie)"
platforms: ["linux"]
url: "https://new.carta.tech/Bitset.h"
---

# Bitset.h(3)

## NAME

include/Zycore/Bitset.h

## SYNOPSIS

`#include <Zycore/Allocator.h>`\
 `#include <Zycore/Status.h>`\
 `#include <Zycore/Types.h>`\
 `#include <Zycore/Vector.h>`\

### Classes

struct **ZyanBitset\_**\

### Typedefs

typedef struct **ZyanBitset\_** **ZyanBitset**\
 typedef **ZyanStatus**(\* **ZyanBitsetByteOperation**) (ZyanU8 \*v1, const ZyanU8 \*v2)\

### Functions

**ZYCORE\_EXPORT** **ZYAN\_REQUIRES\_LIBC** **ZyanStatus** **ZyanBitsetInit** (**ZyanBitset** \*bitset, ZyanUSize count)\
 **ZYCORE\_EXPORT** **ZyanStatus** **ZyanBitsetInitEx** (**ZyanBitset** \*bitset, ZyanUSize count, **ZyanAllocator** \*allocator, ZyanU8 growth\_factor, ZyanU8 shrink\_threshold)\
 **ZYCORE\_EXPORT** **ZyanStatus** **ZyanBitsetInitBuffer** (**ZyanBitset** \*bitset, ZyanUSize count, void \*buffer, ZyanUSize capacity)\
 **ZYCORE\_EXPORT** **ZyanStatus** **ZyanBitsetDestroy** (**ZyanBitset** \*bitset)\
 **ZYCORE\_EXPORT** **ZyanStatus** **ZyanBitsetPerformByteOperation** (**ZyanBitset** \*destination, const **ZyanBitset** \*source, **ZyanBitsetByteOperation** operation)\
 **ZYCORE\_EXPORT** **ZyanStatus** **ZyanBitsetAND** (**ZyanBitset** \*destination, const **ZyanBitset** \*source)\
 **ZYCORE\_EXPORT** **ZyanStatus** **ZyanBitsetOR** (**ZyanBitset** \*destination, const **ZyanBitset** \*source)\
 **ZYCORE\_EXPORT** **ZyanStatus** **ZyanBitsetXOR** (**ZyanBitset** \*destination, const **ZyanBitset** \*source)\
 **ZYCORE\_EXPORT** **ZyanStatus** **ZyanBitsetFlip** (**ZyanBitset** \*bitset)\
 **ZYCORE\_EXPORT** **ZyanStatus** **ZyanBitsetSet** (**ZyanBitset** \*bitset, ZyanUSize index)\
 **ZYCORE\_EXPORT** **ZyanStatus** **ZyanBitsetReset** (**ZyanBitset** \*bitset, ZyanUSize index)\
 **ZYCORE\_EXPORT** **ZyanStatus** **ZyanBitsetAssign** (**ZyanBitset** \*bitset, ZyanUSize index, **ZyanBool** value)\
 **ZYCORE\_EXPORT** **ZyanStatus** **ZyanBitsetToggle** (**ZyanBitset** \*bitset, ZyanUSize index)\
 **ZYCORE\_EXPORT** **ZyanStatus** **ZyanBitsetTest** (**ZyanBitset** \*bitset, ZyanUSize index)\
 **ZYCORE\_EXPORT** **ZyanStatus** **ZyanBitsetTestMSB** (**ZyanBitset** \*bitset)\
 **ZYCORE\_EXPORT** **ZyanStatus** **ZyanBitsetTestLSB** (**ZyanBitset** \*bitset)\
 **ZYCORE\_EXPORT** **ZyanStatus** **ZyanBitsetSetAll** (**ZyanBitset** \*bitset)\
 **ZYCORE\_EXPORT** **ZyanStatus** **ZyanBitsetResetAll** (**ZyanBitset** \*bitset)\
 **ZYCORE\_EXPORT** **ZyanStatus** **ZyanBitsetPush** (**ZyanBitset** \*bitset, **ZyanBool** value)\
 **ZYCORE\_EXPORT** **ZyanStatus** **ZyanBitsetPop** (**ZyanBitset** \*bitset)\
 **ZYCORE\_EXPORT** **ZyanStatus** **ZyanBitsetClear** (**ZyanBitset** \*bitset)\
 **ZYCORE\_EXPORT** **ZyanStatus** **ZyanBitsetReserve** (**ZyanBitset** \*bitset, ZyanUSize count)\
 **ZYCORE\_EXPORT** **ZyanStatus** **ZyanBitsetShrinkToFit** (**ZyanBitset** \*bitset)\
 **ZYCORE\_EXPORT** **ZyanStatus** **ZyanBitsetGetSize** (const **ZyanBitset** \*bitset, ZyanUSize \*size)\
 **ZYCORE\_EXPORT** **ZyanStatus** **ZyanBitsetGetCapacity** (const **ZyanBitset** \*bitset, ZyanUSize \*capacity)\
 **ZYCORE\_EXPORT** **ZyanStatus** **ZyanBitsetGetSizeBytes** (const **ZyanBitset** \*bitset, ZyanUSize \*size)\
 **ZYCORE\_EXPORT** **ZyanStatus** **ZyanBitsetGetCapacityBytes** (const **ZyanBitset** \*bitset, ZyanUSize \*capacity)\
 **ZYCORE\_EXPORT** **ZyanStatus** **ZyanBitsetCount** (const **ZyanBitset** \*bitset, ZyanUSize \*count)\
 **ZYCORE\_EXPORT** **ZyanStatus** **ZyanBitsetAll** (const **ZyanBitset** \*bitset)\
 **ZYCORE\_EXPORT** **ZyanStatus** **ZyanBitsetAny** (const **ZyanBitset** \*bitset)\
 **ZYCORE\_EXPORT** **ZyanStatus** **ZyanBitsetNone** (const **ZyanBitset** \*bitset)\

## Detailed Description

Implements the bitset class.

## Typedef Documentation

### typedef struct ZyanBitset\_ ZyanBitset

Defines the `ZyanVector` struct.

All fields in this struct should be considered as 'private'. Any changes may lead to unexpected behavior.

### typedef ZyanStatus(\* ZyanBitsetByteOperation) (ZyanU8 \*v1, const ZyanU8 \*v2)

Defines the `ZyanBitsetByteOperation` function prototype.

**Parameters**

*v1* A pointer to the first byte. This value receives the result after performing the desired operation. \
 *v2* A pointer to the second byte.

**Returns**

A zyan status code.

This function is used to perform byte-wise operations on two `ZyanBitset` instances.

## Function Documentation

### ZYCORE\_EXPORT ZyanStatus ZyanBitsetAll (const ZyanBitset \* bitset)

Checks, if all bits of the given bitset are set.

**Parameters**

*bitset* A pointer to the `ZyanBitset` instance.

**Returns**

`ZYAN_STATUS_TRUE`, if all bits are set, `ZYAN_STATUS_FALSE`, if not. Another zyan status code, if an error occurred.

### ZYCORE\_EXPORT ZyanStatus ZyanBitsetAND (ZyanBitset \* destination, const ZyanBitset \* source)

Performs a logical `AND` operation on the given `ZyanBitset` instances.

**Parameters**

*destination* A pointer to the `ZyanBitset` instance that is used as the first input and as the destination. \
 *source* A pointer to the `ZyanBitset` instance that is used as the second input.

**Returns**

A zyan status code.

If the destination bitmask contains more bits than the source one, the state of the remaining bits will be undefined.

### ZYCORE\_EXPORT ZyanStatus ZyanBitsetAny (const ZyanBitset \* bitset)

Checks, if at least one bit of the given bitset is set.

**Parameters**

*bitset* A pointer to the `ZyanBitset` instance.

**Returns**

`ZYAN_STATUS_TRUE`, if at least one bit is set, `ZYAN_STATUS_FALSE`, if not. Another zyan status code, if an error occurred.

### ZYCORE\_EXPORT ZyanStatus ZyanBitsetAssign (ZyanBitset \* bitset, ZyanUSize index, ZyanBool value)

Sets the bit at `index` of the given `ZyanBitset` instance to the specified `value`.

**Parameters**

*bitset* A pointer to the `ZyanBitset` instance. \
 *index* The bit index. \
 *value* The new value.

**Returns**

A zyan status code.

### ZYCORE\_EXPORT ZyanStatus ZyanBitsetClear (ZyanBitset \* bitset)

Deletes all bits of the given `ZyanBitset` instance.

**Parameters**

*bitset* A pointer to the `ZyanBitset` instance.

**Returns**

A zyan status code.

### ZYCORE\_EXPORT ZyanStatus ZyanBitsetCount (const ZyanBitset \* bitset, ZyanUSize \* count)

Returns the amount of bits set in the given bitset.

**Parameters**

*bitset* A pointer to the `ZyanBitset` instance. \
 *count* Receives the amount of bits set in the given bitset.

**Returns**

A zyan status code.

### ZYCORE\_EXPORT ZyanStatus ZyanBitsetDestroy (ZyanBitset \* bitset)

Destroys the given `ZyanBitset` instance.

**Parameters**

*bitset* A pointer to the `ZyanBitset` instance.

**Returns**

A zyan status code.

### ZYCORE\_EXPORT ZyanStatus ZyanBitsetFlip (ZyanBitset \* bitset)

Flips all bits of the given `ZyanBitset` instance.

**Parameters**

*bitset* A pointer to the `ZyanBitset` instance.

**Returns**

A zyan status code.

### ZYCORE\_EXPORT ZyanStatus ZyanBitsetGetCapacity (const ZyanBitset \* bitset, ZyanUSize \* capacity)

Returns the current capacity of the bitset in bits.

**Parameters**

*bitset* A pointer to the `ZyanBitset` instance. \
 *capacity* Receives the size of the bitset in bits.

**Returns**

A zyan status code.

### ZYCORE\_EXPORT ZyanStatus ZyanBitsetGetCapacityBytes (const ZyanBitset \* bitset, ZyanUSize \* capacity)

Returns the current capacity of the bitset in bytes.

**Parameters**

*bitset* A pointer to the `ZyanBitset` instance. \
 *capacity* Receives the size of the bitset in bytes.

**Returns**

A zyan status code.

### ZYCORE\_EXPORT ZyanStatus ZyanBitsetGetSize (const ZyanBitset \* bitset, ZyanUSize \* size)

Returns the current size of the bitset in bits.

**Parameters**

*bitset* A pointer to the `ZyanBitset` instance. \
 *size* Receives the size of the bitset in bits.

**Returns**

A zyan status code.

### ZYCORE\_EXPORT ZyanStatus ZyanBitsetGetSizeBytes (const ZyanBitset \* bitset, ZyanUSize \* size)

Returns the current size of the bitset in bytes.

**Parameters**

*bitset* A pointer to the `ZyanBitset` instance. \
 *size* Receives the size of the bitset in bytes.

**Returns**

A zyan status code.

### ZYCORE\_EXPORT ZYAN\_REQUIRES\_LIBC ZyanStatus ZyanBitsetInit (ZyanBitset \* bitset, ZyanUSize count)

Initializes the given `ZyanBitset` instance.

**Parameters**

*bitset* A pointer to the `ZyanBitset` instance. \
 *count* The initial amount of bits.

**Returns**

A zyan status code.

The space for the bitset is dynamically allocated by the default allocator using the default growth factor and the default shrink threshold.

### ZYCORE\_EXPORT ZyanStatus ZyanBitsetInitBuffer (ZyanBitset \* bitset, ZyanUSize count, void \* buffer, ZyanUSize capacity)

Initializes the given `ZyanBitset` instance and configures it to use a custom user defined buffer with a fixed size.

**Parameters**

*bitset* A pointer to the `ZyanBitset` instance. \
 *count* The initial amount of bits. \
 *buffer* A pointer to the buffer that is used as storage for the bits. \
 *capacity* The maximum capacity (number of bytes) of the buffer.

**Returns**

A zyan status code.

### ZYCORE\_EXPORT ZyanStatus ZyanBitsetInitEx (ZyanBitset \* bitset, ZyanUSize count, ZyanAllocator \* allocator, ZyanU8 growth\_factor, ZyanU8 shrink\_threshold)

Initializes the given `ZyanBitset` instance and sets a custom `allocator` and memory allocation/deallocation parameters.

**Parameters**

*bitset* A pointer to the `ZyanBitset` instance. \
 *count* The initial amount of bits. \
 *allocator* A pointer to a `ZyanAllocator` instance. \
 *growth\_factor* The growth factor. \
 *shrink\_threshold* The shrink threshold.

**Returns**

A zyan status code.

A growth factor of `1` disables overallocation and a shrink threshold of `0` disables dynamic shrinking.

### ZYCORE\_EXPORT ZyanStatus ZyanBitsetNone (const ZyanBitset \* bitset)

Checks, if none bits of the given bitset are set.

**Parameters**

*bitset* A pointer to the `ZyanBitset` instance.

**Returns**

`ZYAN_STATUS_TRUE`, if none bits are set, `ZYAN_STATUS_FALSE`, if not. Another zyan status code, if an error occurred.

### ZYCORE\_EXPORT ZyanStatus ZyanBitsetOR (ZyanBitset \* destination, const ZyanBitset \* source)

Performs a logical `OR` operation on the given `ZyanBitset` instances.

**Parameters**

*destination* A pointer to the `ZyanBitset` instance that is used as the first input and as the destination. \
 *source* A pointer to the `ZyanBitset` instance that is used as the second input.

**Returns**

A zyan status code.

If the destination bitmask contains more bits than the source one, the state of the remaining bits will be undefined.

### ZYCORE\_EXPORT ZyanStatus ZyanBitsetPerformByteOperation (ZyanBitset \* destination, const ZyanBitset \* source, ZyanBitsetByteOperation operation)

Performs a byte-wise `operation` for every byte in the given `ZyanBitset` instances.

**Parameters**

*destination* A pointer to the `ZyanBitset` instance that is used as the first input and as the destination. \
 *source* A pointer to the `ZyanBitset` instance that is used as the second input. \
 *operation* A pointer to the function that performs the desired operation.

**Returns**

A zyan status code.

The `operation` callback is invoked once for every byte in the smallest of the `ZyanBitset` instances.

### ZYCORE\_EXPORT ZyanStatus ZyanBitsetPop (ZyanBitset \* bitset)

Removes the last bit of the bitset.

**Parameters**

*bitset* A pointer to the `ZyanBitset` instance.

**Returns**

A zyan status code.

### ZYCORE\_EXPORT ZyanStatus ZyanBitsetPush (ZyanBitset \* bitset, ZyanBool value)

Adds a new bit at the end of the bitset.

**Parameters**

*bitset* A pointer to the `ZyanBitset` instance. \
 *value* The value of the new bit.

**Returns**

A zyan status code.

### ZYCORE\_EXPORT ZyanStatus ZyanBitsetReserve (ZyanBitset \* bitset, ZyanUSize count)

Changes the capacity of the given `ZyanBitset` instance.

**Parameters**

*bitset* A pointer to the `ZyanBitset` instance. \
 *count* The new capacity (number of bits).

**Returns**

A zyan status code.

### ZYCORE\_EXPORT ZyanStatus ZyanBitsetReset (ZyanBitset \* bitset, ZyanUSize index)

Sets the bit at `index` of the given `ZyanBitset` instance to `0`.

**Parameters**

*bitset* A pointer to the `ZyanBitset` instance. \
 *index* The bit index.

**Returns**

A zyan status code.

### ZYCORE\_EXPORT ZyanStatus ZyanBitsetResetAll (ZyanBitset \* bitset)

Sets all bits of the given `ZyanBitset` instance to `0`.

**Parameters**

*bitset* A pointer to the `ZyanBitset` instance.

**Returns**

A zyan status code.

### ZYCORE\_EXPORT ZyanStatus ZyanBitsetSet (ZyanBitset \* bitset, ZyanUSize index)

Sets the bit at `index` of the given `ZyanBitset` instance to `1`.

**Parameters**

*bitset* A pointer to the `ZyanBitset` instance. \
 *index* The bit index.

**Returns**

A zyan status code.

### ZYCORE\_EXPORT ZyanStatus ZyanBitsetSetAll (ZyanBitset \* bitset)

Sets all bits of the given `ZyanBitset` instance to `1`.

**Parameters**

*bitset* A pointer to the `ZyanBitset` instance.

**Returns**

A zyan status code.

### ZYCORE\_EXPORT ZyanStatus ZyanBitsetShrinkToFit (ZyanBitset \* bitset)

Shrinks the capacity of the given bitset to match it's size.

**Parameters**

*bitset* A pointer to the `ZyanBitset` instance.

**Returns**

A zyan status code.

### ZYCORE\_EXPORT ZyanStatus ZyanBitsetTest (ZyanBitset \* bitset, ZyanUSize index)

Returns the value of the bit at `index`.

**Parameters**

*bitset* A pointer to the `ZyanBitset` instance. \
 *index* The bit index.

**Returns**

`ZYAN_STATUS_TRUE`, if the bit is set or `ZYAN_STATUS_FALSE`, if not, Another zyan status code, if an error occurred.

### ZYCORE\_EXPORT ZyanStatus ZyanBitsetTestLSB (ZyanBitset \* bitset)

Returns the value of the least significant bit.

**Parameters**

*bitset* A pointer to the `ZyanBitset` instance.

**Returns**

`ZYAN_STATUS_TRUE`, if the bit is set or `ZYAN_STATUS_FALSE`, if not. Another zyan status code, if an error occurred.

### ZYCORE\_EXPORT ZyanStatus ZyanBitsetTestMSB (ZyanBitset \* bitset)

Returns the value of the most significant bit.

**Parameters**

*bitset* A pointer to the `ZyanBitset` instance.

**Returns**

`ZYAN_STATUS_TRUE`, if the bit is set or `ZYAN_STATUS_FALSE`, if not. Another zyan status code, if an error occurred.

### ZYCORE\_EXPORT ZyanStatus ZyanBitsetToggle (ZyanBitset \* bitset, ZyanUSize index)

Toggles the bit at `index` of the given `ZyanBitset` instance.

**Parameters**

*bitset* A pointer to the `ZyanBitset` instance. \
 *index* The bit index.

**Returns**

A zyan status code.

### ZYCORE\_EXPORT ZyanStatus ZyanBitsetXOR (ZyanBitset \* destination, const ZyanBitset \* source)

Performs a logical `XOR` operation on the given `ZyanBitset` instances.

**Parameters**

*destination* A pointer to the `ZyanBitset` instance that is used as the first input and as the destination. \
 *source* A pointer to the `ZyanBitset` instance that is used as the second input.

**Returns**

A zyan status code.

If the destination bitmask contains more bits than the source one, the state of the remaining bits will be undefined.

## Author

Generated automatically by Doxygen for Zycore from the source code.
