|
@@ -1,10 +1,12 @@
|
|
package slice
|
|
package slice
|
|
|
|
|
|
import "intrinsics"
|
|
import "intrinsics"
|
|
|
|
+import "builtin"
|
|
import "core:math/bits"
|
|
import "core:math/bits"
|
|
import "core:mem"
|
|
import "core:mem"
|
|
|
|
|
|
_ :: intrinsics;
|
|
_ :: intrinsics;
|
|
|
|
+_ :: builtin;
|
|
_ :: bits;
|
|
_ :: bits;
|
|
_ :: mem;
|
|
_ :: 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
|
|
dot_product :: proc(a, b: $S/[]$T) -> T
|
|
where intrinsics.type_is_numeric(T) {
|
|
where intrinsics.type_is_numeric(T) {
|
|
if len(a) != len(b) {
|
|
if len(a) != len(b) {
|