summaryrefslogtreecommitdiffstats
path: root/src/lib/netlist/plib/pmatrix2d.h
diff options
context:
space:
mode:
author Roberto Fresca <robbie@robertofresca.com>2020-06-13 15:58:27 +0200
committer Roberto Fresca <robbie@robertofresca.com>2020-06-13 15:58:27 +0200
commit284f196df1c65a91eb38a5a9f31a2da7fb86a1ac (patch)
treed29473e4024dce305d0ee3bb957a663420417312 /src/lib/netlist/plib/pmatrix2d.h
parent52b8d5fd2b656c317e589da93467c33be74e76ea (diff)
parente949e9c29de82ee7c32692e7b65da05dd22bdc9d (diff)
Merge branch 'master' of https://github.com/mamedev/mame
Diffstat (limited to 'src/lib/netlist/plib/pmatrix2d.h')
-rwxr-xr-x[-rw-r--r--]src/lib/netlist/plib/pmatrix2d.h160
1 files changed, 147 insertions, 13 deletions
diff --git a/src/lib/netlist/plib/pmatrix2d.h b/src/lib/netlist/plib/pmatrix2d.h
index b48c531a921..b9a2ebee116 100644..100755
--- a/src/lib/netlist/plib/pmatrix2d.h
+++ b/src/lib/netlist/plib/pmatrix2d.h
@@ -17,51 +17,182 @@
namespace plib
{
- template<typename T, typename A = aligned_allocator<T>>
+ template<typename T, typename A = aligned_arena>
class pmatrix2d
{
public:
using size_type = std::size_t;
+ using arena_type = A;
+ using allocator_type = typename A::template allocator_type<T>;
+
+ static constexpr const size_type align_size = align_traits<allocator_type>::align_size;
+ static constexpr const size_type stride_size = align_traits<allocator_type>::stride_size;
+
using value_type = T;
- using allocator_type = A;
+ using reference = T &;
+ using const_reference = const T &;
+
+ using pointer = T *;
+ using const_pointer = const T *;
- 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() noexcept
- : m_N(0), m_M(0), m_stride(8), m_v()
+ : m_N(0), m_M(0), m_stride(8), m_v(nullptr)
{
}
pmatrix2d(size_type N, size_type M)
: m_N(N), m_M(M), m_v()
{
+ gsl_Expects(N>0);
+ gsl_Expects(M>0);
m_stride = ((M + stride_size-1) / stride_size) * stride_size;
- m_v.resize(N * m_stride);
+ m_v = m_a.allocate(N * m_stride);
+ for (std::size_t i = 0; i < N * m_stride; i++)
+ ::new(&m_v[i]) T();
+ }
+
+ ~pmatrix2d()
+ {
+ if (m_v != nullptr)
+ {
+ for (std::size_t i = 0; i < m_N * m_stride; i++)
+ (&m_v[i])->~T();
+ m_a.deallocate(m_v, m_N * m_stride);
+ }
}
void resize(size_type N, size_type M)
{
+ gsl_Expects(N>0);
+ gsl_Expects(M>0);
+ if (m_v != nullptr)
+ {
+ for (std::size_t i = 0; i < N * m_stride; i++)
+ (&m_v[i])->~T();
+ m_a.deallocate(m_v, N * m_stride);
+ }
m_N = N;
m_M = M;
m_stride = ((M + stride_size-1) / stride_size) * stride_size;
- m_v.resize(N * m_stride);
+ m_v = m_a.allocate(N * m_stride);
+ for (std::size_t i = 0; i < N * m_stride; i++)
+ ::new(&m_v[i]) T();
+ }
+
+ constexpr pointer operator[] (size_type row) noexcept
+ {
+ return &m_v[m_stride * row];
+ }
+
+ constexpr const_pointer operator[] (size_type row) const noexcept
+ {
+ return &m_v[m_stride * row];
+ }
+
+ reference operator()(size_type r, size_type c) noexcept
+ {
+ return (*this)[r][c];
+ }
+
+ const_reference operator()(size_type r, size_type c) const noexcept
+ {
+ return (*this)[r][c];
+ }
+
+ // for compatibility with vrl variant
+ void set(size_type r, size_type c, const value_type &v) noexcept
+ {
+ (*this)[r][c] = v;
+ }
+
+ pointer data() noexcept
+ {
+ return m_v;
+ }
+
+ const_pointer data() const noexcept
+ {
+ return m_v;
+ }
+
+ size_type didx(size_type r, size_type c) const noexcept
+ {
+ return m_stride * r + c;
+ }
+ private:
+
+ size_type m_N;
+ size_type m_M;
+ size_type m_stride;
+
+ T * __restrict m_v;
+
+ allocator_type m_a;
+ };
+
+ // variable row length matrix
+ template<typename T, typename A = aligned_arena>
+ class pmatrix2d_vrl
+ {
+ public:
+ using size_type = std::size_t;
+ using value_type = T;
+ using arena_type = A;
+ using allocator_type = typename A::template allocator_type<T>;
+
+ static constexpr const size_type align_size = align_traits<allocator_type>::align_size;
+ static constexpr const size_type stride_size = align_traits<allocator_type>::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 assume_aligned_ptr<T, align_size>(&m_v[m_stride * row]);
+ return &(m_v[m_row[row]]);
}
constexpr const T * operator[] (size_type row) const noexcept
{
- return assume_aligned_ptr<T, align_size>(&m_v[m_stride * row]);
+ return &(m_v[m_row[row]]);
}
+ //FIXME: no check!
T & operator()(size_type r, size_type c) noexcept
{
return (*this)[r][c];
}
+ 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() + narrow_cast<std::ptrdiff_t>(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;
+ }
+
+ //FIXME: no check!
const T & operator()(size_type r, size_type c) const noexcept
{
return (*this)[r][c];
@@ -77,19 +208,22 @@ namespace plib
return m_v.data();
}
+ //FIXME: no check!
size_type didx(size_type r, size_type c) const noexcept
{
- return m_stride * r + c;
+ return m_row[r] + c;
}
+
+ std::size_t tx() const { return m_v.size(); }
private:
size_type m_N;
size_type m_M;
- size_type m_stride;
-
- std::vector<T, A> m_v;
+ std::vector<size_type, typename A::template allocator_type<size_type>> m_row;
+ std::vector<T, allocator_type> m_v;
};
+
} // namespace plib
#endif // PMATRIX2D_H_