2021-11-06 15:27:13 +00:00
|
|
|
#pragma once
|
|
|
|
#include <stddef.h>
|
|
|
|
#include <stdint.h>
|
|
|
|
|
|
|
|
inline void bitmap_set( uint32_t* map , int index )
|
|
|
|
{
|
|
|
|
map[index/32] |= (1 << (index % 32));
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void bitmap_unset(uint32_t* map , int index)
|
|
|
|
{
|
|
|
|
map[index/32] &= ~(1 << (index % 32));
|
|
|
|
}
|
|
|
|
|
2022-02-26 19:44:16 +00:00
|
|
|
inline uint32_t bitmap_first_unset( uint32_t* map , int map_size)
|
2021-11-06 15:27:13 +00:00
|
|
|
{
|
2022-02-26 19:44:16 +00:00
|
|
|
for ( int i = 0 ; i < map_size ; i ++ )
|
2021-11-06 15:27:13 +00:00
|
|
|
{
|
2022-02-26 19:44:16 +00:00
|
|
|
// a bit or more is set within this byte!
|
|
|
|
if( (map[i] & 0xFFFFFFFF) > 0 ){
|
|
|
|
|
|
|
|
// which bit is set?
|
|
|
|
for(int j = 0 ; j < 32 ; j++){
|
|
|
|
if ( (map[i] & (0x00000001 << j)) > 0)
|
|
|
|
{
|
|
|
|
return (i*32)+j;
|
2021-11-06 15:27:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-02-26 19:44:16 +00:00
|
|
|
|
2021-11-06 15:27:13 +00:00
|
|
|
}
|
2022-02-26 19:44:16 +00:00
|
|
|
|
|
|
|
|
2021-11-06 15:27:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
}
|