#ifndef ALGOIM_POLYSET_HPP #define ALGOIM_POLYSET_HPP // algoim::PolySet #include #include #include "booluarray.hpp" #include "real.hpp" #include "xarray.hpp" namespace algoim { inline namespace v1 { // PolySet implements a simple container to hold one or more Bernstein polynomials // and their associated masks template struct PolySet { struct Poly { uvector ext; // Degree/extent of polynomial size_t offset; // Offset into buffer, storing the xarray polynomial data booluarray mask; // Mask }; std::vector buff; // Memory buffer containing polynomial data std::vector items; // Record of contained polynomials // Access polynomial by index xarray poly(size_t ind) { assert(0 <= ind && ind < items.size()); return xarray(&buff[items[ind].offset], items[ind].ext); } // Access mask by index booluarray& mask(size_t ind) { assert(0 <= ind && ind < items.size()); return items[ind].mask; } // Add a polynomial/mask pair to the container void push_back(const xarray& p, const booluarray& m) { items.push_back({p.ext(), buff.size(), m}); buff.resize(buff.size() + p.size()); poly(items.size() - 1) = p; // 这里做了一个数据深拷贝,这是为什么xarray在调用push_back后可以被释放 } size_t count() const { return items.size(); } }; } // namespace v1 } // namespace algoim #endif