Files
ci2/include/platform/dsa/ci2_array.h
T
2026-06-10 07:54:03 -05:00

63 lines
2.1 KiB
C

/* - | Copyright | ------------------------------------------------------------
Copyright (c) 2026 Randy Jordan
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
* --------------------------------------------------------------------------*/
#ifndef CI2_ARRAY_H
#define CI2_ARRAY_H
struct CI2_Array
{
void** items;
int cap;
int len;
};
typedef struct CI2_Array CI2_Array;
void
ci2_array_init(struct CI2_Array* a, int cap);
int
ci2_array_len(struct CI2_Array* a);
void
ci2_array_add(struct CI2_Array* a, void* p);
void
ci2_array_set(struct CI2_Array* a, int index, void* p);
void*
ci2_array_get(struct CI2_Array* a, int index);
void
ci2_array_delete(struct CI2_Array* a, int index);
void
ci2_array_free(struct CI2_Array* a);
#define CI2_ARRAY_ADD(vec, item) ci2_array_add(&vec, (void*)item)
#define CI2_ARRAY_SET(vec, id, item) ci2_array_set(&vec, id, (void*)item)
#define CI2_ARRAY_GET(vec, type, id) (type) ci2_array_get(&vec, id)
#define CI2_ARRAY_DELETE(vec, id) ci2_array_delete(&vec, id)
#define CI2_ARRAY_TOTAL(vec) ci2_array_total(&vec)
#define CI2_ARRAY_FREE(vec) ci2_array_free(&vec)
#endif // ci2_array.h