|
rlib
Convenience library for useful things
|
Fixed-width bitset with bit / byte / word accessors and bitwise compound operations. More...
Go to the source code of this file.
Data Structures | |
| struct | RBitset |
| Fixed-width bitset. More... | |
Macros | |
| #define | r_bitset_init_stack(BS, BITS) |
Stack-allocate an RBitset of BITS bits via alloca. | |
| #define | r_bitset_init_heap(BS, BITS) |
Heap-allocate an RBitset of BITS bits; caller frees with r_free. | |
| #define | r_bitset_clear(bs) r_bitset_set_all (bs, FALSE) |
| Convenience: clear every bit. | |
| #define | r_bitset_inv(bs) r_bitset_not (bs, bs) |
| Convenience: in-place complement. | |
Typedefs | |
| typedef ruint64 | rbsword |
| Machine word backing RBitset storage (64 bits). | |
| typedef void(* | RBitsetFunc) (rsize bit, rpointer user) |
| Per-bit visitor signature for r_bitset_foreach. | |
Functions | |
| RBitset * | r_bitset_new_from_binary (rconstpointer data, rsize size) |
| Allocate a bitset from a packed binary blob. | |
| rboolean | r_bitset_copy (RBitset *dest, const RBitset *src) |
Copy src into dest (both must have the same bit count). | |
| rboolean | r_bitset_set_bit (RBitset *bitset, rsize bit, rboolean set) |
| Set or clear a single bit. | |
| rboolean | r_bitset_set_bits (RBitset *bitset, const rsize *bits, rsize count, rboolean set) |
Set or clear each bit listed in bits. | |
| rboolean | r_bitset_set_all (RBitset *bitset, rboolean set) |
Set every bit to set. | |
| rboolean | r_bitset_set_n_bits_at (RBitset *bitset, rsize n, rsize bit, rboolean set) |
Set or clear n consecutive bits starting at bit. | |
| rboolean | r_bitset_set_u8_at (RBitset *bitset, ruint8 u8, rsize bit) |
Write an 8-bit value starting at bit position bit. | |
| rboolean | r_bitset_set_u16_at (RBitset *bitset, ruint16 u16, rsize bit) |
Write a 16-bit value starting at bit position bit. | |
| rboolean | r_bitset_set_u32_at (RBitset *bitset, ruint32 u32, rsize bit) |
Write a 32-bit value starting at bit position bit. | |
| rboolean | r_bitset_set_u64_at (RBitset *bitset, ruint64 u64, rsize bit) |
Write a 64-bit value starting at bit position bit. | |
| rboolean | r_bitset_set_from_human_readable (RBitset *bitset, const rchar *str, rsize *bits) |
Parse a human-readable bitset spec (e.g. "0,3-5,17") into bitset. | |
| rboolean | r_bitset_set_from_human_readable_file (RBitset *bitset, const rchar *file, rsize *bits) |
Same as r_bitset_set_from_human_readable but reads the spec from file. | |
| rboolean | r_bitset_shr (RBitset *a, ruint count) |
In-place right shift by count bits. | |
| rboolean | r_bitset_shl (RBitset *a, ruint count) |
In-place left shift by count bits. | |
| ruint8 | r_bitset_get_u8_at (const RBitset *bitset, rsize bit) |
Read an 8-bit value starting at bit position bit. | |
| ruint16 | r_bitset_get_u16_at (const RBitset *bitset, rsize bit) |
Read a 16-bit value starting at bit position bit. | |
| ruint32 | r_bitset_get_u32_at (const RBitset *bitset, rsize bit) |
Read a 32-bit value starting at bit position bit. | |
| ruint64 | r_bitset_get_u64_at (const RBitset *bitset, rsize bit) |
Read a 64-bit value starting at bit position bit. | |
| rchar * | r_bitset_to_human_readable (const RBitset *bitset) |
Render the set bits as a human-readable string (e.g. "0,3-5,17"). | |
| rboolean | r_bitset_is_bit_set (const RBitset *bitset, rsize bit) |
TRUE iff bit is set. | |
| rsize | r_bitset_popcount (const RBitset *bitset) |
| Number of set bits. | |
| rsize | r_bitset_clz (const RBitset *bitset) |
| Count leading zeros (from the high bit). | |
| rsize | r_bitset_ctz (const RBitset *bitset) |
| Count trailing zeros (from bit 0). | |
| void | r_bitset_foreach (const RBitset *bitset, rboolean set, RBitsetFunc func, rpointer user) |
Invoke func once for every bit equal to set (TRUE = visit set bits, FALSE = visit clear bits). | |
| rboolean | r_bitset_not (RBitset *dest, const RBitset *src) |
dest = ~src. | |
| rboolean | r_bitset_or (RBitset *dest, const RBitset *a, const RBitset *b) |
dest = a | b. | |
| rboolean | r_bitset_xor (RBitset *dest, const RBitset *a, const RBitset *b) |
dest = a ^ b. | |
| rboolean | r_bitset_and (RBitset *dest, const RBitset *a, const RBitset *b) |
dest = a & b. | |
Fixed-width bitset with bit / byte / word accessors and bitwise compound operations.