2020-03-05 19:44:09 +00:00
|
|
|
#pragma once
|
|
|
|
|
2018-05-02 08:31:24 +00:00
|
|
|
#ifndef NAMED_ARRAY_H
|
|
|
|
#define NAMED_ARRAY_H
|
|
|
|
|
2018-05-28 07:52:44 +00:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2018-05-02 08:31:24 +00:00
|
|
|
typedef struct {
|
|
|
|
unsigned int element_size;
|
|
|
|
unsigned int max_element_count;
|
|
|
|
unsigned char* elements;
|
|
|
|
unsigned char* used_markers;
|
|
|
|
unsigned char marker_count;
|
|
|
|
} NamedArray;
|
|
|
|
|
2018-05-26 18:17:42 +00:00
|
|
|
void named_array_init(NamedArray* array, unsigned int element_size, unsigned int max_elements);
|
2020-03-05 19:44:09 +00:00
|
|
|
static inline char named_array_used(NamedArray* array, unsigned int id) {
|
|
|
|
const unsigned int i = id / 8;
|
|
|
|
const unsigned int j = id % 8;
|
|
|
|
|
|
|
|
unsigned char v = array->used_markers[i] & (unsigned char) (1 << j);
|
|
|
|
return !!(v);
|
|
|
|
}
|
2019-02-27 20:45:53 +00:00
|
|
|
|
2018-05-26 18:17:42 +00:00
|
|
|
void* named_array_alloc(NamedArray* array, unsigned int* new_id);
|
2019-02-27 20:45:53 +00:00
|
|
|
void* named_array_reserve(NamedArray* array, unsigned int id);
|
|
|
|
|
2018-05-26 18:17:42 +00:00
|
|
|
void named_array_release(NamedArray* array, unsigned int new_id);
|
|
|
|
void* named_array_get(NamedArray* array, unsigned int id);
|
|
|
|
void named_array_cleanup(NamedArray* array);
|
2018-05-02 08:31:24 +00:00
|
|
|
|
2018-05-28 07:52:44 +00:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2018-05-02 08:31:24 +00:00
|
|
|
#endif // NAMED_ARRAY_H
|