2022-06-02 15:52:43 +03:00
|
|
|
/* This software is licensed by the MIT License, see LICENSE file */
|
|
|
|
/* Copyright © 2022 Gregory Lirent */
|
|
|
|
|
|
|
|
#include "../../include/array.h"
|
|
|
|
#include "../__internal/include.h"
|
|
|
|
|
|
|
|
#ifndef LIBCDSB_SRC_ARRAY_INCLUDE_H
|
|
|
|
#define LIBCDSB_SRC_ARRAY_INCLUDE_H
|
|
|
|
|
2022-08-19 13:41:19 +03:00
|
|
|
typedef void (*type_initializer)(void*, const void*);
|
|
|
|
|
|
|
|
ainline(type_initializer get_type_initializer(vtype type)) {
|
|
|
|
switch (type) {
|
|
|
|
default:
|
|
|
|
#ifndef NDEBUG
|
|
|
|
abort();
|
|
|
|
#endif
|
|
|
|
case VTYPE_STRING: return (void*)string_copy_init;
|
|
|
|
case VTYPE_ARRAY: return (void*) array_copy_init;
|
|
|
|
case VTYPE_LIST: return (void*) list_copy_init;
|
|
|
|
case VTYPE_MAP: return (void*) map_copy_init;
|
|
|
|
case VTYPE_SET: return (void*) vset_copy_init;
|
|
|
|
case VTYPE_DICT: return (void*) dict_copy_init;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-06-02 15:52:43 +03:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2022-06-03 11:58:02 +03:00
|
|
|
ainline(void* array_internal_at(const arr_t* x, size_t i)) {
|
2022-06-02 15:52:43 +03:00
|
|
|
return x->mem + i*vtype_size(x->type);
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* LIBCDSB_SRC_ARRAY_INCLUDE_H */
|