From 7336073618c7d862759add5cbbe45465e496b029 Mon Sep 17 00:00:00 2001 From: Stefan Huber Date: Tue, 14 Jan 2014 15:10:21 +0100 Subject: [PATCH] booleanvector: Use isempty() instead of size()==0 --- include/libstick-0.1/booleanmatrix.h | 6 +++--- include/libstick-0.1/booleanvector.h | 7 +++++-- include/libstick-0.1/persistence.h | 10 +++++----- 3 files changed, 13 insertions(+), 10 deletions(-) diff --git a/include/libstick-0.1/booleanmatrix.h b/include/libstick-0.1/booleanmatrix.h index 594eb92..b32e902 100644 --- a/include/libstick-0.1/booleanmatrix.h +++ b/include/libstick-0.1/booleanmatrix.h @@ -53,7 +53,7 @@ class boolean_colmatrix_base { size_t height() const { IT h = 0; for (unsigned c=0; c < width(); ++c) - if (cols[c].size() > 0) + if (!cols[c].isempty()) h = std::max(h, cols[c].back()); return h+1; } @@ -513,7 +513,7 @@ std::ostream& operator<<(std::ostream &os, const boolean_colmatrix_base & os << "-"; - if (col.size() != 0) + if (!col.isempty()) height = std::max(height, col.back()); } @@ -524,7 +524,7 @@ std::ostream& operator<<(std::ostream &os, const boolean_colmatrix_base & for (unsigned c=0; c < mat.width(); ++c) { std::list &col = cols.at(c); // This column is already empty - if (col.size() == 0) + if (col.isempty()) os << " "; else if (col.front() == r) { os << "X"; diff --git a/include/libstick-0.1/booleanvector.h b/include/libstick-0.1/booleanvector.h index d7eb41b..5d87063 100644 --- a/include/libstick-0.1/booleanvector.h +++ b/include/libstick-0.1/booleanvector.h @@ -251,8 +251,11 @@ class heapsorted_boolean_vector { /** Returns true if vector contains no 1. */ bool isempty() const { - strip_heap(); - return isheap ? heapsize==0 : array.size()==0; + if (isheap) { + strip_heap(); + return heapsize == 0; + } else + return array.size() == 0; } /** Print this vector */ diff --git a/include/libstick-0.1/persistence.h b/include/libstick-0.1/persistence.h index ea73693..d7cc25f 100644 --- a/include/libstick-0.1/persistence.h +++ b/include/libstick-0.1/persistence.h @@ -117,7 +117,7 @@ class persistence { //if (c % 100 == 0) //std::cout << "c = " << c << " (" << (100.0*float(c)/rbm.width()) << " %)" << std::endl; // Reduce as long as we need to reduce - while (rbm.get_column(c).size() > 0) { + while (!rbm.get_column(c).isempty()) { // (r, c) is the lowest one of col const IT r = rbm.get_column(c).back(); // This column contains its lowest one on the same row @@ -137,7 +137,7 @@ class persistence { } // A lowest one remained, recall it - if (rbm.get_column(c).size() > 0) { + if (!rbm.get_column(c).isempty()) { const IT r = rbm.get_column(c).back(); assert(lowestones[r] == 0); assert(r < c); @@ -204,7 +204,7 @@ class persistence { os << " boundary: " << bm.get_column(c) << std::endl; typename boolean_colmatrix::column_type col = rbm.get_column(c); - if (col.size() == 0) { + if (col.isempty()) { os << " \033[1;32mbirth\033[0;m of a cycle: " << tm.get_column(c) << std::endl; } else { os << " \033[1;31mdeath\033[0;m of a cycle: " << rbm.get_column(c) << std::endl; @@ -240,7 +240,7 @@ class persistence { for (unsigned c=0; c < lowestones.size(); ++c) { // A cycle was born - if (rbm.get_column(c).size() == 0) { + if (rbm.get_column(c).isempty()) { const int dim = order.get_simplex(c).dim; // Create a diagram point @@ -265,7 +265,7 @@ class persistence { // or not be, tertium non datur. for (unsigned c=0; c < lowestones.size(); ++c) { // A class died with c - if (rbm.get_column(c).size() != 0) + if (!rbm.get_column(c).isempty()) assert(c == 0 || deaths.count(c) > 0); else assert(births.count(c) > 0); -- 2.39.5