barry: Your go-to motif accountant  0.0-1
Full enumeration of sample space and fast count of sufficient statistics for binary arrays
barraydenserow-bones.hpp
Go to the documentation of this file.
1 #ifndef BARRY_BARRAYDENSEROW_BONES_HPP
2 #define BARRY_BARRAYDENSEROW_BONES_HPP
3 
4 #define POS(a,b) (b) * N + (a)
5 #define POS_N(a,b,c) (b)*(c) + (a)
6 #define ZERO_CELL static_cast< Cell_Type >(0.0)
7 
8 template <typename Cell_Type = bool, typename Data_Type = bool>
10  friend class BArrayDense<Cell_Type,Data_Type>;
11  friend class BArrayDenseCell<Cell_Type,Data_Type>;
12  friend class BArrayDenseCell_const<Cell_Type,Data_Type>;
13 private:
16  size_t index;
17  bool row_filled = false; // after row is filled
18 
19  void fill_if_needed()
20  {
21  if (!row_filled)
22  {
23 
24  for (size_t j = 0u; j < array->M; ++j)
25  {
26 
27  if (array->el[POS_N(index, j, array->N)] != ZERO_CELL)
28  row[j] = row[POS_N(index, j, array->N)];
29 
30  }
31 
32  row_filled = true;
33 
34  }
35  }
36 
37 
38 public:
39 
42  size_t i
43  ) : array(&array_), index(i) {};
44 
46  {
47 
48  fill_if_needed();
49  return row.begin();
50 
51  };
52 
54  {
55 
56  fill_if_needed();
57  return row.end();
58 
59  };
60 
61  size_t size() const noexcept
62  {
63 
64  fill_if_needed();
65  return row.size();
66 
67  };
68 
69  std::pair<size_t,Cell<Cell_Type>> & operator()(size_t i)
70  {
71 
72  fill_if_needed();
73  return row[i];
74 
75  }
76 
77 };
78 
79 template <typename Cell_Type = bool, typename Data_Type = bool>
81  friend class BArrayDenseCell<Cell_Type,Data_Type>;
82  friend class BArrayDenseCell_const<Cell_Type,Data_Type>;
83 private:
86  size_t index;
87 
88 public:
91  size_t i
92  ) : array(&array_), index(i)
93  {
94 
95  for (size_t j = 0u; j < array->M; ++j)
96  {
97 
98  if (array->el[POS_N(index, j, array->M)] != ZERO_CELL)
99  row[j] = row[POS_N(index, j, array->M)];
100 
101  }
102 
103  return;
104 
105 
106  };
107 
109  {
110  return row.begin();
111  };
112 
114  {
115  return row.end();
116  };
117 
118  size_t size() const noexcept
119  {
120  return row.size();
121  };
122 
123  const std::pair<size_t,Cell<Cell_Type>> operator()(size_t i) const
124  {
125  return row[i];
126  }
127 
128 };
129 
130 #undef POS
131 #undef POS_N
132 #undef ZERO_CELL
133 
134 #endif
#define POS_N(a, b, c)
#define ZERO_CELL
Baseline class for binary arrays.
const std::pair< size_t, Cell< Cell_Type > > operator()(size_t i) const
BArrayDenseRow_const(const BArrayDense< Cell_Type, Data_Type > &array_, size_t i)
size_t size() const noexcept
Row_type< Cell_Type >::const_iterator end() const
Row_type< Cell_Type >::const_iterator begin() const
BArrayDenseRow(BArrayDense< Cell_Type, Data_Type > &array_, size_t i)
Row_type< Cell_Type >::iterator & begin()
size_t size() const noexcept
Row_type< Cell_Type >::iterator & end()
std::pair< size_t, Cell< Cell_Type > > & operator()(size_t i)
size_t size_t j
size_t i
Data_Type &&counter_ noexcept
Map< size_t, Cell< Cell_Type > > Row_type
Definition: typedefs.hpp:67