From b9375fdc80a9b73d3f2f4e0d867d8a5c15e1a200 Mon Sep 17 00:00:00 2001 From: "James D. Mitchell" Date: Sun, 29 Oct 2023 13:26:40 +0000 Subject: [PATCH] Remove names starting with underscore --- include/perm_generic.hpp | 8 ++-- include/perm_generic_impl.hpp | 73 +++++++++++++++-------------- include/vect_generic.hpp | 86 +++++++++++++++++------------------ 3 files changed, 83 insertions(+), 84 deletions(-) diff --git a/include/perm_generic.hpp b/include/perm_generic.hpp index d9c0b94f..3420daa7 100644 --- a/include/perm_generic.hpp +++ b/include/perm_generic.hpp @@ -24,11 +24,11 @@ namespace HPCombi { -template -struct PermGeneric : public VectGeneric<_Size, Expo> { - using vect = VectGeneric<_Size, Expo>; +template +struct PermGeneric : public VectGeneric { + using vect = VectGeneric; - static constexpr size_t size() { return _Size; } + static constexpr size_t size() { return Size; } PermGeneric() = default; PermGeneric(const vect v) : vect(v) {} // NOLINT diff --git a/include/perm_generic_impl.hpp b/include/perm_generic_impl.hpp index 19f3ee49..ba145747 100644 --- a/include/perm_generic_impl.hpp +++ b/include/perm_generic_impl.hpp @@ -15,34 +15,34 @@ namespace HPCombi { -template -PermGeneric<_Size, Expo>::PermGeneric(std::initializer_list il) { - assert(il.size() <= _Size); +template +PermGeneric::PermGeneric(std::initializer_list il) { + assert(il.size() <= Size); std::copy(il.begin(), il.end(), this->v.begin()); - for (Expo i = il.size(); i < _Size; i++) + for (Expo i = il.size(); i < Size; i++) this->v[i] = i; } -template -PermGeneric<_Size, Expo> -PermGeneric<_Size, Expo>::elementary_transposition(uint64_t i) { - assert(i < _Size); +template +PermGeneric +PermGeneric::elementary_transposition(uint64_t i) { + assert(i < Size); PermGeneric res{{}}; res[i] = i + 1; res[i + 1] = i; return res; } -template -PermGeneric<_Size, Expo> PermGeneric<_Size, Expo>::inverse() const { +template +PermGeneric PermGeneric::inverse() const { PermGeneric res; - for (uint64_t i = 0; i < _Size; i++) + for (uint64_t i = 0; i < Size; i++) res[this->v[i]] = i; return res; } -template -PermGeneric<_Size, Expo> PermGeneric<_Size, Expo>::random() { +template +PermGeneric PermGeneric::random() { static std::random_device rd; static std::mt19937 g(rd()); @@ -51,41 +51,40 @@ PermGeneric<_Size, Expo> PermGeneric<_Size, Expo>::random() { return res; } -template -typename PermGeneric<_Size, Expo>::vect -PermGeneric<_Size, Expo>::lehmer() const { +template +typename PermGeneric::vect PermGeneric::lehmer() const { vect res{}; - for (size_t i = 0; i < _Size; i++) - for (size_t j = i + 1; j < _Size; j++) + for (size_t i = 0; i < Size; i++) + for (size_t j = i + 1; j < Size; j++) if (this->v[i] > this->v[j]) res[i]++; return res; } -template -uint64_t PermGeneric<_Size, Expo>::length() const { +template +uint64_t PermGeneric::length() const { uint64_t res = 0; - for (size_t i = 0; i < _Size; i++) - for (size_t j = i + 1; j < _Size; j++) + for (size_t i = 0; i < Size; i++) + for (size_t j = i + 1; j < Size; j++) if (this->v[i] > this->v[j]) res++; return res; } -template -uint64_t PermGeneric<_Size, Expo>::nb_descents() const { +template +uint64_t PermGeneric::nb_descents() const { uint64_t res = 0; - for (size_t i = 0; i < _Size - 1; i++) + for (size_t i = 0; i < Size - 1; i++) if (this->v[i] > this->v[i + 1]) res++; return res; } -template -uint64_t PermGeneric<_Size, Expo>::nb_cycles() const { - std::array b{}; +template +uint64_t PermGeneric::nb_cycles() const { + std::array b{}; uint64_t c = 0; - for (size_t i = 0; i < _Size; i++) { + for (size_t i = 0; i < Size; i++) { if (!b[i]) { for (size_t j = i; !b[j]; j = this->v[j]) b[j] = true; @@ -95,10 +94,10 @@ uint64_t PermGeneric<_Size, Expo>::nb_cycles() const { return c; } -template -bool PermGeneric<_Size, Expo>::left_weak_leq(PermGeneric other) const { - for (size_t i = 0; i < _Size; i++) { - for (size_t j = i + 1; j < _Size; j++) { +template +bool PermGeneric::left_weak_leq(PermGeneric other) const { + for (size_t i = 0; i < Size; i++) { + for (size_t j = i + 1; j < Size; j++) { if ((this->v[i] > this->v[j]) && (other[i] < other[j])) return false; } @@ -110,10 +109,10 @@ bool PermGeneric<_Size, Expo>::left_weak_leq(PermGeneric other) const { namespace std { -template -struct hash> { - size_t operator()(const HPCombi::PermGeneric<_Size, Expo> &ar) const { - return hash>()(ar); +template +struct hash> { + size_t operator()(const HPCombi::PermGeneric &ar) const { + return hash>()(ar); } }; diff --git a/include/vect_generic.hpp b/include/vect_generic.hpp index 40d6309a..d549615e 100644 --- a/include/vect_generic.hpp +++ b/include/vect_generic.hpp @@ -34,15 +34,15 @@ std::array sorted_vect(std::array v) { /** A generic class for combinatorial integer vectors. */ -template struct VectGeneric { - static constexpr size_t size() { return _Size; } - using array = std::array; +template struct VectGeneric { + static constexpr size_t size() { return Size; } + using array = std::array; array v; VectGeneric() = default; - VectGeneric(const std::array &_v) : v(_v) {} // NOLINT + VectGeneric(const std::array &_v) : v(_v) {} // NOLINT VectGeneric(std::initializer_list il, Expo def = 0) { - assert(il.size() <= _Size); + assert(il.size() <= Size); std::copy(il.begin(), il.end(), v.begin()); std::fill(v.begin() + il.size(), v.end(), def); } @@ -56,20 +56,20 @@ template struct VectGeneric { Expo operator[](uint64_t i) const { return v[i]; } Expo &operator[](uint64_t i) { return v[i]; } - size_t first_diff(const VectGeneric &u, size_t bound = _Size) const { + size_t first_diff(const VectGeneric &u, size_t bound = Size) const { for (size_t i = 0; i < bound; i++) if (v[i] != u[i]) return i; - return _Size; + return Size; } - size_t last_diff(const VectGeneric &u, size_t bound = _Size) const { + size_t last_diff(const VectGeneric &u, size_t bound = Size) const { while (bound != 0) { --bound; if (u[bound] != v[bound]) return bound; } - return _Size; + return Size; } using value_type = Expo; @@ -81,25 +81,25 @@ template struct VectGeneric { const_iterator end() const { return v.end(); } bool operator==(const VectGeneric &u) const { - return first_diff(u) == _Size; + return first_diff(u) == Size; } bool operator!=(const VectGeneric &u) const { - return first_diff(u) != _Size; + return first_diff(u) != Size; } bool operator<(const VectGeneric &u) const { uint64_t diff = first_diff(u); - return (diff != _Size) && v[diff] < u[diff]; + return (diff != Size) && v[diff] < u[diff]; } int8_t less_partial(const VectGeneric &u, int k) const { uint64_t diff = first_diff(u, k); - return (diff == _Size) ? 0 : int8_t(v[diff]) - int8_t(u[diff]); + return (diff == Size) ? 0 : int8_t(v[diff]) - int8_t(u[diff]); } VectGeneric permuted(const VectGeneric &u) const { VectGeneric res; - for (uint64_t i = 0; i < _Size; i++) + for (uint64_t i = 0; i < Size; i++) res[i] = v[u[i]]; return res; } @@ -107,7 +107,7 @@ template struct VectGeneric { void sort() { std::sort(v.begin(), v.end()); } bool is_sorted() const { - for (uint64_t i = 1; i < _Size; i++) + for (uint64_t i = 1; i < Size; i++) if (v[i - 1] < v[i]) return false; return true; @@ -117,43 +117,43 @@ template struct VectGeneric { static std::random_device rd; static std::mt19937 g(rd()); - VectGeneric<_Size, Expo> res = VectGeneric<_Size, Expo>(0, 0); + VectGeneric res = VectGeneric(0, 0); std::shuffle(res.begin(), res.end(), g); return res; } - uint64_t first_non_zero(size_t bound = _Size) const { + uint64_t first_non_zero(size_t bound = Size) const { for (uint64_t i = 0; i < bound; i++) if (v[i] != 0) return i; - return _Size; + return Size; } - uint64_t first_zero(size_t bound = _Size) const { + uint64_t first_zero(size_t bound = Size) const { for (uint64_t i = 0; i < bound; i++) if (v[i] == 0) return i; - return _Size; + return Size; } - uint64_t last_non_zero(size_t bound = _Size) const { + uint64_t last_non_zero(size_t bound = Size) const { for (int64_t i = bound - 1; i >= 0; i--) if (v[i] != 0) return i; - return _Size; + return Size; } - uint64_t last_zero(size_t bound = _Size) const { + uint64_t last_zero(size_t bound = Size) const { for (int64_t i = bound - 1; i >= 0; i--) if (v[i] == 0) return i; - return _Size; + return Size; } - bool is_permutation(const size_t k = _Size) const { + bool is_permutation(const size_t k = Size) const { auto temp = v; std::sort(temp.begin(), temp.end()); - for (uint64_t i = 0; i < _Size; i++) + for (uint64_t i = 0; i < Size; i++) if (temp[i] != i) return false; - for (uint64_t i = k; i < _Size; i++) + for (uint64_t i = k; i < Size; i++) if (v[i] != i) return false; return true; @@ -161,51 +161,51 @@ template struct VectGeneric { uint64_t horiz_sum() const { Expo res = 0; - for (uint64_t i = 0; i < _Size; i++) + for (uint64_t i = 0; i < Size; i++) res += v[i]; return res; } VectGeneric partial_sums() const { auto res = *this; - for (uint64_t i = 1; i < _Size; i++) + for (uint64_t i = 1; i < Size; i++) res[i] += res[i - 1]; return res; } void partial_sums_inplace() { - for (uint64_t i = 1; i < _Size; i++) + for (uint64_t i = 1; i < Size; i++) v[i] += v[i - 1]; } Expo horiz_max() const { Expo res = v[0]; - for (uint64_t i = 1; i < _Size; i++) + for (uint64_t i = 1; i < Size; i++) res = std::max(res, v[i]); return res; } void partial_max_inplace() { - for (uint64_t i = 1; i < _Size; i++) + for (uint64_t i = 1; i < Size; i++) v[i] = std::max(v[i], v[i - 1]); } Expo horiz_min() const { Expo res = v[0]; - for (uint64_t i = 1; i < _Size; i++) + for (uint64_t i = 1; i < Size; i++) res = std::min(res, v[i]); return res; } void partial_min_inplace() { - for (uint64_t i = 1; i < _Size; i++) + for (uint64_t i = 1; i < Size; i++) v[i] = std::min(v[i], v[i - 1]); } VectGeneric eval() const { VectGeneric res{}; - for (size_t i = 0; i < _Size; i++) - if (v[i] < _Size) + for (size_t i = 0; i < Size; i++) + if (v[i] < Size) res[v[i]]++; return res; } @@ -218,21 +218,21 @@ static_assert(std::is_trivial>(), namespace std { -template +template std::ostream &operator<<(std::ostream &stream, - const HPCombi::VectGeneric<_Size, Expo> &v) { + const HPCombi::VectGeneric &v) { stream << "{" << std::setw(2) << unsigned(v[0]); - for (unsigned i = 1; i < _Size; ++i) + for (unsigned i = 1; i < Size; ++i) stream << "," << std::setw(2) << unsigned(v[i]); stream << "}"; return stream; } -template -struct hash> { - size_t operator()(const HPCombi::VectGeneric<_Size, Expo> &ar) const { +template +struct hash> { + size_t operator()(const HPCombi::VectGeneric &ar) const { size_t h = 0; - for (size_t i = 0; i < _Size; i++) + for (size_t i = 0; i < Size; i++) h = hash()(ar[i]) + (h << 6) + (h << 16) - h; return h; }