diff --git a/core/slice/slice.odin b/core/slice/slice.odin index 2c7d225a8..4d60fe67a 100644 --- a/core/slice/slice.odin +++ b/core/slice/slice.odin @@ -1,10 +1,12 @@ package slice import "intrinsics" +import "builtin" import "core:math/bits" import "core:mem" _ :: intrinsics; +_ :: builtin; _ :: bits; _ :: mem; @@ -292,6 +294,28 @@ filter :: proc(s: $S/[]$U, f: proc(U) -> bool, allocator := context.allocator) - +min :: proc(s: $S/[]$T) -> (res: T, ok: bool) where intrinsics.type_is_ordered(T) #optional_ok { + if len(s) != 0 { + res = s[0]; + ok = true; + for v in s[1:] { + res = min(res, v); + } + } + return; +} +max :: proc(s: $S/[]$T) -> (res: T, ok: bool) where intrinsics.type_is_ordered(T) #optional_ok { + if len(s) != 0 { + res = s[0]; + ok = true; + for v in s[1:] { + res = max(res, v); + } + } + return; +} + + dot_product :: proc(a, b: $S/[]$T) -> T where intrinsics.type_is_numeric(T) { if len(a) != len(b) {