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 to 1. ✨
  • ba_clear β€” clears one element (sets it to 0). πŸ™ˆ
  • 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 says ba_or_ba twice instead of ba_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 or NULL, or -1 vs 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