barry: Your go-to motif accountant  0.0-1
Full enumeration of sample space and fast count of sufficient statistics for binary arrays
barrayvector-bones.hpp
Go to the documentation of this file.
1 #ifndef BARRY_BARRAYVECTOR_BONES_HPP
2 #define BARRY_BARRAYVECTOR_BONES_HPP 1
3 
10 template <typename Cell_Type = bool, typename Data_Type = bool>
11 class BArrayVector {
12 private:
13 
15  std::vector< std::pair< size_t, Cell_Type > > vec;
16  size_t dim;
17  size_t i;
18 
19  void init_vec();
20  bool vec_initialized = false;
21 
22 public:
23 
34  size_t & dim_
35  size_t & i_,
36  bool check_bounds = true
37  ) :
38  Array(Array_), vec(0u), dim(dim_), i(i_) {
39 
40  if (dim > 1u)
41  throw std::range_error("-dim_- should be either 0 (row) or 1 (col).");
42 
43  if (check_bounds) {
44 
45  if ((dim == 0u) && (i >= Array->nrow()))
46  throw std::length_error("Row out of range.");
47  if ((dim == 1u) && (j >= Array->ncol()))
48  throw std::length_error("Col out of range.");
49 
50  }
51  };
52 
54 
55  bool is_row() const noexcept;
56  bool is_col() const noexcept;
57  size_t size() const noexcept;
58  std::vector< Cell_Type >::const_iterator begin() noexcept;
59  std::vector< Cell_Type >::const_iterator end() noexcept;
60 
61  void operator=(const Cell_Type & val);
62  void operator+=(const Cell_Type & val);
63  void operator-=(const Cell_Type & val);
64  void operator*=(const Cell_Type & val);
65  void operator/=(const Cell_Type & val);
66 
67  operator std::vector< Cell_Type >() const;
68  bool operator==(const Cell_Type & val) const;
69 
70 };
71 
72 template <typename Cell_Type = bool, typename Data_Type = bool>
74 private:
75 
76  const BArray<Cell_Type,Data_Type> * Array;
77  std::vector< std::pair< size_t, Cell_Type > > vec;
78  size_t dim;
79  size_t i;
80 
81  void init_vec();
82  bool vec_initialized = false;
83 
84 public:
85 
87  const BArray<Cell_Type,Data_Type> * Array_,
88  size_t & dim_
89  size_t & i_,
90  bool check_bounds = true
91  ) :
92  Array(Array_), vec(0u), dim(dim_), i(i_) {
93 
94  if (dim > 1u)
95  throw std::range_error("-dim_- should be either 0 (row) or 1 (col).");
96 
97  if (check_bounds) {
98 
99  if ((dim == 0u) && (i >= Array->nrow()))
100  throw std::length_error("Row out of range.");
101  if ((dim == 1u) && (j >= Array->ncol()))
102  throw std::length_error("Col out of range.");
103 
104  }
105 
106  };
107 
109 
110  bool is_row() const noexcept;
111  bool is_col() const noexcept;
112  size_t size() const noexcept;
113  std::vector< Cell_Type >::const_iterator begin() noexcept;
114  std::vector< Cell_Type >::const_iterator end() noexcept;
115 
116  operator std::vector<Cell_Type>() const;
117  bool operator==(const Cell_Type & val) const;
118  bool operator!=(const Cell_Type & val) const;
119  bool operator<(const Cell_Type & val) const;
120  bool operator>(const Cell_Type & val) const;
121  bool operator<=(const Cell_Type & val) const;
122  bool operator>=(const Cell_Type & val) const;
123 
124 };
125 
126 #endif
size_t ncol() const noexcept
size_t nrow() const noexcept
BArrayVector_const(const BArray< Cell_Type, Data_Type > *Array_, size_t &dim_ size_t &i_, bool check_bounds=true)
bool is_row() const noexcept
Row or column of a BArray
size_t size() const noexcept
bool is_row() const noexcept
BArrayVector(BArray< Cell_Type, Data_Type > *Array_, size_t &dim_ size_t &i_, bool check_bounds=true)
Construct a new BArrayVector object.
std::vector< Cell_Type >::const_iterator begin() noexcept
bool is_col() const noexcept
std::vector< Cell_Type >::const_iterator end() noexcept
size_t size_t j
size_t i
Data_Type &&counter_ noexcept