comparison foosdk/sdk/pfc/bsearch_inline.h @ 1:20d02a178406 default tip

*: check in everything else yay
author Paper <paper@tflc.us>
date Mon, 05 Jan 2026 02:15:46 -0500
parents
children
comparison
equal deleted inserted replaced
0:e9bb126753e7 1:20d02a178406
1 #pragma once
2
3 namespace pfc {
4
5 //deprecated
6
7 template<typename t_callback>
8 inline bool bsearch_inline_t(t_size p_count, t_callback && p_callback,t_size & p_result)
9 {
10 t_size max = p_count;
11 t_size min = 0;
12 t_size ptr;
13 while(min<max)
14 {
15 ptr = min + ( (max-min) >> 1);
16 int result = p_callback.test(ptr);
17 if (result<0) min = ptr + 1;
18 else if (result>0) max = ptr;
19 else
20 {
21 p_result = ptr;
22 return true;
23 }
24 }
25 p_result = min;
26 return false;
27 }
28
29 template<typename t_buffer, typename t_value, typename pred_t>
30 inline bool bsearch_simple_inline_t(t_buffer&& p_buffer, t_size p_count, t_value const& p_value, pred_t && pred, t_size& p_result)
31 {
32 t_size max = p_count;
33 t_size min = 0;
34 t_size ptr;
35 while (min < max)
36 {
37 ptr = min + ((max - min) >> 1);
38 int test = pred(p_value, p_buffer[ptr]);
39 if ( test > 0 ) min = ptr + 1;
40 else if ( test < 0 ) max = ptr;
41 else
42 {
43 p_result = ptr;
44 return true;
45 }
46 }
47 p_result = min;
48 return false;
49 }
50
51 template<typename t_buffer,typename t_value>
52 inline bool bsearch_simple_inline_t(t_buffer && p_buffer,t_size p_count,t_value && p_value,t_size & p_result)
53 {
54 t_size max = p_count;
55 t_size min = 0;
56 t_size ptr;
57 while(min<max)
58 {
59 ptr = min + ( (max-min) >> 1);
60 if (p_value > p_buffer[ptr]) min = ptr + 1;
61 else if (p_value < p_buffer[ptr]) max = ptr;
62 else
63 {
64 p_result = ptr;
65 return true;
66 }
67 }
68 p_result = min;
69 return false;
70 }
71
72 }