ludic.base: tb_reserve and imap_reserve size a table up front; HandlePool (a slot and a generation, nothing made after hd_pool_new, past its capacity a panic naming it); kept_push is the one declared grow, and every growth path left says its bound in @alloc_ok

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Orkun ÇAKILKAYA 2026-09-28 15:58:11 +03:00
parent f2dd27f443
commit 2d1d06899e
17 changed files with 199 additions and 26 deletions

View file

@ -179,8 +179,26 @@ program EcsTest {
test "observers hear each add, and a remove once" (hook_st: HookState) { hooks_case(hook_st) }
test "change detection skips the blocks nobody wrote" () { blocks_case() }
test "a removed handle misses, rows stay dense, a reused slot is a new handle" () { handles_case() }
function reserve_case() -> void {
let tb: Table<Toy> = table_new(2, 2)
let g = tb_grid(tb, CX, CZ, ON, 8.0)
let ix = tb_index(tb, KIND, ON)
put(tb, "a", 1.0, 1.0, 3)
tb_reserve(tb, 200)
expect_eq(tb_len(tb), 1)
var hs = new []int
for i in 0 .. 150 { push(hs, put(tb, "t", float(i), 2.0, i % 4)) }
expect_eq(tb_len(tb), 151)
expect_eq(ix_count(ix, 3), 38)
expect(tb_row(tb, hs[10]) >= 0)
expect(tb_remove(tb, hs[10]))
expect_eq(tb_row(tb, hs[10]), -1)
expect_eq(grid_count(g), 150)
}
test "the grid answers nearest and within, gated, after moves" () { grid_case() }
test "the kind index follows the setters, the gate and removals" () { index_case() }
test "change ticks name the rows written since" () { ticks_case() }
test "IntMap puts, finds, deletes and grows" () { map_case() }
test "a reserved table holds its rows and indexes as an unreserved one does" () { reserve_case() }
}

View file

@ -0,0 +1,38 @@
# handle_test.ludic - a pool's ids: a freed one misses once its slot is reused, the generation wraps,
# and past the capacity a pool that is not strict refuses rather than grows
import "ludic.base"
program HandleTest {
numbers float
test "a freed handle misses, and its slot comes back under a new generation" {
let p = hd_pool_new("bufs", 4)
p.strict = false
let a = hd_new(p)
let b = hd_new(p)
expect_eq(hd_slot(p, a), 0)
expect_eq(hd_slot(p, b), 1)
expect(hd_free(p, a))
expect_eq(hd_slot(p, a), -1)
expect(not hd_free(p, a))
let c = hd_new(p)
expect_eq(hd_slot(p, c), 0)
expect(c != a)
expect_eq(hd_slot(p, a), -1)
expect_eq(hd_live(p), 2)
}
test "the generation wraps after 512 reuses and the pool never grows past its capacity" {
let p = hd_pool_new("once", 2)
p.strict = false
var h = hd_new(p)
let first = h
for i in 0 .. 511 {
hd_free(p, h)
h = hd_new(p)
}
hd_free(p, h)
expect_eq(hd_new(p), first)
hd_new(p)
expect_eq(hd_new(p), -1)
expect_eq(p.refused, 1)
expect_eq(hd_cap(p), 2)
}
}