2026-05-10 13:36:52 -07:00
|
|
|
// SPDX-FileCopyrightText: 2025 Erin Catto
|
|
|
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
#include "container.h"
|
|
|
|
|
|
|
|
|
|
typedef struct b3IdPool
|
|
|
|
|
{
|
2026-06-11 22:39:26 -07:00
|
|
|
b3Array( int ) freeArray;
|
2026-05-10 13:36:52 -07:00
|
|
|
int nextIndex;
|
|
|
|
|
} b3IdPool;
|
|
|
|
|
|
|
|
|
|
b3IdPool b3CreateIdPool( void );
|
|
|
|
|
void b3DestroyIdPool( b3IdPool* pool );
|
|
|
|
|
|
|
|
|
|
int b3AllocId( b3IdPool* pool );
|
|
|
|
|
void b3FreeId( b3IdPool* pool, int id );
|
|
|
|
|
void b3ValidateFreeId( const b3IdPool* pool, int id );
|
|
|
|
|
|
2026-05-12 15:24:20 -07:00
|
|
|
static inline int b3GetIdCount( const b3IdPool* pool )
|
2026-05-10 13:36:52 -07:00
|
|
|
{
|
|
|
|
|
return pool->nextIndex - pool->freeArray.count;
|
|
|
|
|
}
|
|
|
|
|
|
2026-05-12 15:24:20 -07:00
|
|
|
static inline int b3GetIdCapacity( const b3IdPool* pool )
|
2026-05-10 13:36:52 -07:00
|
|
|
{
|
|
|
|
|
return pool->nextIndex;
|
|
|
|
|
}
|
|
|
|
|
|
2026-05-12 15:24:20 -07:00
|
|
|
static inline int b3GetIdBytes( const b3IdPool* pool )
|
2026-05-10 13:36:52 -07:00
|
|
|
{
|
|
|
|
|
return b3Array_ByteCount( pool->freeArray );
|
|
|
|
|
}
|