Barrelfish
Macros | Typedefs | Functions
bitmap.c File Reference

General Numa functions. More...

Macros

#define BITMAP_BITS_PER_ELEMENT   (8 * sizeof(bitmap_data_t))
 helper macro for determining the number of
 

Typedefs

typedef uint32_t bitmap_data_t
 < the bitmap data type to store the bitmap elements More...
 

Functions

struct bitmap * bitmap_alloc (uint32_t nbits)
 allocates a new bitmap of a given size More...
 
void bitmap_free (struct bitmap *bm)
 frees the resources of a bitmap More...
 
size_t bitmap_format (char *outbuf, size_t length, struct bitmap *bm, uint8_t hex)
 formats the contents of the bitmap into the outbut buffer More...
 
size_t bitmap_parse (struct bitmap *outbm, char *inbuf, size_t length, uint8_t hex)
 parses an input string and stores it into the bitmap More...
 
errval_t bitmap_serialize (void *dest, size_t length, const struct bitmap *bm)
 serializes the bitmap into a buffer More...
 
errval_t bitmap_deserialize (struct bitmap *bm, const void *src, size_t length)
 deserializes a bitmap form a buffer More...
 
uint32_t bitmap_get_nbytes (const struct bitmap *bm)
 returns the number of bytes in the bitmap data representation More...
 
uint32_t bitmap_get_nbits (const struct bitmap *bm)
 gets the number of bits of this bitmap More...
 
uint32_t bitmap_get_weight (const struct bitmap *bm)
 gets the weight of the bit map i.e. number of set bits More...
 
void * bitmap_raw (struct bitmap *bm)
 returns a pointer to the raw bitmap More...
 
bool bitmap_is_bit_set (const struct bitmap *bm, bitmap_bit_t i)
 ckecks if a given bit is set More...
 
bool bitmap_is_bit_clear (const struct bitmap *bm, bitmap_bit_t i)
 ckecks if a given bit is cleare More...
 
bool bitmap_is_all_set (const struct bitmap *bm)
 checks if all bits are set More...
 
bool bitmap_is_all_clear (const struct bitmap *bm)
 checks if all bits are clear More...
 
bitmap_bit_t bitmap_get_first (const struct bitmap *bm)
 returns the bit number of the first set More...
 
bitmap_bit_t bitmap_get_last (const struct bitmap *bm)
 returns the bit number of the last set More...
 
bitmap_bit_t bitmap_get_next (const struct bitmap *bm, bitmap_bit_t i)
 gets the index of the next bit set More...
 
bitmap_bit_t bitmap_get_prev (const struct bitmap *bm, bitmap_bit_t i)
 gets the index of the previous bit set More...
 
void bitmap_set_bit (struct bitmap *bm, bitmap_bit_t i)
 sets a bit in the bitmap More...
 
void bitmap_clear_bit (struct bitmap *bm, bitmap_bit_t i)
 clears a bit in the bitmap More...
 
void bitmap_set_all (struct bitmap *bm)
 sets all the bits in the bitmap More...
 
void bitmap_clear_all (struct bitmap *bm)
 clears all the bits in the bitmap More...
 
void bitmap_set_range (struct bitmap *bm, bitmap_bit_t from, bitmap_bit_t to)
 sets a range of bits in the bitmap More...
 
void bitmap_clear_range (struct bitmap *bm, bitmap_bit_t from, bitmap_bit_t to)
 sets a range of bits in the bitmap More...
 
void bitmap_keep_range (struct bitmap *bm, uint32_t from, uint32_t to)
 clears the bitmap except for the given range More...
 
void bitmap_copy (struct bitmap *to, const struct bitmap *from)
 copies one bitmap onto another More...
 
bool bitmap_equal (const struct bitmap *bm1, const struct bitmap *bm2)
 determines if two bitmaps are equal More...
 
bool bitmap_subset (const struct bitmap *haystack, const struct bitmap *needle)
 determines if one bitmask is a subset of the other More...
 
bool bitmap_disjoint (const struct bitmap *bm1, const struct bitmap *bm2)
 determines if two bitmaps are disjoint i.e. not sharing a set bit More...
 
bool bitmap_intersects (const struct bitmap *bm1, const struct bitmap *bm2)
 determines if two bitmaps are intersecting i.e. sharing a set bit More...
 
void bitmap_complement (struct bitmap *bm)
 computes the complement to the bitmap More...
 
void bitmap_shift_right (struct bitmap *bm, bitmap_bit_t n)
 performs a right shift operation on the bitmap More...
 
void bitmap_shift_left (struct bitmap *bm, bitmap_bit_t n)
 performs a left shift operation on the bitmap More...
 
