From 470a25323ca89ffa3b0b697aeddcf184d12a1382 Mon Sep 17 00:00:00 2001 From: 3gg <3gg@shellblade.net> Date: Mon, 23 Jan 2023 18:32:49 -0800 Subject: Update listpool's interface to be on par with mempool's. --- listpool/src/listpool.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'listpool/src') diff --git a/listpool/src/listpool.c b/listpool/src/listpool.c index 8e49f32..758062c 100644 --- a/listpool/src/listpool.c +++ b/listpool/src/listpool.c @@ -77,3 +77,16 @@ void listpool_free_(listpool* pool, void** block_ptr) { *block_ptr = 0; } + +void* listpool_get_block_(const listpool* pool, size_t block_index) { + assert(pool); + assert(block_index < pool->num_blocks); + return pool->blocks + block_index * pool->block_size_bytes; +} + +size_t listpool_get_block_index_(const listpool* pool, const void* block) { + assert(pool); + const size_t block_byte_index = (const uint8_t*)block - pool->blocks; + assert(block_byte_index % pool->block_size_bytes == 0); + return block_byte_index / pool->block_size_bytes; +} -- cgit v1.2.3