#ifndef SIECS_STORAGE_TABLE_INDEX_H
#define SIECS_STORAGE_TABLE_INDEX_H
#include "../table.h"
#include "../type.h"
#include <stdint.h>

struct ecs_world_s;

typedef struct {
    uint16_t table_index; // UINT16_MAX for empty
    uint16_t hash;
} ecs_type_slot_t;

typedef struct {
    ecs_table_t *tables;
    ecs_type_slot_t *slots;
    uint16_t table_count;
    uint16_t table_capacity;
    uint8_t slot_shift; // slot_count = 1 << slot_shift
} ecs_table_index_t;

void ecs_table_index_init(ecs_table_index_t *map);
void ecs_table_index_fini(struct ecs_world_s *world, ecs_table_index_t *map);

#define ecs_table_index_at(map, index) (&(map)->tables[index])

uint16_t ecs_table_index_get_or_create(
    struct ecs_world_s *world,
    ecs_type_t type
);

#endif