void bitmap_and (struct bitmap *dst, const struct bitmap *src)
 performs a logical AND operation between two bitmaps More...
 
void bitmap_nand (struct bitmap *dst, const struct bitmap *src)
 performs a logical NAND operation between two bitmaps More...
 
void bitmap_or (struct bitmap *dst, const struct bitmap *src)
 performs a logical OR operation between two bitmaps More...
 
void bitmap_xor (struct bitmap *dst, const struct bitmap *src)
 performs a logical AND operation between two bitmaps More...
 

Detailed Description

General Numa functions.

Typedef Documentation

typedef uint32_t bitmap_data_t

< the bitmap data type to store the bitmap elements

helper macro for

Function Documentation

struct bitmap* bitmap_alloc ( uint32_t  nbits)

allocates a new bitmap of a given size

Parameters
nbitssize of the bitmap
Returns
pointer to the allocated bitmap on success NULL on failure
void bitmap_and ( struct bitmap *  dst,
const struct bitmap *  src 
)

performs a logical AND operation between two bitmaps

Parameters
dstdestination to store the new bitmap
srcsource bitmap

dst = dst AND src

void bitmap_clear_all ( struct bitmap *  bm)

clears all the bits in the bitmap

Parameters
bmbitmap to clear all bits
void bitmap_clear_bit ( struct bitmap *  bm,
bitmap_bit_t  i 
)

clears a bit in the bitmap

Parameters
bmbitmap to set the bit
iindex of the bit to clear
void bitmap_clear_range ( struct bitmap *  bm,
bitmap_bit_t  from,
bitmap_bit_t  to 
)

sets a range of bits in the bitmap

Parameters
bmbitmap to set the range
fromstart of the range (including)
toend of the range (including)
void bitmap_complement ( struct bitmap *  bm)

computes the complement to the bitmap

Parameters
bmthe bitmap
void bitmap_copy ( struct bitmap *  to,
const struct bitmap *  from 
)

copies one bitmap onto another

Parameters
tobitmap to copy into
frombitmap to copy from

only the minimum number of bits in both bitmaps are copied. If the source is smaller than the destination remaining bits are cleared

errval_t bitmap_deserialize ( struct bitmap *  bm,
const void *  src,
size_t  length 
)

deserializes a bitmap form a buffer

Parameters
bmbitmap to store the serialized data
srcsource buffer to read the serialized data from
lengthlength of the source buffer
Returns
SYS_ERR_OK on success errval on failure
bool bitmap_disjoint ( const struct bitmap *  bm1,
const struct bitmap *  bm2 
)

determines if two bitmaps are disjoint i.e. not sharing a set bit

Parameters
bm1the first bitmap
bm2the second bitmap
Returns
TRUE if the two bitmaps are disjoint FALSE otherwise
bool bitmap_equal ( const struct bitmap *  bm1,
const struct bitmap *  bm2 
)

determines if two bitmaps are equal

Parameters
bm1the first bitmap
bm2the second bitmap
Returns
TRUE if the two bitmaps are equal FALSE otherwise
size_t bitmap_format ( char *  outbuf,
size_t  length,
struct bitmap *  bm,
uint8_t  hex 
)

formats the contents of the bitmap into the outbut buffer

Parameters
outbufbuffer to hold the output data
lengthlength of the output buffer
bmbitmap to format
hexflag to enable hexadecimal formatted output
Returns
number of bytes written into the buffer
void bitmap_free ( struct bitmap *  bm)

frees the resources of a bitmap

Parameters
bmbitmap to be freed
bitmap_bit_t bitmap_get_first ( const struct bitmap *  bm)

returns the bit number of the first set

Parameters
bmbitmap to get the first set bit
Returns
index of the first bit BITMAP_BIT_NONE if there is no bit set
bitmap_bit_t bitmap_get_last ( const struct bitmap *  bm)

returns the bit number of the last set

Parameters
bmbitmap to get the last set bit
Returns
index of the last bit BITMAP_BIT_NONE if there is no bit set
uint32_t bitmap_get_nbits ( const struct bitmap *  bm)

gets the number of bits of this bitmap

Parameters
bmthe bitmap
Returns
size of the bitmap in bits
uint32_t bitmap_get_nbytes ( const struct bitmap *  bm)

returns the number of bytes in the bitmap data representation

Parameters
bmbitmap to determine the bytes for
Returns
size of the bitmap in bytes
bitmap_bit_t bitmap_get_next ( const struct bitmap *  bm,
bitmap_bit_t  i 
)

gets the index of the next bit set

Parameters
bmthe bitmap to check
ibit to start checking from (not inclusive)
Returns
index of the next set bit BITMAP_BIT_NONE if none is set
bitmap_bit_t bitmap_get_prev ( const struct bitmap *  bm,
bitmap_bit_t  i 
)

