42 lines
1.1 KiB
C
42 lines
1.1 KiB
C
|
/* This software is licensed by the MIT License, see LICENSE file */
|
||
|
/* Copyright © 2022 Gregory Lirent */
|
||
|
|
||
|
#include "../../include/array.h"
|
||
|
#include "../../include/extra/array.h"
|
||
|
#include "../__internal/include.h"
|
||
|
|
||
|
#ifndef LIBCDSB_SRC_ARRAY_INCLUDE_H
|
||
|
#define LIBCDSB_SRC_ARRAY_INCLUDE_H
|
||
|
|
||
|
#define ARRAY_MEM_BLOCK_SIZE 256
|
||
|
|
||
|
ainline(size_t array_nblocks(const arr_t* x)) {
|
||
|
size_t n = x->size*vtype_size(x->type);
|
||
|
|
||
|
if (n%vtype_size(x->type)) {
|
||
|
return n / ARRAY_MEM_BLOCK_SIZE + 1;
|
||
|
} else return n / ARRAY_MEM_BLOCK_SIZE;
|
||
|
}
|
||
|
|
||
|
ainline(size_t array_allocated_nmemb(const arr_t* x)) {
|
||
|
return array_nblocks(x) * ARRAY_MEM_BLOCK_SIZE;
|
||
|
}
|
||
|
|
||
|
ainline(void array_cut(arr_t* x, size_t i, size_t n)) {
|
||
|
void* v = x->mem + i*vtype_size(x->type);
|
||
|
void* e = v + n*vtype_size(x->type);
|
||
|
|
||
|
memmove(v, e, (x->size-(i+n))*vtype_size(x->type));
|
||
|
x->size -= n;
|
||
|
}
|
||
|
|
||
|
ainline(void* array_end(const arr_t* x)) {
|
||
|
return x->mem + x->size*vtype_size(x->type);
|
||
|
}
|
||
|
|
||
|
ainline(void* array_at(const arr_t* x, size_t i)) {
|
||
|
return x->mem + i*vtype_size(x->type);
|
||
|
}
|
||
|
|
||
|
#endif /* LIBCDSB_SRC_ARRAY_INCLUDE_H */
|