mirror of
https://github.com/Ed94/Odin.git
synced 2026-06-24 06:35:00 -07:00
Add soa_zip and soa_unzip to demo.odin
This commit is contained in:
+24
-2
@@ -1760,8 +1760,6 @@ range_statements_with_multiple_return_values :: proc() {
|
||||
|
||||
|
||||
soa_struct_layout :: proc() {
|
||||
// IMPORTANT NOTE(bill, 2019-11-03): This feature is subject to be changed/removed
|
||||
// NOTE(bill): Most likely #soa [N]T
|
||||
fmt.println("\n#SOA Struct Layout");
|
||||
|
||||
{
|
||||
@@ -1858,6 +1856,30 @@ soa_struct_layout :: proc() {
|
||||
fmt.println(cap(d));
|
||||
fmt.println(d[:]);
|
||||
}
|
||||
{ // soa_zip and soa_unzip
|
||||
fmt.println("\nsoa_zip and soa_unzip");
|
||||
|
||||
x := []i32{1, 3, 9};
|
||||
y := []f32{2, 4, 16};
|
||||
z := []b32{true, false, true};
|
||||
|
||||
// produce an #soa slice the normal slices passed
|
||||
s := soa_zip(a=x, b=y, c=z);
|
||||
|
||||
// iterate over the #soa slice
|
||||
for v, i in s {
|
||||
fmt.println(v); // exactly the same as s[i]
|
||||
// NOTE: 'v' is NOT a temporary value but has a specialized addressing mode
|
||||
// which means that when accessing v.a etc, it does the correct transformation
|
||||
// internally:
|
||||
// s[i].a === s.a[i]
|
||||
fmt.println(v.a, v.b, v.c);
|
||||
}
|
||||
|
||||
// Recover the slices from the #soa slice
|
||||
a, b, c := soa_unzip(s);
|
||||
fmt.println(a, b, c);
|
||||
}
|
||||
}
|
||||
|
||||
constant_literal_expressions :: proc() {
|
||||
|
||||
Reference in New Issue
Block a user