Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 50 additions & 12 deletions distr/flecs.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,59 +49,97 @@
extern "C" {
#endif

/** A bitset data structure for compact boolean storage. */
typedef struct ecs_bitset_t {
uint64_t *data;
int32_t count;
ecs_size_t size;
uint64_t *data; /**< Array of 64-bit words storing the bits. */
int32_t count; /**< Number of bits in the bitset. */
ecs_size_t size; /**< Allocated capacity in 64-bit words. */
} ecs_bitset_t;

/** Initialize bitset. */
/** Initialize a bitset.
*
* @param bs The bitset to initialize.
*/
FLECS_DBG_API
void flecs_bitset_init(
ecs_bitset_t *bs);

/** Deinitialize bitset. */
/** Deinitialize a bitset.
*
* @param bs The bitset to deinitialize.
*/
FLECS_DBG_API
void flecs_bitset_fini(
ecs_bitset_t *bs);

/** Add n elements to bitset. */
/** Add n elements to a bitset.
*
* @param bs The bitset to add to.
* @param count Number of bits to add.
*/
FLECS_DBG_API
void flecs_bitset_addn(
ecs_bitset_t *bs,
int32_t count);

/** Ensure element exists. */
/** Ensure an element exists.
*
* @param bs The bitset to ensure capacity for.
* @param count Minimum number of bits the bitset must hold.
*/
FLECS_DBG_API
void flecs_bitset_ensure(
ecs_bitset_t *bs,
int32_t count);

/** Set element. */
/** Set an element.
*
* @param bs The bitset to modify.
* @param elem Index of the bit to set.
* @param value The boolean value to set.
*/
FLECS_DBG_API
void flecs_bitset_set(
ecs_bitset_t *bs,
int32_t elem,
bool value);

/** Get element. */
/** Get an element.
*
* @param bs The bitset to read from.
* @param elem Index of the bit to get.
* @return The boolean value of the bit.
*/
FLECS_DBG_API
bool flecs_bitset_get(
const ecs_bitset_t *bs,
int32_t elem);

/** Return number of elements. */
/** Return the number of elements.
*
* @param bs The bitset.
* @return The number of bits in the bitset.
*/
FLECS_DBG_API
int32_t flecs_bitset_count(
const ecs_bitset_t *bs);

/** Remove from bitset. */
/** Remove from a bitset.
*
* @param bs The bitset to remove from.
* @param elem Index of the bit to remove.
*/
FLECS_DBG_API
void flecs_bitset_remove(
ecs_bitset_t *bs,
int32_t elem);

/** Swap values in bitset. */
/** Swap values in a bitset.
*
* @param bs The bitset.
* @param elem_a Index of the first bit to swap.
* @param elem_b Index of the second bit to swap.
*/
FLECS_DBG_API
void flecs_bitset_swap(
ecs_bitset_t *bs,
Expand Down
Loading
Loading