bitmap 1
This commit is contained in:
parent
ab3ae686bb
commit
a3da87ad75
6 changed files with 27 additions and 1 deletions
|
|
@ -6,12 +6,14 @@ set(HEADERS
|
||||||
cutil.h
|
cutil.h
|
||||||
list.h
|
list.h
|
||||||
array.h
|
array.h
|
||||||
|
bitmap.h
|
||||||
)
|
)
|
||||||
|
|
||||||
set(SOURCES
|
set(SOURCES
|
||||||
cutil.c
|
cutil.c
|
||||||
list.c
|
list.c
|
||||||
array.c
|
array.c
|
||||||
|
bitmap.c
|
||||||
)
|
)
|
||||||
|
|
||||||
add_library(cutil STATIC ${SOURCES} ${HEADERS})
|
add_library(cutil STATIC ${SOURCES} ${HEADERS})
|
||||||
|
|
|
||||||
2
array.c
2
array.c
|
|
@ -23,7 +23,7 @@ void array_clear(array_t* array)
|
||||||
|
|
||||||
uint array_align(array_t* array, uint count)
|
uint array_align(array_t* array, uint count)
|
||||||
{
|
{
|
||||||
return (count / array->align + !!(count % array->align)) * array->align;
|
return cu_align(count, array->align);
|
||||||
}
|
}
|
||||||
|
|
||||||
void array_resize(array_t* array, uint newCount)
|
void array_resize(array_t* array, uint newCount)
|
||||||
|
|
|
||||||
8
bitmap.c
Normal file
8
bitmap.c
Normal file
|
|
@ -0,0 +1,8 @@
|
||||||
|
#include "bitmap.h"
|
||||||
|
|
||||||
|
uint bit_log2(uint64_t value)
|
||||||
|
{
|
||||||
|
uint pow2 = 0;
|
||||||
|
while (value>>=1) pow2++;
|
||||||
|
return pow2;
|
||||||
|
}
|
||||||
9
bitmap.h
Normal file
9
bitmap.h
Normal file
|
|
@ -0,0 +1,9 @@
|
||||||
|
#ifndef __BITMAP_H
|
||||||
|
#define __BITMAP_H
|
||||||
|
|
||||||
|
#include "cutypes.h"
|
||||||
|
|
||||||
|
#define bit_align2(v, p) (((v>>p)+!!(v&((1<<p)-1)))<<p)
|
||||||
|
uint bit_log2(uint64_t value);
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
@ -10,4 +10,6 @@ typedef unsigned int uint;
|
||||||
typedef void* cu_ptr;
|
typedef void* cu_ptr;
|
||||||
#define CU_PTR_SIZE sizeof(cu_ptr)
|
#define CU_PTR_SIZE sizeof(cu_ptr)
|
||||||
|
|
||||||
|
#define cu_align(value, align) (((value / align) + !!(value % align))*align)
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
5
test.c
5
test.c
|
|
@ -3,6 +3,7 @@
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
#include "list.h"
|
#include "list.h"
|
||||||
#include "array.h"
|
#include "array.h"
|
||||||
|
#include "bitmap.h"
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
|
|
@ -50,5 +51,9 @@ int main()
|
||||||
printf("%p\t%d\t%d\t%d\n", array.mem,
|
printf("%p\t%d\t%d\t%d\n", array.mem,
|
||||||
array.size, array.count, array.align);
|
array.size, array.count, array.align);
|
||||||
array_clear(&array);
|
array_clear(&array);
|
||||||
|
|
||||||
|
printf("[bitmap]\n");
|
||||||
|
printf("bit_align2\t%u\n", bit_align2(354, 3));
|
||||||
|
printf("bit_log2\t%u\n", bit_log2(34));
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
Loading…
Add table
Reference in a new issue