Add _internal field to context

This commit is contained in:
gingerBill
2020-11-29 18:42:13 +00:00
parent dd4f8e9747
commit f4f2b8f5ad
2 changed files with 7 additions and 4 deletions
+3
View File
@@ -332,6 +332,9 @@ Context :: struct {
user_data: any,
user_ptr: rawptr,
user_index: int,
// Internal use only
_internal: rawptr,
}
+4 -4
View File
@@ -54,17 +54,17 @@ reverse_sort :: proc(data: $T/[]$E) where ORD(E) {
// TODO(bill): Should `sort_by_key` exist or is `sort_by` more than enough?
sort_by_key :: proc(data: $T/[]$E, key: proc(E) -> $K) where ORD(K) {
context.user_ptr = rawptr(key);
context._internal = rawptr(key);
sort_by(data, proc(i, j: E) -> bool {
k := (proc(E) -> K)(context.user_ptr);
k := (proc(E) -> K)(context._internal);
return k(i) < k(j);
});
}
reverse_sort_by_key :: proc(data: $T/[]$E, key: proc(E) -> $K) where ORD(K) {
context.user_ptr = rawptr(key);
context._internal = rawptr(key);
sort_by(data, proc(i, j: E) -> bool {
k := (proc(E) -> K)(context.user_ptr);
k := (proc(E) -> K)(context._internal);
return k(j) < k(i);
});
}