20#ifndef LIBALGO_BITMAP_H
21#define LIBALGO_BITMAP_H
23#include <kernel/types.h>
25#include <utils/bits.h>
26#include <utils/compiler.h>
43#define BITMAP_BLOCK_SIZE (8 * sizeof(bitmap_block_t))
45#define BITMAP_OFFSET(_index) ((_index) / BITMAP_BLOCK_SIZE)
48#define BITMAP(_name, _size) \
49 bitmap_block_t _name[BITMAP_OFFSET(NON_ZERO(_size) - 1) + 1]
60 return BIT_READ(bitmap[BITMAP_OFFSET(index)], index % BITMAP_BLOCK_SIZE);
70 BIT_SET(bitmap[BITMAP_OFFSET(index)], index % BITMAP_BLOCK_SIZE);
80 BIT_CLEAR(bitmap[BITMAP_OFFSET(index)], index % BITMAP_BLOCK_SIZE);
88static ALWAYS_INLINE
void
static ALWAYS_INLINE void bitmap_assign(bitmap_t bitmap, uint32_t index, bool value)
Set a value at a given index inside a bitmap to the given value.
Definition: bitmap.h:89
static ALWAYS_INLINE void bitmap_clear(bitmap_t bitmap, uint32_t index)
Set a value at a given index inside a bitmap as absent.
Definition: bitmap.h:78
static ALWAYS_INLINE void bitmap_set(bitmap_t bitmap, uint32_t index)
Set a value at a given index inside a bitmap as present.
Definition: bitmap.h:68
native_t bitmap_block_t
Basic unit used by the bitmap.
Definition: bitmap.h:36
bitmap_block_t * bitmap_t
A bitmap instance A bitmap is just a simple list of bytes (bitmap_block_t)
Definition: bitmap.h:41
static ALWAYS_INLINE bool bitmap_read(const bitmap_t bitmap, uint32_t index)
Read the value at a given index inside a bitmap.
Definition: bitmap.h:58
#define BIT_SET(_var, _n)
Set the nth bit.
Definition: bits.h:27
#define BIT_CLEAR(_var, _n)
Clear the nth bit.
Definition: bits.h:24
#define BIT_READ(_x, _n)
Read the nth bit.
Definition: bits.h:30