summaryrefslogtreecommitdiffstatshomepage
path: root/src/lib/netlist/plib/pmatrix2d.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/netlist/plib/pmatrix2d.h')
-rw-r--r--src/lib/netlist/plib/pmatrix2d.h99
1 files changed, 99 insertions, 0 deletions
diff --git a/src/lib/netlist/plib/pmatrix2d.h b/src/lib/netlist/plib/pmatrix2d.h
index b48c531a921..33e3169c64a 100644
--- a/src/lib/netlist/plib/pmatrix2d.h
+++ b/src/lib/netlist/plib/pmatrix2d.h
@@ -67,6 +67,12 @@ namespace plib
return (*this)[r][c];
}
+ // for compatibility with vrl variant
+ void set(size_type r, size_type c, const T &v) noexcept
+ {
+ (*this)[r][c] = v;
+ }
+
T * data() noexcept
{
return m_v.data();
@@ -90,6 +96,99 @@ namespace plib
std::vector<T, A> m_v;
};
+ // variable row length matrix
+ template<typename T, typename A = aligned_allocator<T>>
+ class pmatrix2d_vrl
+ {
+ public:
+ using size_type = std::size_t;
+ using value_type = T;
+ using allocator_type = A;
+
+ static constexpr const size_type align_size = align_traits<A>::align_size;
+ static constexpr const size_type stride_size = align_traits<A>::stride_size;
+ pmatrix2d_vrl() noexcept
+ : m_N(0), m_M(0), m_v()
+ {
+ }
+
+ pmatrix2d_vrl(size_type N, size_type M)
+ : m_N(N), m_M(M), m_v()
+ {
+ m_row.resize(N + 1, 0);
+ m_v.resize(N); //FIXME
+ }
+
+ void resize(size_type N, size_type M)
+ {
+ m_N = N;
+ m_M = M;
+ m_row.resize(N + 1);
+ for (std::size_t i = 0; i < m_N; i++)
+ m_row[i] = 0;
+ m_v.resize(N); //FIXME
+ }
+
+ constexpr T * operator[] (size_type row) noexcept
+ {
+ return &(m_v[m_row[row]]);
+ }
+
+ constexpr const T * operator[] (size_type row) const noexcept
+ {
+ return &(m_v[m_row[row]]);
+ }
+
+#if 0
+ T & operator()(size_type r, size_type c) noexcept
+ {
+ return (*this)[r][c];
+ }
+#else
+ void set(size_type r, size_type c, const T &v) noexcept
+ {
+ if (c + m_row[r] >= m_row[r + 1])
+ {
+ m_v.insert(m_v.begin() + m_row[r+1], v);
+ for (size_type i = r + 1; i <= m_N; i++)
+ m_row[i] = m_row[i] + 1;
+ }
+ else
+ (*this)[r][c] = v;
+ }
+#endif
+ //FIXME: no check!
+ const T & operator()(size_type r, size_type c) const noexcept
+ {
+ return (*this)[r][c];
+ }
+
+ T * data() noexcept
+ {
+ return m_v.data();
+ }
+
+ const T * data() const noexcept
+ {
+ return m_v.data();
+ }
+
+ //FIXME: no check!
+ size_type didx(size_type r, size_type c) const noexcept
+ {
+ return m_row[r] + c;
+ }
+
+ std::size_t tx() const { return m_v.size(); }
+ private:
+
+ size_type m_N;
+ size_type m_M;
+ std::vector<size_type, A> m_row;
+ std::vector<T, A> m_v;
+ };
+
+
} // namespace plib
#endif // PMATRIX2D_H_