std::tuple<aku_Status, size_t> CombineAggregateOperator::read(aku_Timestamp *destts, AggregationResult *destval, size_t size) { if (size == 0) { return std::make_tuple(AKU_EBAD_ARG, 0); } if (iter_index_ == iter_.size()) { return std::make_tuple(AKU_ENO_DATA, 0); } const size_t SZBUF = 1024; aku_Status status = AKU_ENO_DATA; AggregationResult xsresult = INIT_AGGRES; aku_Timestamp tsresult = 0; std::vector<AggregationResult> outval(SZBUF, INIT_AGGRES); std::vector<aku_Timestamp> outts(SZBUF, 0); ssize_t ressz; int nagg = 0; while(iter_index_ < iter_.size()) { std::tie(status, ressz) = iter_[iter_index_]->read(outts.data(), outval.data(), SZBUF); if (ressz != 0) { xsresult = std::accumulate(outval.begin(), outval.begin() + ressz, xsresult, [](AggregationResult lhs, AggregationResult rhs) { lhs.combine(rhs); return lhs; }); tsresult = outts[static_cast<size_t>(ressz)-1]; nagg++; } if (status == AKU_ENO_DATA) { // This leaf node is empty, continue with next. iter_index_++; continue; } if (status != AKU_SUCCESS) { // Failure, stop iteration. return std::make_pair(status, 0); } } size_t result_size = 0; if (nagg != 0) { result_size = 1; destts[0] = tsresult; destval[0] = xsresult; } return std::make_tuple(AKU_SUCCESS, result_size); }
void QGCodeViewer::onOpenGCode(QString filename) { QFile fin(filename); QFile fout(gcodefile); if (fin.open(QFile::ReadOnly | QFile::Text) && ( fout.open( QIODevice::ReadWrite | QIODevice::Truncate | QIODevice::Text) ) ) { QTextStream ints(&fin); QTextStream outts(&fout); while(!ints.atEnd()) outts << ints.readLine() << "\n"; fin.close(); fout.close(); clear(); emit setRS274(rs274); emit setToolTable(tooltable); emit setGcodeFile(openFile = gcodefile); emit interpret(); } }
aku_Status CombineGroupAggregateOperator::refill_read_buffer() { aku_Status status = AKU_ENO_DATA; if (iter_index_ == iter_.size()) { return AKU_ENO_DATA; } u32 pos = 0; if (!rdbuf_.empty()) { auto tail = rdbuf_.back(); // the last element should be saved because it is possible that // it's not full (part of the range contained in first iterator // and another part in second iterator or even in more than one // iterators). rdbuf_.clear(); rdbuf_.resize(RDBUF_SIZE, INIT_AGGRES); rdpos_ = 0; rdbuf_.at(0) = tail; pos = 1; } else { rdbuf_.clear(); rdbuf_.resize(RDBUF_SIZE, INIT_AGGRES); rdpos_ = 0; } while(iter_index_ < iter_.size()) { size_t size = rdbuf_.size() - pos; if (size == 0) { break; } // NOTE: We can't read data from iterator directly to the rdbuf_ because buckets // can be split between two iterators. In this case we should join such // values together. // Invariant: rdbuf_ have enough room to fit outxs in the worst case (the worst // case: `read` returns `size` elements and ranges isn't overlapping and we // don't need to merge last element of `rdbuf_` with first elem of `outxs`). std::vector<AggregationResult> outxs(size, INIT_AGGRES); std::vector<aku_Timestamp> outts(size, 0); u32 outsz; std::tie(status, outsz) = iter_[iter_index_]->read(outts.data(), outxs.data(), outxs.size()); if (outsz != 0) { if (pos > 0) { // Check last and first values of rdbuf_ and outxs auto const& last = rdbuf_.at(pos - 1); auto const& first = outxs.front(); aku_Timestamp lastts = dir_ == Direction::FORWARD ? last._begin - begin_ : begin_ - last._begin; aku_Timestamp firstts = dir_ == Direction::FORWARD ? first._begin - begin_ : begin_ - first._begin; auto lastbin = lastts / step_; auto firstbin = firstts / step_; if (lastbin == firstbin) { pos--; } } } for (size_t ix = 0; ix < outsz; ix++) { rdbuf_.at(pos).combine(outxs.at(ix)); const auto newdelta = rdbuf_.at(pos)._end - rdbuf_.at(pos)._begin; if (newdelta > step_) { assert(newdelta <= step_); } pos++; } if (status == AKU_ENO_DATA) { // This leaf node is empty, continue with next. iter_index_++; continue; } if (status != AKU_SUCCESS) { // Failure, stop iteration. rdbuf_.resize(pos); return status; } } rdbuf_.resize(pos); return AKU_SUCCESS; }