Add chunk iterator
This commit is contained in:
parent
7d23ca691c
commit
250f86ac2d
@ -172,3 +172,58 @@ iterator_next :: proc(it: ^Iterator($E, $SOA)) -> (e: ^E, idx: int, ok: bool) {
|
||||
it.idx += 1
|
||||
return
|
||||
}
|
||||
|
||||
Chunk_Iterator :: struct($E: typeid, $SOA: bool) {
|
||||
xarr: ^Xarr(E, SOA),
|
||||
base_element_idx: int,
|
||||
chunk_idx: i8,
|
||||
}
|
||||
|
||||
chunk_iterator :: proc(a: $T/^Xarr($E, $SOA)) -> Chunk_Iterator(E, SOA) {
|
||||
return Chunk_Iterator(E, SOA){xarr = a}
|
||||
}
|
||||
|
||||
chunk_iterator_next_scalar :: proc(
|
||||
it: ^Chunk_Iterator($E, false),
|
||||
) -> (
|
||||
chunk: []E,
|
||||
base_element_idx: int,
|
||||
ok: bool,
|
||||
) {
|
||||
if (it.xarr.allocated_chunks_mask & (u32(1) << it.idx)) == 0 {
|
||||
return nil, 0, false
|
||||
}
|
||||
|
||||
chunk = get_chunk_slice_scalar(it.xarr, it.idx)
|
||||
base_element_idx = it.base_element_idx
|
||||
ok = true
|
||||
|
||||
base_element_idx += chunk_size(it.chunk_idx)
|
||||
it.chunk_idx += 1
|
||||
return
|
||||
}
|
||||
|
||||
chunk_iterator_next_soa :: proc(
|
||||
it: ^Chunk_Iterator($E, true),
|
||||
) -> (
|
||||
chunk: #soa[]E,
|
||||
base_element_idx: int,
|
||||
ok: bool,
|
||||
) {
|
||||
if (it.xarr.allocated_chunks_mask & (u32(1) << it.idx)) == 0 {
|
||||
return nil, 0, false
|
||||
}
|
||||
|
||||
chunk = get_chunk_slice_soa(it.xarr, it.idx)
|
||||
base_element_idx = it.base_element_idx
|
||||
ok = true
|
||||
|
||||
base_element_idx += chunk_size(it.chunk_idx)
|
||||
it.chunk_idx += 1
|
||||
return
|
||||
}
|
||||
|
||||
chunk_iterator_next :: proc {
|
||||
chunk_iterator_next_scalar,
|
||||
chunk_iterator_next_soa,
|
||||
}
|
||||
|
@ -131,7 +131,6 @@ test_soa :: proc(t: ^testing.T) {
|
||||
|
||||
append(&a, My_Struct{x = 1, y = 2, z = 3})
|
||||
|
||||
|
||||
testing.expect_value(t, get(a, 0), My_Struct{x = 1, y = 2, z = 3})
|
||||
testing.expect_value(t, size_of(Xarr(My_Struct, false)), 0)
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user