1 /* Bit_Matrix class implementation: inline functions.
2 Copyright (C) 2001-2010 Roberto Bagnara <bagnara@cs.unipr.it>
3 Copyright (C) 2010-2016 BUGSENG srl (http://bugseng.com)
4
5 This file is part of the Parma Polyhedra Library (PPL).
6
7 The PPL is free software; you can redistribute it and/or modify it
8 under the terms of the GNU General Public License as published by the
9 Free Software Foundation; either version 3 of the License, or (at your
10 option) any later version.
11
12 The PPL is distributed in the hope that it will be useful, but WITHOUT
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software Foundation,
19 Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1307, USA.
20
21 For the most up-to-date information see the Parma Polyhedra Library
22 site: http://bugseng.com/products/ppl/ . */
23
24 #ifndef PPL_Bit_Matrix_inlines_hh
25 #define PPL_Bit_Matrix_inlines_hh 1
26
27 #include "assertions.hh"
28 #include <algorithm>
29
30 namespace Parma_Polyhedra_Library {
31
32 inline
Bit_Matrix()33 Bit_Matrix::Bit_Matrix()
34 : rows(),
35 row_size(0) {
36 }
37
38 inline dimension_type
max_num_rows()39 Bit_Matrix::max_num_rows() {
40 return std::vector<Bit_Row>().max_size();
41 }
42
43 inline
Bit_Matrix(const dimension_type n_rows,const dimension_type n_columns)44 Bit_Matrix::Bit_Matrix(const dimension_type n_rows,
45 const dimension_type n_columns)
46 : rows(n_rows),
47 row_size(n_columns) {
48 }
49
50 inline
Bit_Matrix(const Bit_Matrix & y)51 Bit_Matrix::Bit_Matrix(const Bit_Matrix& y)
52 : rows(y.rows),
53 row_size(y.row_size) {
54 }
55
56 inline
~Bit_Matrix()57 Bit_Matrix::~Bit_Matrix() {
58 }
59
60 inline void
remove_trailing_rows(const dimension_type n)61 Bit_Matrix::remove_trailing_rows(const dimension_type n) {
62 // The number of rows to be erased cannot be greater
63 // than the actual number of the rows of the matrix.
64 PPL_ASSERT(n <= rows.size());
65 if (n != 0) {
66 rows.resize(rows.size() - n);
67 }
68 PPL_ASSERT(OK());
69 }
70
71 inline void
remove_trailing_columns(const dimension_type n)72 Bit_Matrix::remove_trailing_columns(const dimension_type n) {
73 // The number of columns to be erased cannot be greater
74 // than the actual number of the columns of the matrix.
75 PPL_ASSERT(n <= row_size);
76 row_size -= n;
77 PPL_ASSERT(OK());
78 }
79
80 inline void
m_swap(Bit_Matrix & y)81 Bit_Matrix::m_swap(Bit_Matrix& y) {
82 std::swap(row_size, y.row_size);
83 std::swap(rows, y.rows);
84 }
85
86 inline Bit_Row&
operator [](const dimension_type k)87 Bit_Matrix::operator[](const dimension_type k) {
88 PPL_ASSERT(k < rows.size());
89 return rows[k];
90 }
91
92 inline const Bit_Row&
operator [](const dimension_type k) const93 Bit_Matrix::operator[](const dimension_type k) const {
94 PPL_ASSERT(k < rows.size());
95 return rows[k];
96 }
97
98 inline dimension_type
num_columns() const99 Bit_Matrix::num_columns() const {
100 return row_size;
101 }
102
103 inline dimension_type
num_rows() const104 Bit_Matrix::num_rows() const {
105 return rows.size();
106 }
107
108 inline void
clear()109 Bit_Matrix::clear() {
110 // Clear `rows' and minimize its capacity.
111 std::vector<Bit_Row> tmp;
112 std::swap(tmp, rows);
113 row_size = 0;
114 }
115
116 inline memory_size_type
total_memory_in_bytes() const117 Bit_Matrix::total_memory_in_bytes() const {
118 return sizeof(*this) + external_memory_in_bytes();
119 }
120
121 inline bool
122 Bit_Matrix::Bit_Row_Less_Than::
operator ()(const Bit_Row & x,const Bit_Row & y) const123 operator()(const Bit_Row& x, const Bit_Row& y) const {
124 return compare(x, y) < 0;
125 }
126
127 inline bool
sorted_contains(const Bit_Row & row) const128 Bit_Matrix::sorted_contains(const Bit_Row& row) const {
129 PPL_ASSERT(check_sorted());
130 return std::binary_search(rows.begin(), rows.end(), row,
131 Bit_Row_Less_Than());
132 }
133
134 /*! \relates Bit_Matrix */
135 inline bool
operator !=(const Bit_Matrix & x,const Bit_Matrix & y)136 operator!=(const Bit_Matrix& x, const Bit_Matrix& y) {
137 return !(x == y);
138 }
139
140 /*! \relates Bit_Matrix */
141 inline void
swap(Bit_Matrix & x,Bit_Matrix & y)142 swap(Bit_Matrix& x, Bit_Matrix& y) {
143 x.m_swap(y);
144 }
145
146 } // namespace Parma_Polyhedra_Library
147
148 #endif // !defined(PPL_Bit_Matrix_inlines_hh)
149