13 #include "common/datatypes/List.h"
14 #include "common/datatypes/Value.h"
21 std::vector<std::string> colNames;
22 std::vector<Row> rows;
25 explicit DataSet(std::vector<std::string> columns) : colNames(std::move(columns)) {}
27 colNames = ds.colNames;
31 colNames = std::move(ds.colNames);
32 rows = std::move(ds.rows);
36 colNames = ds.colNames;
43 colNames = std::move(ds.colNames);
44 rows = std::move(ds.rows);
49 const std::vector<std::string>& keys()
const {
53 const std::vector<Value>& rowValues(std::size_t index)
const {
54 return rows[index].values;
57 std::vector<Value> colValues(
const std::string& colName)
const {
58 std::vector<Value> col;
59 const auto find = std::find(colNames.begin(), colNames.end(), colName);
60 if (find == colNames.end()) {
63 std::size_t index = std::distance(colNames.begin(), find);
64 col.reserve(rows.size());
65 for (
const auto& row : rows) {
66 col.emplace_back(row.values[index]);
71 using iterator = std::vector<Row>::iterator;
72 using const_iterator = std::vector<Row>::const_iterator;
78 const_iterator begin()
const {
86 const_iterator end()
const {
91 typename =
typename std::enable_if<std::is_convertible<T, Row>::value, T>::type>
92 bool emplace_back(T&& row) {
93 if (row.size() != colNames.size()) {
96 rows.emplace_back(std::forward<T>(row));
102 if (colNames.empty()) {
103 colNames = std::move(o.colNames);
105 if (colNames != o.colNames) {
109 rows.reserve(rowSize() + o.rowSize());
111 rows.end(), std::make_move_iterator(o.rows.begin()), std::make_move_iterator(o.rows.end()));
117 if (rowSize() != o.rowSize()) {
120 auto newColSize = colSize() + o.colSize();
121 colNames.reserve(newColSize);
122 colNames.insert(colNames.end(),
123 std::make_move_iterator(o.colNames.begin()),
124 std::make_move_iterator(o.colNames.end()));
125 for (std::size_t i = 0; i < rowSize(); ++i) {
126 rows[i].values.reserve(newColSize);
127 rows[i].values.insert(rows[i].values.begin(),
128 std::make_move_iterator(o.rows[i].values.begin()),
129 std::make_move_iterator(o.rows[i].values.end()));
143 std::size_t size()
const {
147 std::size_t rowSize()
const {
151 std::size_t colSize()
const {
152 return colNames.size();
155 std::string toString()
const {
156 std::stringstream os;
158 for (
const auto& h : colNames) {
164 for (
const auto& row : rows) {
165 for (
const auto& col : row.values) {
174 bool operator==(
const DataSet& rhs)
const {
175 return colNames == rhs.colNames && rows == rhs.rows;
179 inline std::ostream& operator<<(std::ostream& os,
const DataSet& d) {
180 return os << d.toString();