foobar2000 SDK  2015-08-03
bsearch.h
Go to the documentation of this file.
1 namespace pfc {
2 
3  //deprecated
4 
5  class NOVTABLE bsearch_callback
6  {
7  public:
8  virtual int test(t_size n) const = 0;
9  };
10 
11  bool bsearch(t_size p_count, bsearch_callback const & p_callback,t_size & p_result);
12 
13  template<typename t_container,typename t_compare, typename t_param>
15  public:
16  int test(t_size p_index) const {
17  return m_compare(m_container[p_index],m_param);
18  }
19  bsearch_callback_impl_simple_t(const t_container & p_container,t_compare p_compare,const t_param & p_param)
20  : m_container(p_container), m_compare(p_compare), m_param(p_param)
21  {
22  }
23  private:
24  const t_container & m_container;
25  t_compare m_compare;
26  const t_param & m_param;
27  };
28 
29  template<typename t_container,typename t_compare, typename t_param,typename t_permutation>
31  public:
32  int test(t_size p_index) const {
33  return m_compare(m_container[m_permutation[p_index]],m_param);
34  }
35  bsearch_callback_impl_permutation_t(const t_container & p_container,t_compare p_compare,const t_param & p_param,const t_permutation & p_permutation)
36  : m_container(p_container), m_compare(p_compare), m_param(p_param), m_permutation(p_permutation)
37  {
38  }
39  private:
40  const t_container & m_container;
41  t_compare m_compare;
42  const t_param & m_param;
43  const t_permutation & m_permutation;
44  };
45 
46 
47  template<typename t_container,typename t_compare, typename t_param>
48  bool bsearch_t(t_size p_count,const t_container & p_container,t_compare p_compare,const t_param & p_param,t_size & p_index) {
49  return bsearch(
50  p_count,
52  p_index);
53  }
54 
55  template<typename t_container,typename t_compare,typename t_param,typename t_permutation>
56  bool bsearch_permutation_t(t_size p_count,const t_container & p_container,t_compare p_compare,const t_param & p_param,const t_permutation & p_permutation,t_size & p_index) {
57  t_size index;
58  if (bsearch(
59  p_count,
61  index))
62  {
63  p_index = p_permutation[index];
64  return true;
65  } else {
66  return false;
67  }
68  }
69 
70  template<typename t_container,typename t_compare, typename t_param>
71  bool bsearch_range_t(const t_size p_count,const t_container & p_container,t_compare p_compare,const t_param & p_param,t_size & p_range_base,t_size & p_range_count)
72  {
73  t_size probe;
74  if (!bsearch(
75  p_count,
77  probe)) return false;
78 
79  t_size base = probe, count = 1;
80  while(base > 0 && p_compare(p_container[base-1],p_param) == 0) {base--; count++;}
81  while(base + count < p_count && p_compare(p_container[base+count],p_param) == 0) {count++;}
82  p_range_base = base;
83  p_range_count = count;
84  return true;
85  }
86 
87 }
bsearch_callback_impl_permutation_t(const t_container &p_container, t_compare p_compare, const t_param &p_param, const t_permutation &p_permutation)
Definition: bsearch.h:35
int test(t_size p_index) const
Definition: bsearch.h:32
bool bsearch_range_t(const t_size p_count, const t_container &p_container, t_compare p_compare, const t_param &p_param, t_size &p_range_base, t_size &p_range_count)
Definition: bsearch.h:71
Decoder Validator v1 readme Usage Select a single file handled by the decoder you want to test
Definition: readme.txt:4
bsearch_callback_impl_simple_t(const t_container &p_container, t_compare p_compare, const t_param &p_param)
Definition: bsearch.h:19
bool bsearch_permutation_t(t_size p_count, const t_container &p_container, t_compare p_compare, const t_param &p_param, const t_permutation &p_permutation, t_size &p_index)
Definition: bsearch.h:56
const t_container & m_container
Definition: bsearch.h:24
size_t t_size
Definition: int_types.h:48
int test(t_size p_index) const
Definition: bsearch.h:16
const t_permutation & m_permutation
Definition: bsearch.h:43
bool bsearch_t(t_size p_count, const t_container &p_container, t_compare p_compare, const t_param &p_param, t_size &p_index)
Definition: bsearch.h:48
bool bsearch(t_size p_count, bsearch_callback const &p_callback, t_size &p_result)
Definition: bsearch.cpp:15