mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-06 07:38:48 +00:00
Use cmp_proc in binary_search
This commit is contained in:
@@ -158,15 +158,7 @@ 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)
|
binary_search :: proc(array: $A/[]$T, key: T) -> (index: int, found: bool)
|
||||||
where intrinsics.type_is_ordered(T) #no_bounds_check
|
where intrinsics.type_is_ordered(T) #no_bounds_check
|
||||||
{
|
{
|
||||||
// I would like to use binary_search_by(array, key, cmp) here, but it doesn't like it:
|
return binary_search_by(array, key, cmp_proc(T))
|
||||||
// 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)
|
@(require_results)
|
||||||
|
|||||||
Reference in New Issue
Block a user