/* Copyright (c) 2023 Alex Diener This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. Alex Diener alex@ludobloom.com */ #ifndef __ChunkArray_H__ #define __ChunkArray_H__ #include typedef struct ChunkArray { void * data; size_t count; size_t * offsets; size_t totalSize; size_t alignment; size_t allocatedOffsetCount; size_t allocatedDataSize; } ChunkArray; ChunkArray ChunkArray_init(void); ChunkArray ChunkArray_copy(ChunkArray * array); void ChunkArray_free(ChunkArray * array); void * ChunkArray_entryAtIndex(ChunkArray * array, size_t index); // Returned size includes alignment padding, and therefore may be larger than the size specified to append() or insert() for this entry size_t ChunkArray_getEntrySize(ChunkArray * array, size_t index); // Returns UINT_MAX for entries out of range; entry can be any address in the range of a chunk size_t ChunkArray_indexOfEntry(ChunkArray * array, void * entry); // append and insert return the newly added entry. If data is NULL, space will be allocated and returned without a value being assigned. void * ChunkArray_append(ChunkArray * array, const void * data, size_t size); void * ChunkArray_insert(ChunkArray * array, size_t index, const void * data, size_t size); void ChunkArray_remove(ChunkArray * array, size_t index); void ChunkArray_removeAll(ChunkArray * array); #endif