From fa53ff81bf1cb8c4dd11c05c8e9533ee91fe768d Mon Sep 17 00:00:00 2001 From: Zachary Levy Date: Mon, 29 Jun 2026 16:17:15 +0000 Subject: [PATCH] Switching ring.append to ring.push (#39) Co-authored-by: Zachary Levy Reviewed-on: https://git.bfpower.io/BFPOWER/levlib/pulls/39 --- ring/ring.odin | 46 +++++++++++++++++++++++----------------------- 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/ring/ring.odin b/ring/ring.odin index e897d96..0b86971 100644 --- a/ring/ring.odin +++ b/ring/ring.odin @@ -113,19 +113,19 @@ advance :: proc { advance_soa, } -append_aos :: #force_inline proc(ring: ^Ring($E), element: E) { +push_aos :: #force_inline proc(ring: ^Ring($E), element: E) { ring.data[ring.next_write_index] = element advance(ring) } -append_soa :: #force_inline proc(ring: ^Ring_Soa($E), element: E) { +push_soa :: #force_inline proc(ring: ^Ring_Soa($E), element: E) { ring.data[ring.next_write_index] = element advance(ring) } -append :: proc { - append_aos, - append_soa, +push :: proc { + push_aos, + push_soa, } get_aos :: #force_inline proc(ring: Ring($E), index: int) -> ^E { @@ -202,7 +202,7 @@ test_ring_aos :: proc(t: ^testing.T) { defer destroy(&ring) for i in 1 ..= 5 { - append(&ring, i) + push(&ring, i) log.debug("Length:", ring.len) log.debug("Start index:", start_index_aos(ring)) log.debug("Next write index:", ring.next_write_index) @@ -215,7 +215,7 @@ test_ring_aos :: proc(t: ^testing.T) { testing.expect_value(t, start_index_aos(ring), 0) for i in 6 ..= 15 { - append(&ring, i) + push(&ring, i) log.debug("Length:", ring.len) log.debug("Start index:", start_index_aos(ring)) log.debug("Next write index:", ring.next_write_index) @@ -230,7 +230,7 @@ test_ring_aos :: proc(t: ^testing.T) { testing.expect_value(t, start_index_aos(ring), 5) for i in 15 ..= 25 { - append(&ring, i) + push(&ring, i) log.debug("Length:", ring.len) log.debug("Start index:", start_index_aos(ring)) log.debug("Next write index:", ring.next_write_index) @@ -241,7 +241,7 @@ test_ring_aos :: proc(t: ^testing.T) { testing.expect_value(t, get_last(ring)^, 25) clear(&ring) - append(&ring, 1) + push(&ring, 1) testing.expect_value(t, ring.len, 1) testing.expect_value(t, get(ring, 0)^, 1) } @@ -256,7 +256,7 @@ test_ring_soa :: proc(t: ^testing.T) { defer destroy(&ring) for i in 1 ..= 5 { - append(&ring, Ints{i, i}) + push(&ring, Ints{i, i}) log.debug("Length:", ring.len) log.debug("Start index:", start_index_soa(ring)) log.debug("Next write index:", ring.next_write_index) @@ -269,7 +269,7 @@ test_ring_soa :: proc(t: ^testing.T) { testing.expect_value(t, start_index_soa(ring), 0) for i in 6 ..= 15 { - append(&ring, Ints{i, i}) + push(&ring, Ints{i, i}) log.debug("Length:", ring.len) log.debug("Start index:", start_index_soa(ring)) log.debug("Next write index:", ring.next_write_index) @@ -284,7 +284,7 @@ test_ring_soa :: proc(t: ^testing.T) { testing.expect_value(t, start_index_soa(ring), 5) for i in 15 ..= 25 { - append(&ring, Ints{i, i}) + push(&ring, Ints{i, i}) log.debug("Length:", ring.len) log.debug("Start index:", start_index_soa(ring)) log.debug("Next write index:", ring.next_write_index) @@ -295,7 +295,7 @@ test_ring_soa :: proc(t: ^testing.T) { testing.expect_value(t, get_last(ring), Ints{25, 25}) clear(&ring) - append(&ring, Ints{1, 1}) + push(&ring, Ints{1, 1}) testing.expect_value(t, ring.len, 1) testing.expect_value(t, get(ring, 0), Ints{1, 1}) } @@ -314,7 +314,7 @@ test_ring_aos_init_from_slice :: proc(t: ^testing.T) { testing.expect_value(t, start_index_aos(ring), 0) // Partial fill (3 / 7). - for i in 1 ..= 3 do append(&ring, i) + for i in 1 ..= 3 do push(&ring, i) testing.expect_value(t, ring.len, 3) testing.expect_value(t, ring.next_write_index, 3) testing.expect_value(t, start_index_aos(ring), 0) @@ -324,7 +324,7 @@ test_ring_aos_init_from_slice :: proc(t: ^testing.T) { // Fill exactly to capacity. Pushing element 7 must make len == cap // AND wrap next_write_index from 6 back to 0 in the same step. - for i in 4 ..= 7 do append(&ring, i) + for i in 4 ..= 7 do push(&ring, i) testing.expect_value(t, ring.len, 7) testing.expect_value(t, ring.next_write_index, 0) testing.expect_value(t, start_index_aos(ring), 0) @@ -333,7 +333,7 @@ test_ring_aos_init_from_slice :: proc(t: ^testing.T) { testing.expect_value(t, get_last(ring)^, 7) // First overwrite — oldest element shifts by one. - append(&ring, 8) + push(&ring, 8) testing.expect_value(t, ring.len, 7) testing.expect_value(t, ring.next_write_index, 1) testing.expect_value(t, start_index_aos(ring), 1) @@ -344,7 +344,7 @@ test_ring_aos_init_from_slice :: proc(t: ^testing.T) { // Stress: 3 more complete wrap cycles (21 more pushes). // After 29 total pushes, ring contains the last 7 (23..=29), // and next_write_index = 29 mod 7 = 1. - for i in 9 ..= 29 do append(&ring, i) + for i in 9 ..= 29 do push(&ring, i) testing.expect_value(t, ring.len, 7) testing.expect_value(t, ring.next_write_index, 1) testing.expect_value(t, start_index_aos(ring), 1) @@ -360,7 +360,7 @@ test_ring_aos_init_from_slice :: proc(t: ^testing.T) { testing.expect_value(t, start_index_aos(ring), 0) // Single-element edge case: get_last(len==1) routes through get(ring, 0). - append(&ring, 42) + push(&ring, 42) testing.expect_value(t, ring.len, 1) testing.expect_value(t, ring.next_write_index, 1) testing.expect_value(t, get(ring, 0)^, 42) @@ -385,7 +385,7 @@ test_ring_soa_init_from_slice :: proc(t: ^testing.T) { testing.expect_value(t, start_index_soa(ring), 0) // Partial fill (3 / 7). - for i in 1 ..= 3 do append(&ring, Ints{i, i}) + for i in 1 ..= 3 do push(&ring, Ints{i, i}) testing.expect_value(t, ring.len, 3) testing.expect_value(t, ring.next_write_index, 3) testing.expect_value(t, start_index_soa(ring), 0) @@ -395,7 +395,7 @@ test_ring_soa_init_from_slice :: proc(t: ^testing.T) { // Fill exactly to capacity. Pushing element 7 must make len == cap // AND wrap next_write_index from 6 back to 0 in the same step. - for i in 4 ..= 7 do append(&ring, Ints{i, i}) + for i in 4 ..= 7 do push(&ring, Ints{i, i}) testing.expect_value(t, ring.len, 7) testing.expect_value(t, ring.next_write_index, 0) testing.expect_value(t, start_index_soa(ring), 0) @@ -404,7 +404,7 @@ test_ring_soa_init_from_slice :: proc(t: ^testing.T) { testing.expect_value(t, get_last(ring), Ints{7, 7}) // First overwrite — oldest element shifts by one. - append(&ring, Ints{8, 8}) + push(&ring, Ints{8, 8}) testing.expect_value(t, ring.len, 7) testing.expect_value(t, ring.next_write_index, 1) testing.expect_value(t, start_index_soa(ring), 1) @@ -415,7 +415,7 @@ test_ring_soa_init_from_slice :: proc(t: ^testing.T) { // Stress: 3 more complete wrap cycles (21 more pushes). // After 29 total pushes, ring contains the last 7 (23..=29), // and next_write_index = 29 mod 7 = 1. - for i in 9 ..= 29 do append(&ring, Ints{i, i}) + for i in 9 ..= 29 do push(&ring, Ints{i, i}) testing.expect_value(t, ring.len, 7) testing.expect_value(t, ring.next_write_index, 1) testing.expect_value(t, start_index_soa(ring), 1) @@ -431,7 +431,7 @@ test_ring_soa_init_from_slice :: proc(t: ^testing.T) { testing.expect_value(t, start_index_soa(ring), 0) // Single-element edge case: get_last(len==1) routes through get(ring, 0). - append(&ring, Ints{42, 42}) + push(&ring, Ints{42, 42}) testing.expect_value(t, ring.len, 1) testing.expect_value(t, ring.next_write_index, 1) testing.expect_value(t, get(ring, 0), Ints{42, 42})