aboutsummaryrefslogtreecommitdiff
path: root/core/slice
diff options
context:
space:
mode:
authorgingerBill <bill@gingerbill.org>2023-12-13 01:20:53 +0000
committergingerBill <bill@gingerbill.org>2023-12-13 01:20:53 +0000
commitfe0244606b89edfbe9068008191b03f05c2c16b3 (patch)
tree7f84ee54d7cb83ed2c020604de0f377baa69078a /core/slice
parent036fa6482ccc6d4eb7562e2a5a4af566ea05eb90 (diff)
Revert
Diffstat (limited to 'core/slice')
-rw-r--r--core/slice/slice.odin16
1 files changed, 12 insertions, 4 deletions
diff --git a/core/slice/slice.odin b/core/slice/slice.odin
index eea571a80..216050eb1 100644
--- a/core/slice/slice.odin
+++ b/core/slice/slice.odin
@@ -158,7 +158,15 @@ linear_search_proc :: proc(array: $A/[]$T, f: proc(T) -> bool) -> (index: int, f
binary_search :: proc(array: $A/[]$T, key: T) -> (index: int, found: bool)
where intrinsics.type_is_ordered(T) #no_bounds_check
{
- return binary_search_by(array, key, cmp_proc(T))
+ // I would like to use binary_search_by(array, key, cmp) here, but it doesn't like it:
+ // Cannot assign value 'cmp' of type 'proc($E, $E) -> Ordering' to 'proc(i32, i32) -> Ordering' in argument
+ return binary_search_by(array, key, proc(key: T, element: T) -> Ordering {
+ switch {
+ case element < key: return .Less
+ case element > key: return .Greater
+ case: return .Equal
+ }
+ })
}
@(require_results)
@@ -186,9 +194,9 @@ binary_search_by :: proc(array: $A/[]$T, key: T, f: proc(T, T) -> Ordering) -> (
right = mid if cmp == .Greater else right
switch cmp {
- case .Equal: return mid, true
- case .Less: left = mid + 1
- case .Greater: right = mid
+ case .Equal: return mid, true
+ case .Less: left = mid + 1
+ case .Greater: right = mid
}
size = right - left