From: Brendan Hansen Date: Mon, 23 Aug 2021 21:01:33 +0000 (-0500) Subject: bugfixes with core libs X-Git-Url: https://git.brendanfh.com/?a=commitdiff_plain;h=4bb45375357168b6756340253fe03f8ec483170d;p=onyx.git bugfixes with core libs --- diff --git a/core/container/array.onyx b/core/container/array.onyx index 4115b65d..16eb82ed 100644 --- a/core/container/array.onyx +++ b/core/container/array.onyx @@ -402,19 +402,24 @@ count_where :: #match { }, } -#private_file -fold_idx_elem :: (arr: ^$T, count: i32, cmp: (T, T) -> bool) -> (i32, T) { - idx := 0; - elem := arr[0]; - - for i: 1 .. count { - if cmp(arr[i], elem) { - idx = i; - elem = arr[i]; +fold_idx_elem :: #match { + (arr: ^[..] $T, cmp: (T, T) -> bool) -> (i32, T) { + return fold_idx_elem(arr.data, arr.count, cmp); + }, + + (arr: ^$T, count: i32, cmp: (T, T) -> bool) -> (i32, T) { + idx := 0; + elem := arr[0]; + + for i: 1 .. count { + if cmp(arr[i], elem) { + idx = i; + elem = arr[i]; + } } - } - - return idx, elem; + + return idx, elem; + }, } #private_file cmp_greater :: (x: $T, y: T) -> bool do return x > y; diff --git a/core/container/set.onyx b/core/container/set.onyx index 9f5b163b..e15a43a7 100644 --- a/core/container/set.onyx +++ b/core/container/set.onyx @@ -57,6 +57,11 @@ has :: (use set: ^Set($T), value: T) -> bool { return lr.entry_index >= 0; } +get :: (use set: ^Set($T), value: T) -> T { + lr := lookup(set, value); + return entries[lr.entry_index].value if lr.entry_index >= 0 else __zero_value(T); +} + remove :: (use set: ^Set($T), value: T) { lr := lookup(set, value); if lr.entry_index < 0 do return; diff --git a/core/io/stream.onyx b/core/io/stream.onyx index 9ab53f6d..3d785991 100644 --- a/core/io/stream.onyx +++ b/core/io/stream.onyx @@ -6,7 +6,7 @@ Stream :: struct { vtable : ^Stream_Vtable; } -#private +// #private Stream_Vtable :: struct { seek : (s: ^Stream, to: i32, whence: SeekFrom) -> Error; tell : (s: ^Stream) -> (Error, u32);