foobar2000 SDK  2015-08-03
order_helper.h
Go to the documentation of this file.
1 namespace pfc {
2  PFC_DECLARE_EXCEPTION( exception_invalid_permutation, exception_invalid_params, "Invalid permutation" );
3  t_size permutation_find_reverse(t_size const * order, t_size count, t_size value);
4 
6  bool permutation_is_valid(t_size const * order, t_size count);
8  void permutation_validate(t_size const * order, t_size count);
9 
11  void create_move_items_permutation(t_size * p_output,t_size p_count,const class bit_array & p_selection,int p_delta);
12 }
13 
15 {
17 public:
18  order_helper(t_size p_size) {
19  m_data.set_size(p_size);
20  for(t_size n=0;n<p_size;n++) m_data[n]=n;
21  }
22 
23  order_helper(const order_helper & p_order) {*this = p_order;}
24 
25  static bool g_is_identity(const t_size * order, t_size count) {
26  for(t_size walk = 0; walk < count; ++walk) {
27  if (order[walk] != walk) return false;
28  }
29  return true;
30  }
31  template<typename t_array> static bool g_is_identity(const t_array & p_array) {
32  const t_size count = pfc::array_size_t(p_array);
33  for(t_size walk = 0; walk < count; ++walk) if (p_array[walk] != walk) return false;
34  return true;
35  }
36 
37  template<typename t_int>
38  static void g_fill(t_int * p_order,const t_size p_count) {
39  t_size n; for(n=0;n<p_count;n++) p_order[n] = (t_int)n;
40  }
41 
42  template<typename t_array>
43  static void g_fill(t_array & p_array) {
44  t_size n; const t_size max = pfc::array_size_t(p_array);
45  for(n=0;n<max;n++) p_array[n] = n;
46  }
47 
48 
49  t_size get_item(t_size ptr) const {return m_data[ptr];}
50 
51  t_size & operator[](t_size ptr) {return m_data[ptr];}
52  t_size operator[](t_size ptr) const {return m_data[ptr];}
53 
54  static void g_swap(t_size * p_data,t_size ptr1,t_size ptr2);
55  inline void swap(t_size ptr1,t_size ptr2) {pfc::swap_t(m_data[ptr1],m_data[ptr2]);}
56 
57  const t_size * get_ptr() const {return m_data.get_ptr();}
58 
60  static t_size g_find_reverse(const t_size * order,t_size val);
62  inline t_size find_reverse(t_size val) {return g_find_reverse(m_data.get_ptr(),val);}
63 
64  static void g_reverse(t_size * order,t_size base,t_size count);
65  inline void reverse(t_size base,t_size count) {g_reverse(m_data.get_ptr(),base,count);}
66 
67  t_size get_count() const {return m_data.get_size();}
68 };
const t_item * get_ptr() const
Definition: array.h:213
t_size get_count() const
Definition: order_helper.h:67
static void g_fill(t_int *p_order, const t_size p_count)
Definition: order_helper.h:38
pfc::array_t< t_size > m_data
Definition: order_helper.h:16
t_size find_reverse(t_size val)
Insecure - may deadlock or crash on invalid permutation content. In theory faster than walking the pe...
Definition: order_helper.h:62
static bool g_is_identity(const t_array &p_array)
Definition: order_helper.h:31
Bit array interface class, constant version (you can only retrieve values). Range of valid indexes d...
Definition: bit_array.h:6
int t_int
Definition: int_types.h:11
void swap(t_size ptr1, t_size ptr2)
Definition: order_helper.h:55
void permutation_validate(t_size const *order, t_size count)
For critical sanity checks. Speed: O(n), allocates memory.
Definition: other.cpp:26
order_helper(t_size p_size)
Definition: order_helper.h:18
t_size get_item(t_size ptr) const
Definition: order_helper.h:49
t_size permutation_find_reverse(t_size const *order, t_size count, t_size value)
Definition: other.cpp:30
t_size operator[](t_size ptr) const
Definition: order_helper.h:52
size_t t_size
Definition: int_types.h:48
void set_size(t_size p_size)
Definition: array.h:104
t_size & operator[](t_size ptr)
Definition: order_helper.h:51
bool permutation_is_valid(t_size const *order, t_size count)
For critical sanity checks. Speed: O(n), allocates memory.
Definition: other.cpp:17
void create_move_items_permutation(t_size *p_output, t_size p_count, const class bit_array &p_selection, int p_delta)
Creates a permutation that moves selected items in a list box by the specified delta-offset.
t_size array_size_t(const t_array &p_array)
Definition: primitives.h:309
const t_size * get_ptr() const
Definition: order_helper.h:57
static bool g_is_identity(const t_size *order, t_size count)
Definition: order_helper.h:25
order_helper(const order_helper &p_order)
Definition: order_helper.h:23
void swap_t(T &p_item1, T &p_item2)
Definition: primitives.h:285
void reverse(t_size base, t_size count)
Definition: order_helper.h:65
PFC_DECLARE_EXCEPTION(exception_map_entry_not_found, exception,"Map entry not found")
t_size get_size() const
Definition: array.h:130
static void g_fill(t_array &p_array)
Definition: order_helper.h:43