Preparing to add matrices to the list

This commit is contained in:
Synthasmagoria 2026-07-30 22:16:35 +02:00
commit 4987f1b0d2
4 changed files with 127 additions and 82 deletions

View file

@ -1,42 +0,0 @@
package adb_pool
Pool :: struct($T: typeid) {
pool: []T,
usage: int,
}
init :: proc(pool: ^Pool($T), capacity: int, allocator := context.allocator) {
pool.pool = make([]T, capacity, allocator)
pool.usage = 0
}
elems_available :: proc(pool: ^Pool($T), capacity: int) -> bool {
return pool.usage + count <= pool.capacity
}
get :: proc(pool: ^Pool($T), count: int) -> []T {
range_to := pool.usage + count
assert(range_to <= len(pool.pool), "pool.get count reaches outside preallocated size")
elements := pool.pool[pool.usage:]
pool.usage += count
return elements
}
usage :: proc(pool: Pool($T)) -> int {
return pool.usage
}
get_allocated_elements :: proc(pool: Pool($T)) -> []T {
return pool.pool[:pool.usage]
}
clear :: proc(pool: ^Pool($T)) {
pool.usage = 0
}
free_range :: proc(pool: ^Pool($T), from, count: int) {
assert(count > 0, "Cannot free zero or negative count")
to := from + count
assert(to < pool.usage, "Cannot free beyond usage")
mem.copy(&pool.pool[from], &pool.pool[to], (pool.usage - to) * size_of(T))
}