}
}
+quicksort :: #match {
+ (arr: [] $T, cmp: ( T, T) -> i32) do quicksort_impl(arr, cmp, 0, arr.count - 1); ,
+ (arr: [] $T, cmp: (^T, ^T) -> i32) do quicksort_impl(arr, cmp, 0, arr.count - 1); ,
+}
+
+#private_file {
+ quicksort_impl :: (arr: [] $T, cmp: $PredicateFunction, lo, hi: i32) {
+ if lo < 0 || hi < 0 do return;
+ if lo >= hi do return;
+
+ pivot := quicksort_partition(arr, cmp, lo, hi);
+ quicksort_impl(arr, cmp, lo, pivot - 1);
+ quicksort_impl(arr, cmp, pivot + 1, hi);
+ }
+
+ quicksort_partition :: #match {
+ (arr: [] $T, cmp: (T, T) -> i32, lo, hi: i32) -> i32 {
+ pivot := arr[hi];
+ i := lo - 1;
+
+ for j: lo .. hi+1 {
+ if cmp(arr[j], pivot) <= 0 {
+ i += 1;
+ arr[i], arr[j] = arr[j], arr[i];
+ }
+ }
+
+ return i;
+ },
+
+ (arr: [] $T, cmp: (^T, ^T) -> i32, lo, hi: i32) -> i32 {
+ pivot := ^arr[hi];
+ i := lo - 1;
+
+ for j: lo .. hi+1 {
+ if cmp(^arr[j], pivot) <= 0 {
+ i += 1;
+ arr[i], arr[j] = arr[j], arr[i];
+ }
+ }
+
+ return i;
+ }
+ }
+}
+
fold :: (arr: [] $T, init: $R, f: (T, R) -> R) -> R {
val := init;
for it: arr do val = f(it, val);
bh_arr(TypeWithOffset) linear_members; \
Type* types[]; \
}) \
- TYPE_KIND(Array, struct { u32 size; u32 count; Type *elem; }) \
+ TYPE_KIND(Array, struct { Type* elem; u32 size; u32 count; }) \
TYPE_KIND(Slice, struct { Type *elem; }) \
TYPE_KIND(DynArray, struct { Type *elem; }) \
TYPE_KIND(VarArgs, struct { Type *elem; }) \
}
case Ast_Kind_Slice_Type: {
- if (elem.actual->kind != Type_Kind_Slice && elem.actual->kind != Type_Kind_DynArray && elem.actual->kind != Type_Kind_VarArgs) break;
+ if (elem.actual->kind != Type_Kind_Slice && elem.actual->kind != Type_Kind_DynArray
+ && elem.actual->kind != Type_Kind_VarArgs && elem.actual->kind != Type_Kind_Array) break;
bh_arr_push(elem_queue, ((PolySolveElem) {
.type_expr = ((AstSliceType *) elem.type_expr)->elem,
.kind = PSK_Type,
- // HACK: This makes the assumption that slices, dynamic arrays and varargs have the same element type at the same location.
+ // HACK: This makes the assumption that arrays, slices, dynamic arrays and varargs have the same element type at the same location.
.actual = elem.actual->Slice.elem,
}));
break;