foobar2000 SDK  2015-08-03
Public Member Functions | Static Public Member Functions | Private Attributes
order_helper

#include <order_helper.h>

Public Member Functions

 order_helper (t_size p_size)
 
 order_helper (const order_helper &p_order)
 
t_size find_reverse (t_size val)
 
t_size get_count () const
 
t_size get_item (t_size ptr) const
 
const t_sizeget_ptr () const
 
t_sizeoperator[] (t_size ptr)
 
t_size operator[] (t_size ptr) const
 
void reverse (t_size base, t_size count)
 
void swap (t_size ptr1, t_size ptr2)
 

Static Public Member Functions

template<typename t_int >
static void g_fill (t_int *p_order, const t_size p_count)
 
template<typename t_array >
static void g_fill (t_array &p_array)
 
static t_size g_find_reverse (const t_size *order, t_size val)
 
static bool g_is_identity (const t_size *order, t_size count)
 
template<typename t_array >
static bool g_is_identity (const t_array &p_array)
 
static void g_reverse (t_size *order, t_size base, t_size count)
 
static void g_swap (t_size *p_data, t_size ptr1, t_size ptr2)
 

Private Attributes

pfc::array_t< t_sizem_data
 

Detailed Description

Definition at line 14 of file order_helper.h.

Constructor & Destructor Documentation

order_helper::order_helper ( t_size  p_size)
inline

Definition at line 18 of file order_helper.h.

18  {
19  m_data.set_size(p_size);
20  for(t_size n=0;n<p_size;n++) m_data[n]=n;
21  }
pfc::array_t< t_size > m_data
Definition: order_helper.h:16
size_t t_size
Definition: int_types.h:48
void set_size(t_size p_size)
Definition: array.h:104
order_helper::order_helper ( const order_helper p_order)
inline

Definition at line 23 of file order_helper.h.

23 {*this = p_order;}

Member Function Documentation

t_size order_helper::find_reverse ( t_size  val)
inline

Insecure - may deadlock or crash on invalid permutation content. In theory faster than walking the permutation, but still O(n).

Definition at line 62 of file order_helper.h.

62 {return g_find_reverse(m_data.get_ptr(),val);}
const t_item * get_ptr() const
Definition: array.h:213
pfc::array_t< t_size > m_data
Definition: order_helper.h:16
static t_size g_find_reverse(const t_size *order, t_size val)
Insecure - may deadlock or crash on invalid permutation content. In theory faster than walking the pe...
Definition: other.cpp:90
template<typename t_int >
static void order_helper::g_fill ( t_int p_order,
const t_size  p_count 
)
inlinestatic

Definition at line 38 of file order_helper.h.

38  {
39  t_size n; for(n=0;n<p_count;n++) p_order[n] = (t_int)n;
40  }
int t_int
Definition: int_types.h:11
size_t t_size
Definition: int_types.h:48
template<typename t_array >
static void order_helper::g_fill ( t_array &  p_array)
inlinestatic

Definition at line 43 of file order_helper.h.

43  {
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  }
size_t t_size
Definition: int_types.h:48
t_size array_size_t(const t_array &p_array)
Definition: primitives.h:309
t_size order_helper::g_find_reverse ( const t_size order,
t_size  val 
)
static

Insecure - may deadlock or crash on invalid permutation content. In theory faster than walking the permutation, but still O(n).

Definition at line 90 of file other.cpp.

91 {
92  t_size prev = val, next = order[val];
93  while(next != val)
94  {
95  prev = next;
96  next = order[next];
97  }
98  return prev;
99 }
size_t t_size
Definition: int_types.h:48
static bool order_helper::g_is_identity ( const t_size order,
t_size  count 
)
inlinestatic

Definition at line 25 of file order_helper.h.

25  {
26  for(t_size walk = 0; walk < count; ++walk) {
27  if (order[walk] != walk) return false;
28  }
29  return true;
30  }
size_t t_size
Definition: int_types.h:48
template<typename t_array >
static bool order_helper::g_is_identity ( const t_array &  p_array)
inlinestatic

Definition at line 31 of file order_helper.h.

31  {
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  }
size_t t_size
Definition: int_types.h:48
t_size array_size_t(const t_array &p_array)
Definition: primitives.h:309
void order_helper::g_reverse ( t_size order,
t_size  base,
t_size  count 
)
static

Definition at line 102 of file other.cpp.

103 {
104  t_size max = count>>1;
105  t_size n;
106  t_size base2 = base+count-1;
107  for(n=0;n<max;n++)
108  g_swap(order,base+n,base2-n);
109 }
static void g_swap(t_size *p_data, t_size ptr1, t_size ptr2)
Definition: other.cpp:82
size_t t_size
Definition: int_types.h:48
void order_helper::g_swap ( t_size p_data,
t_size  ptr1,
t_size  ptr2 
)
static

Definition at line 82 of file other.cpp.

83 {
84  t_size temp = data[ptr1];
85  data[ptr1] = data[ptr2];
86  data[ptr2] = temp;
87 }
size_t t_size
Definition: int_types.h:48
t_size order_helper::get_count ( ) const
inline

Definition at line 67 of file order_helper.h.

67 {return m_data.get_size();}
pfc::array_t< t_size > m_data
Definition: order_helper.h:16
t_size get_size() const
Definition: array.h:130
t_size order_helper::get_item ( t_size  ptr) const
inline

Definition at line 49 of file order_helper.h.

49 {return m_data[ptr];}
pfc::array_t< t_size > m_data
Definition: order_helper.h:16
const t_size* order_helper::get_ptr ( ) const
inline

Definition at line 57 of file order_helper.h.

57 {return m_data.get_ptr();}
const t_item * get_ptr() const
Definition: array.h:213
pfc::array_t< t_size > m_data
Definition: order_helper.h:16
t_size& order_helper::operator[] ( t_size  ptr)
inline

Definition at line 51 of file order_helper.h.

51 {return m_data[ptr];}
pfc::array_t< t_size > m_data
Definition: order_helper.h:16
t_size order_helper::operator[] ( t_size  ptr) const
inline

Definition at line 52 of file order_helper.h.

52 {return m_data[ptr];}
pfc::array_t< t_size > m_data
Definition: order_helper.h:16
void order_helper::reverse ( t_size  base,
t_size  count 
)
inline

Definition at line 65 of file order_helper.h.

65 {g_reverse(m_data.get_ptr(),base,count);}
const t_item * get_ptr() const
Definition: array.h:213
pfc::array_t< t_size > m_data
Definition: order_helper.h:16
static void g_reverse(t_size *order, t_size base, t_size count)
Definition: other.cpp:102
void order_helper::swap ( t_size  ptr1,
t_size  ptr2 
)
inline

Definition at line 55 of file order_helper.h.

55 {pfc::swap_t(m_data[ptr1],m_data[ptr2]);}
pfc::array_t< t_size > m_data
Definition: order_helper.h:16
void swap_t(T &p_item1, T &p_item2)
Definition: primitives.h:285

Field Documentation

pfc::array_t<t_size> order_helper::m_data
private

Definition at line 16 of file order_helper.h.


The documentation for this class was generated from the following files: