-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbinary_search.h
45 lines (42 loc) · 1.39 KB
/
binary_search.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
// Licensed under the MIT License.
#include <stddef.h>
#include "array.h"
#include "comparer.h"
#include "object.h"
/**
* Searches a sorted collection for the least element greater than or equal to
* a given value. This function uses the binary search algorithm.
*
* @param min the required minimum value.
* @param items the sorted collection of items.
* @param length the number of items.
* @param itemSize the size of each item.
* @param comparer the item comparer. The `items` argument must be sorted
* using the same comparer.
* @return A reference to the least element greater than or equal to the
* given minimum.
*/
Object binary_search_min(
Object min,
Array items,
size_t length,
size_t itemSize,
Comparer comparer);
/**
* Determines the number of elements less than a given value in a sorted
* collection. This function uses the binary search algorithm.
*
* @param max the required maximum value.
* @param items the sorted collection of items.
* @param length the number of items.
* @param itemSize the size of each item.
* @param comparer the item comparer. The `items` argument must be sorted using
* the same comparer.
* @return The number of items less than the given maximum.
*/
size_t binary_search_rank(
Object max,
Array items,
size_t length,
size_t itemSize,
Comparer comparer);