foobar2000 SDK  2015-08-03
bsearch_inline.h
Go to the documentation of this file.
1 namespace pfc {
2 
3  //deprecated
4 
5 template<typename t_callback>
6 inline bool bsearch_inline_t(t_size p_count, const t_callback & p_callback,t_size & p_result)
7 {
8  t_size max = p_count;
9  t_size min = 0;
10  t_size ptr;
11  while(min<max)
12  {
13  ptr = min + ( (max-min) >> 1);
14  int result = p_callback.test(ptr);
15  if (result<0) min = ptr + 1;
16  else if (result>0) max = ptr;
17  else
18  {
19  p_result = ptr;
20  return true;
21  }
22  }
23  p_result = min;
24  return false;
25 }
26 
27 template<typename t_buffer,typename t_value>
28 inline bool bsearch_simple_inline_t(const t_buffer & p_buffer,t_size p_count,t_value const & p_value,t_size & p_result)
29 {
30  t_size max = p_count;
31  t_size min = 0;
32  t_size ptr;
33  while(min<max)
34  {
35  ptr = min + ( (max-min) >> 1);
36  if (p_value > p_buffer[ptr]) min = ptr + 1;
37  else if (p_value < p_buffer[ptr]) max = ptr;
38  else
39  {
40  p_result = ptr;
41  return true;
42  }
43  }
44  p_result = min;
45  return false;
46 }
47 
48 }
bool bsearch_simple_inline_t(const t_buffer &p_buffer, t_size p_count, t_value const &p_value, t_size &p_result)
bool bsearch_inline_t(t_size p_count, const t_callback &p_callback, t_size &p_result)
Definition: bsearch_inline.h:6
size_t t_size
Definition: int_types.h:48