diff options
author | Xiaoxu Guo <shimo11370@proton.me> | 2024-07-26 08:32:37 +0800 |
---|---|---|
committer | Xiaoxu Guo <shimo11370@proton.me> | 2024-07-26 08:32:37 +0800 |
commit | b1e82d19303ae440a7f9ff2989582424735f797e (patch) | |
tree | 70f655312eeac5ee9ac3db53e55354344a9dded9 | |
parent | 60eccba2a1c013f6831394429b0a521a9afb8db0 (diff) | |
download | shoka-b1e82d19303ae440a7f9ff2989582424735f797e.tar.gz shoka-b1e82d19303ae440a7f9ff2989582424735f797e.zip |
added
-rw-r--r-- | debug.h | 6 | ||||
-rw-r--r-- | fixed_size_upper_matrix.h | 4 | ||||
-rw-r--r-- | snippets/group.h | 16 |
3 files changed, 20 insertions, 6 deletions
@@ -50,9 +50,9 @@ template <typename T> ostream &operator<<(ostream &out, const Binary<T> &b) { return out << ")_2"; } -template <ranges::forward_range RangeT> -ostream &operator<<(ostream &out, RangeT &&range) - requires(!same_as<ranges::range_value_t<RangeT>, char>) +template <ranges::forward_range Range> +ostream &operator<<(ostream &out, Range &&range) + requires(!same_as<ranges::range_value_t<Range>, char>) { out << "["; bool first = true; diff --git a/fixed_size_upper_matrix.h b/fixed_size_upper_matrix.h index 307d648..5df624b 100644 --- a/fixed_size_upper_matrix.h +++ b/fixed_size_upper_matrix.h @@ -1,10 +1,8 @@ #pragma once #include <array> -#include <cstdint> #include <cstring> #include <initializer_list> -#include <vector> template <typename T, int N> struct FixedSizeUpperMatrixT : std::array<std::array<T, N>, N> { @@ -58,7 +56,7 @@ struct FixedSizeUpperMatrixT : std::array<std::array<T, N>, N> { buffer[i] = o[i][j]; } for (int i = 0; i <= j; ++i) { - for (int k = i; k < N; ++k) { + for (int k = i; k <= j; ++k) { result[i][j] += (*this)[i][k] * buffer[k]; } } diff --git a/snippets/group.h b/snippets/group.h new file mode 100644 index 0000000..bd183e0 --- /dev/null +++ b/snippets/group.h @@ -0,0 +1,16 @@ +#pragma once + +#include <functional> +#include <ranges> + +template <std::ranges::random_access_range Range> +void group(const Range &v, const std::function<void(int, int)> &fn) { + int n = v.size(); + for (int i = 0; i < n;) { + auto i0 = i; + while (i < n && v[i0] == v[i]) { + i++; + } + fn(i0, i); + } +} |