gets the index of the previous bit set

Parameters
bmthe bitmap to check
iindex of the bit to check
Returns
index of the next set bit BITMAP_BIT_NONE if none is set
uint32_t bitmap_get_weight ( const struct bitmap *  bm)

gets the weight of the bit map i.e. number of set bits

Parameters
bmthe bitmap
Returns
number of set bits
bool bitmap_intersects ( const struct bitmap *  bm1,
const struct bitmap *  bm2 
)

determines if two bitmaps are intersecting i.e. sharing a set bit

Parameters
bm1the first bitmap
bm2the second bitmap
Returns
TRUE if the two bitmaps are equal FALSE otherwise
bool bitmap_is_all_clear ( const struct bitmap *  bm)

checks if all bits are clear

Parameters
bmbitmap to check
Returns
TRUE iff all bits are clear FALSE otherwise
bool bitmap_is_all_set ( const struct bitmap *  bm)

checks if all bits are set

Parameters
bmbitmap to check
Returns
TRUE iff all bits are set FALSE otherwise
bool bitmap_is_bit_clear ( const struct bitmap *  bm,
bitmap_bit_t  i 
)

ckecks if a given bit is cleare

Parameters
bmbitmap to check
iindex of the bit
Returns
TRUE iff the bit is clear FALSE otherwise
bool bitmap_is_bit_set ( const struct bitmap *  bm,
bitmap_bit_t  i 
)

ckecks if a given bit is set

Parameters
bmbitmap to check
iindex of the bit
Returns
TRUE iff the bit is set FALSE otherwise (also if bit index exceeds bitmap size)
void bitmap_keep_range ( struct bitmap *  bm,
uint32_t  from,
uint32_t  to 
)

clears the bitmap except for the given range

Parameters
bmbitmap to set the range
fromstart of the range (including)
toend of the range (including)
void bitmap_nand ( struct bitmap *  dst,
const struct bitmap *  src 
)

performs a logical NAND operation between two bitmaps

Parameters
dstdestination to store the new bitmap
srcsource bitmap

dst = dst NAND src

void bitmap_or ( struct bitmap *  dst,
const struct bitmap *  src 
)

performs a logical OR operation between two bitmaps

Parameters
dstdestination to store the new bitmap
srcsource bitmap

dst = dst OR src

size_t bitmap_parse ( struct bitmap *  outbm,
char *  inbuf,
size_t  length,
uint8_t  hex 
)

parses an input string and stores it into the bitmap

Parameters
outbmbitmap to store the parsed data into
inbufinput string buffer
lengthlength of the input string buffer
hexparse input as hex
Returns
number of bytes parsed from the input string
void* bitmap_raw ( struct bitmap *  bm)

returns a pointer to the raw bitmap

Parameters
bmthe bitmap
Returns
Pointer to the raw bitmap
errval_t bitmap_serialize ( void *  dest,
size_t  length,
const struct bitmap *  bm 
)

serializes the bitmap into a buffer

Parameters
destbuffer to store the serialized bitmap
lengthlenght ouf the buffer
bmbitmap to serialize
Returns
void bitmap_set_all ( struct bitmap *  bm)

sets all the bits in the bitmap

Parameters
bmbitmap to set all bits
void bitmap_set_bit ( struct bitmap *  bm,
bitmap_bit_t  i 
)

sets a bit in the bitmap

Parameters
bmbitmap to set the bit
iindex of the bit to set
void bitmap_set_range ( struct bitmap *  bm,
bitmap_bit_t  from,
bitmap_bit_t  to 
)

sets a range of bits in the bitmap

Parameters
bmbitmap to set the range
fromstart of the range (including)
toend of the range (including)
void bitmap_shift_left ( struct bitmap *  bm,
bitmap_bit_t  n 
)

performs a left shift operation on the bitmap

Parameters
bmthe bitmap
nnumber of bits to shift
void bitmap_shift_right ( struct bitmap *  bm,
bitmap_bit_t  n 
)

performs a right shift operation on the bitmap

Parameters
bmthe bitmap
nnumber of bits to shift
bool bitmap_subset ( const struct bitmap *  haystack,
const struct bitmap *  needle 
)

determines if one bitmask is a subset of the other

Parameters
haystackthe original bitmap
needlethe potential subset bitmap
Returns
TRUE if the second bitmap is a subset of the other FALSE otherwise
void bitmap_xor ( struct bitmap *  dst,
const struct bitmap *  src 
)

performs a logical AND operation between two bitmaps

Parameters
dstdestination to store the new bitmap
srcsource bitmap

dst = dst XOR src