BITARR(3pub)
π BITARR(3pub) β bit array manipulation π
okay so bestie, welcome to BITARR from the C Programmer's Manual β it's a whole little family of functions for wrangling bit arrays, and honestly? it's giving tiny-but-mighty. let's get into it π¦
β¨ NAME β¨
ba_and_ba, ba_clear, ba_clear_all, ba_copy, ba_create, ba_destroy, ba_not, ba_or_ba, ba_or_not_ba, ba_query, ba_resize, ba_set, ba_xor_ba β bit array manipulation π
π SYNOPSIS π
#include <bitarr.h>
Bitarr *ba_create(void);
void ba_destroy(Bitarr *ba);
Bitarr *ba_copy(const Bitarr *ba);
int ba_resize(Bitarr *ba, size_t max_number);
int ba_set(Bitarr *ba, unsigned number);
int ba_clear(Bitarr *ba, unsigned number);
void ba_clear_all(Bitarr *ba);
int ba_query(Bitarr *ba, unsigned number);
void ba_and_ba(Bitarr *ba1, const Bitarr *ba2);
int ba_or_ba(Bitarr *ba1, const Bitarr *ba2);
void ba_xor_ba(Bitarr *ba1, const Bitarr *ba2);
void ba_or_not_ba(Bitarr *ba1, const Bitarr *ba2);
void ba_not(Bitarr *ba);
π DESCRIPTION π
These functions operate on bit arrays. ba_create creates one and ba_destroy it. ba_copy makes a copy of one, and ba_resize changes its size. The bit arrays resize themselves automatically, but ba_resize can be used to get rid of extra memory allocated for the array, or to make sure there is enough memory allocated for the array (so that further operations are guaranteed to work).
lowkey the auto-resize is doing the most so you don't have to, but ba_resize is your girl when you want to tighten things up or lock in enough room ahead of time π«Ά
ba_setβ sets one element (bit) in the array to1. β¨ba_clearβ clears one element (sets it to0). πba_clear_allβ clears all elements. πba_queryβ returns the current value of an element. π
ba_and_ba, ba_or_ba, ba_xor_ba, and ba_or_ba do logical operations on two arrays. The result will be stored in the first one. ba_not will invert all elements in the array.
not me noticing the original list saysba_or_batwice instead ofba_or_not_baβ i'm just relaying it exactly as written, bestie, no notes, we don't gatekeep πΈ
β RETURNS β
ba_create and ba_copy return a pointer to the new array, or NULL if they fail. Those that return an integer, return -1 for error, non-negative for success.
so like: pointer orNULL, or-1vs non-negative. check your returns, fr fr, it's not that deep but it IS that important π
π SEE ALSO π
π AUTHOR π
Lars Wirzenius (lars.wirzenius@helsinki.fi)
and that's the whole page, bestie π this one came from Publib's C Programmer's Manual, filed under BITARR(3pub) β slay, ate, periodt π
β¨
π¦ where this page comes from
- debian bookworm: publib-dev 0.40-3+b1 Β· BSD-2-Clause
- debian trixie: publib-dev 0.40-4 Β· BSD-2-Clause
- ubuntu jammy: publib-dev 0.40-3build1 Β· BSD-2-Clause
- ubuntu noble: publib-dev 0.40-3build1 Β· BSD-2-Clause
- ubuntu questing: publib-dev 0.40-4
- ubuntu resolute: publib-dev 0.40-4build1 Β· BSD-2-Clause
- ubuntu stonking: publib-dev 0.40-4build1 Β· BSD-2-Clause
- Copyright (c) 1994-2006 Lars Wirzenius. All rights reserved
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms