void test_tuple_initialization () { std::cout << "testing tuple-based initialization\n"; typedef BasedVectorSpace_c<VectorSpace_c<RealField,12,IdX>,Basis_c<IdX>> BVS; typedef ImplementationOf_t<BVS,float,UseMemberArray_t<ComponentsAreConst::FALSE>> U; float array[12]; typedef ImplementationOf_t<BVS,float,UsePreallocatedArray_t<ComponentsAreConst::FALSE>> V; U u(tuple(1.0f, 2.0f, 3.0f, 4.0f) | tuple(5.0f, 6.0f, 7.0f, 8.0f) | tuple(9.0f, 10.0f, 11.0f, 12.0f)); V v(tuple(1.0f, 2.0f, 3.0f, 4.0f) | tuple(5.0f, 6.0f, 7.0f, 8.0f) | tuple(9.0f, 10.0f, 11.0f, 12.0f), &array[0]); std::cout << FORMAT_VALUE(u) << '\n'; std::cout << FORMAT_VALUE(v) << '\n'; std::cout << '\n'; }
PythonObject callFunctionWithArgs( PythonObject function, const std::vector<PythonObject>& args, const std::vector<std::pair<std::string, PythonObject>>& kwargs) { if (!PyCallable_Check(function.get())) { throw WrappyError("Wrappy: Supplied object isn't callable."); } // Build tuple size_t sz = args.size(); PythonObject tuple(PythonObject::owning {}, PyTuple_New(sz)); if (!tuple) { PyErr_Print(); throw WrappyError("Wrappy: Couldn't create python typle."); } for (size_t i = 0; i < sz; ++i) { PyObject* arg = args.at(i).get(); Py_XINCREF(arg); // PyTuple_SetItem steals a reference PyTuple_SetItem(tuple.get(), i, arg); } // Build kwargs dict PythonObject dict(PythonObject::owning {}, PyDict_New()); if (!dict) { PyErr_Print(); throw WrappyError("Wrappy: Couldn't create python dictionary."); } for (const auto& kv : kwargs) { PyDict_SetItemString(dict.get(), kv.first.c_str(), kv.second.get()); } PythonObject res(PythonObject::owning{}, PyObject_Call(function.get(), tuple.get(), dict.get())); if (!res) { PyErr_Print(); throw WrappyError("Wrappy: Error calling function"); } return res; }
/** * @brief Create projected tuples based on one or two input. * Newly-created physical tiles are needed. * * @return true on success, false otherwise. */ bool ProjectionExecutor::DExecute() { PL_ASSERT(project_info_); PL_ASSERT(schema_); PL_ASSERT(children_.size() == 1); // NOTE: We only handle 1 child for now if (children_.size() == 1) { LOG_TRACE("Projection : child 1 "); // Execute child auto status = children_[0]->Execute(); if (false == status) return false; // Get input from child std::unique_ptr<LogicalTile> source_tile(children_[0]->GetOutput()); auto num_tuples = source_tile->GetTupleCount(); // Create new physical tile where we store projected tuples std::shared_ptr<storage::Tile> dest_tile( storage::TileFactory::GetTempTile(*schema_, num_tuples)); // Create projections tuple-at-a-time from original tile oid_t new_tuple_id = 0; for (oid_t old_tuple_id : *source_tile) { storage::Tuple *buffer = new storage::Tuple(schema_, true); expression::ContainerTuple<LogicalTile> tuple(source_tile.get(), old_tuple_id); project_info_->Evaluate(buffer, &tuple, nullptr, executor_context_); // Insert projected tuple into the new tile dest_tile.get()->InsertTuple(new_tuple_id, buffer); delete buffer; new_tuple_id++; } // Wrap physical tile in logical tile and return it SetOutput(LogicalTileFactory::WrapTiles({dest_tile})); return true; } return false; }
bool DatabaseMetricsCatalog::InsertDatabaseMetrics( oid_t database_oid, oid_t txn_committed, oid_t txn_aborted, oid_t time_stamp, type::AbstractPool *pool, concurrency::TransactionContext *txn) { std::unique_ptr<storage::Tuple> tuple( new storage::Tuple(catalog_table_->GetSchema(), true)); auto val0 = type::ValueFactory::GetIntegerValue(database_oid); auto val1 = type::ValueFactory::GetIntegerValue(txn_committed); auto val2 = type::ValueFactory::GetIntegerValue(txn_aborted); auto val3 = type::ValueFactory::GetIntegerValue(time_stamp); tuple->SetValue(ColumnId::DATABASE_OID, val0, pool); tuple->SetValue(ColumnId::TXN_COMMITTED, val1, pool); tuple->SetValue(ColumnId::TXN_ABORTED, val2, pool); tuple->SetValue(ColumnId::TIME_STAMP, val3, pool); // Insert the tuple into catalog table return InsertTuple(std::move(tuple), txn); }
void Array::unshift(STATE, Object* val) { native_int new_size = total_->to_native() + 1; native_int lend = start_->to_native(); if(lend > 0) { tuple_->put(state, lend-1, val); start(state, Fixnum::from(lend-1)); total(state, Fixnum::from(new_size)); } else { Tuple* nt = Tuple::create(state, new_size); nt->copy_from(state, tuple_, start_, total_, Fixnum::from(1)); nt->put(state, 0, val); total(state, Fixnum::from(new_size)); start(state, Fixnum::from(0)); tuple(state, nt); } }
std::string Table::debug(const std::string &spacer) const { VOLT_DEBUG("tabledebug start"); std::ostringstream buffer; std::string infoSpacer = spacer + " |"; buffer << infoSpacer << tableType() << "(" << name() << "):\n"; buffer << infoSpacer << "\tAllocated Tuples: " << allocatedTupleCount() << "\n"; buffer << infoSpacer << "\tNumber of Columns: " << columnCount() << "\n"; // // Columns // buffer << infoSpacer << "===========================================================\n"; buffer << infoSpacer << "\tCOLUMNS\n"; buffer << infoSpacer << m_schema->debug(); //buffer << infoSpacer << " - TupleSchema needs a \"debug\" method. Add one for output here.\n"; // // Tuples // if (tableType().compare("LargeTempTable") != 0) { buffer << infoSpacer << "===========================================================\n"; buffer << infoSpacer << "\tDATA\n"; TableIterator iter = const_cast<Table*>(this)->iterator(); TableTuple tuple(m_schema); if (this->activeTupleCount() == 0) { buffer << infoSpacer << "\t<NONE>\n"; } else { std::string lastTuple = ""; while (iter.next(tuple)) { if (tuple.isActive()) { buffer << infoSpacer << "\t" << tuple.debug(this->name().c_str()) << "\n"; } } } buffer << infoSpacer << "===========================================================\n"; } std::string ret(buffer.str()); VOLT_DEBUG("tabledebug end"); return ret; }
void var::print(wostream& o) const { switch (primary()) { case Primary::Null: o << _W("Null"); return; case Primary::Symbol: symbol()->print(o); return; case Primary::Key: key().print(o); return; case Primary::Object: object().print(o); return; case Primary::Tuple: tuple().print(o); return; } }
static bool picture_is_cached (url file_name, int w, int h) { tree key= tuple (file_name->t, as_string (w), as_string (h)); if (!picture_cache->contains (key)) return false; int loaded= last_modified (file_name, false); int cached= picture_stamp [key]; if (cached >= loaded) return true; else { int ow,oh,nw,nh; image_size (file_name, ow, oh); clear_imgbox_cache (key[0]); image_size (file_name, nw, nh); // the new size will be displayed correctly only // after the typesetter's image box is invalidated. // if (nw!=ow || nh!=oh) call("update-current-buffer"); return false; } }
void LoadTable() { const oid_t col_count = state.attribute_count + 1; const int tuple_count = state.scale_factor * state.tuples_per_tilegroup; auto table_schema = sdbench_table->GetSchema(); ///////////////////////////////////////////////////////// // Load in the data ///////////////////////////////////////////////////////// // Insert tuples into tile_group. auto &txn_manager = concurrency::TransactionManagerFactory::GetInstance(); const bool allocate = true; auto txn = txn_manager.BeginTransaction(); std::unique_ptr<type::AbstractPool> pool(new type::EphemeralPool()); std::unique_ptr<executor::ExecutorContext> context( new executor::ExecutorContext(txn)); for (int rowid = 0; rowid < tuple_count; rowid++) { int populate_value = rowid; std::unique_ptr<storage::Tuple> tuple(new storage::Tuple(table_schema, allocate)); for (oid_t col_itr = 0; col_itr < col_count; col_itr++) { auto value = type::ValueFactory::GetIntegerValue(populate_value); tuple->SetValue(col_itr, value, pool.get()); } planner::InsertPlan node(sdbench_table.get(), std::move(tuple)); executor::InsertExecutor executor(&node, context.get()); executor.Execute(); } auto result = txn_manager.CommitTransaction(txn); if (result == ResultType::SUCCESS) { LOG_TRACE("commit successfully"); } else { LOG_TRACE("commit failed"); } }
VstigTuple KernelHandle::getVirtualStigmergyTuple(unsigned int id, std::string key_std) { std::string robot_id_string=boost::lexical_cast<std::string>(KernelInitializer::unique_robot_id_); std::string shm_object_name="KernelData"+robot_id_string; boost::interprocess::managed_shared_memory segment(boost::interprocess::open_or_create ,shm_object_name.data(), 102400); VoidAllocator alloc_inst (segment.get_segment_manager()); micros_swarm_framework::shm_string key(key_std.data(), alloc_inst); std::pair<shm_virtual_stigmergy_type*, std::size_t> virtual_stigmergy = segment.find<shm_virtual_stigmergy_type>("shm_virtual_stigmergy_"); if(virtual_stigmergy.first==0) { } shm_virtual_stigmergy_type *vst_pointer=virtual_stigmergy.first; shm_virtual_stigmergy_type::iterator vst_it; vst_it=vst_pointer->find(id); if(vst_it!=vst_pointer->end()) { shm_virtual_stigmergy_tuple_type::iterator svstt_it=vst_it->second.find(key); if(svstt_it!=vst_it->second.end()) { shm_string value_shm=svstt_it->second.getVirtualStigmergyValue(); std::string value(value_shm.data(), value_shm.size()); time_t time_now=svstt_it->second.getVirtualStigmergyTimestamp(); unsigned int robot_id=svstt_it->second.getRobotID(); VstigTuple new_tuple(value, time_now, robot_id); return new_tuple; } } std::string value=""; time_t time_now=0; unsigned int robot_id=0; VstigTuple tuple(value, time_now, robot_id); return tuple; }
TEST_F(TupleTests, VarcharTest) { std::vector<catalog::Column> columns; catalog::Column column1(VALUE_TYPE_INTEGER, GetTypeSize(VALUE_TYPE_INTEGER), "A", true); catalog::Column column2(VALUE_TYPE_INTEGER, GetTypeSize(VALUE_TYPE_INTEGER), "B", true); catalog::Column column3(VALUE_TYPE_TINYINT, GetTypeSize(VALUE_TYPE_TINYINT), "C", true); catalog::Column column4(VALUE_TYPE_VARCHAR, 25, "D", false); columns.push_back(column1); columns.push_back(column2); columns.push_back(column3); columns.push_back(column4); catalog::Schema *schema(new catalog::Schema(columns)); storage::Tuple *tuple(new storage::Tuple(schema, true)); auto pool = TestingHarness::GetInstance().GetTestingPool(); tuple->SetValue(0, ValueFactory::GetIntegerValue(23), pool); tuple->SetValue(1, ValueFactory::GetIntegerValue(45), pool); tuple->SetValue(2, ValueFactory::GetTinyIntValue(1), pool); Value val = ValueFactory::GetStringValue("hello hello world", pool); tuple->SetValue(3, val, pool); EXPECT_EQ(tuple->GetValue(3), val); LOG_INFO("%s", tuple->GetInfo().c_str()); Value val2 = ValueFactory::GetStringValue("hi joy !", pool); tuple->SetValue(3, val2, pool); EXPECT_NE(tuple->GetValue(3), val); EXPECT_EQ(tuple->GetValue(3), val2); LOG_INFO("%s", tuple->GetInfo().c_str()); delete tuple; delete schema; }
long var::compare(const var& x) const { long r = primary() - x.primary(); if (r) return r; switch (primary()) { case Primary::Symbol: return symbol()->compare(x.symbol()); case Primary::Key: return key().compare(x.key()); case Primary::Object: { long r = object().type->compare(x.object().type); if (r) return r; } return object().compare(x.object()); case Primary::Tuple: return tuple().compare(x.tuple()); } return 0; }
// ============================================================================ // retrieve (book on demand) matrix-items for ntuple (fixed) // ============================================================================ Tuples::TupleObj::FMatrix* Tuples::TupleObj::fMatrix ( const std::string& name , const Tuples::TupleObj::MIndex& rows , const Tuples::TupleObj::MIndex& cols ) { // existing array ? FMatrices::iterator found = m_matricesf.find( name ) ; if( m_matricesf.end() != found ) { return found->second ; } // create new array FMatrix* matrix = new FMatrix () ; m_matricesf[ name] = matrix ; const StatusCode sc = tuple() -> addItem( name , rows , cols , *matrix ) ; if( sc.isFailure() ) { Error ( "matrix ('" + name + "'): item is not added", sc ) ; } if ( !addItem ( name , "FMatrix" ) ) { Error ( "matrix ('" + name + "'): item is not unique" ) ; } return matrix ; }
bool TransactionTestsUtil::ExecuteInsert(concurrency::Transaction *transaction, storage::DataTable *table, int id, int value) { std::unique_ptr<executor::ExecutorContext> context( new executor::ExecutorContext(transaction)); // Make tuple std::unique_ptr<storage::Tuple> tuple( new storage::Tuple(table->GetSchema(), true)); auto testing_pool = TestingHarness::GetInstance().GetTestingPool(); tuple->SetValue(0, ValueFactory::GetIntegerValue(id), testing_pool); tuple->SetValue(1, ValueFactory::GetIntegerValue(value), testing_pool); std::unique_ptr<const planner::ProjectInfo> project_info{ MakeProjectInfoFromTuple(tuple.get())}; // Insert planner::InsertPlan node(table, std::move(project_info)); executor::InsertExecutor executor(&node, context.get()); return executor.Execute(); }
storage::Tuple StatsTestsUtil::PopulateTuple(const catalog::Schema *schema, int first_col_val, int second_col_val, int third_col_val, int fourth_col_val) { auto testing_pool = TestingHarness::GetInstance().GetTestingPool(); storage::Tuple tuple(schema, true); tuple.SetValue(0, common::ValueFactory::GetIntegerValue(first_col_val), testing_pool); tuple.SetValue(1, common::ValueFactory::GetIntegerValue(second_col_val), testing_pool); tuple.SetValue(2, common::ValueFactory::GetDoubleValue(third_col_val), testing_pool); common::Value string_value = common::ValueFactory::GetVarcharValue(std::to_string(fourth_col_val)); tuple.SetValue(3, string_value, testing_pool); return tuple; }
/* * Recalculate how many tuples are remaining and compare to the countdown value. * This method does not work once we're in the middle of the temp table. * Only call it while m_finishedTableScan==false. */ void CopyOnWriteContext::checkRemainingTuples(const std::string &label) { assert(m_iterator != NULL); assert(!m_finishedTableScan); intmax_t count1 = static_cast<CopyOnWriteIterator*>(m_iterator.get())->countRemaining(); TableTuple tuple(getTable().schema()); boost::scoped_ptr<TupleIterator> iter(m_backedUpTuples.get()->makeIterator()); intmax_t count2 = 0; while (iter->next(tuple)) { count2++; } if (m_tuplesRemaining != count1 + count2) { VOLT_ERROR("CopyOnWriteContext::%s remaining tuple count mismatch: " "table=%s partcol=%d count=%jd count1=%jd count2=%jd " "expected=%jd compacted=%jd batch=%jd " "inserts=%jd updates=%jd", label.c_str(), getTable().name().c_str(), getTable().partitionColumn(), count1 + count2, count1, count2, (intmax_t)m_tuplesRemaining, (intmax_t)m_blocksCompacted, (intmax_t)m_serializationBatches, (intmax_t)m_inserts, (intmax_t)m_updates); } }
void LoadYCSBDatabase() { const oid_t col_count = state.column_count + 1; const int tuple_count = state.scale_factor * 1000; // Pick the user table auto table_schema = user_table->GetSchema(); // std::string field_raw_value(ycsb_field_length - 1, 'o'); int field_raw_value = 1; ///////////////////////////////////////////////////////// // Load in the data ///////////////////////////////////////////////////////// // Insert tuples into tile_group. auto &txn_manager = concurrency::TransactionManagerFactory::GetInstance(); const bool allocate = true; auto txn = txn_manager.BeginTransaction(); // std::unique_ptr<VarlenPool> pool(new VarlenPool(BACKEND_TYPE_MM)); std::unique_ptr<executor::ExecutorContext> context( new executor::ExecutorContext(txn)); int rowid; for (rowid = 0; rowid < tuple_count; rowid++) { std::unique_ptr<storage::Tuple> tuple( new storage::Tuple(table_schema, allocate)); auto key_value = ValueFactory::GetIntegerValue(rowid); auto field_value = ValueFactory::GetIntegerValue(field_raw_value); tuple->SetValue(0, key_value, nullptr); for (oid_t col_itr = 1; col_itr < col_count; col_itr++) { tuple->SetValue(col_itr, field_value, nullptr); } planner::InsertPlan node(user_table, std::move(tuple)); executor::InsertExecutor executor(&node, context.get()); executor.Execute(); } txn_manager.CommitTransaction(); }
bool Tile::SerializeTo(SerializeOutput &output, oid_t num_tuples) { /** * The table is serialized as: * * [(int) total size] * [(int) header size] [num columns] [column types] [column names] * [(int) num tuples] [tuple data] * */ // A placeholder for the total table size written at the end std::size_t pos = output.Position(); output.WriteInt(-1); // Serialize the header if (!SerializeHeaderTo(output)) return false; // Active tuple count output.WriteInt(static_cast<int>(num_tuples)); oid_t written_count = 0; TupleIterator tile_itr(this); Tuple tuple(&schema); while (tile_itr.Next(tuple) && written_count < num_tuples) { tuple.SerializeTo(output); ++written_count; } tuple.SetNull(); PL_ASSERT(written_count == num_tuples); // Length prefix is non-inclusive int32_t sz = static_cast<int32_t>(output.Position() - pos - sizeof(int32_t)); PL_ASSERT(sz > 0); output.WriteIntAt(pos, sz); return true; }
bool IndexCatalog::InsertIndex(concurrency::TransactionContext *txn, const std::string &schema_name, oid_t table_oid, oid_t index_oid, const std::string &index_name, IndexType index_type, IndexConstraintType index_constraint, bool unique_keys, std::vector<oid_t> index_keys, type::AbstractPool *pool) { // Create the tuple first std::unique_ptr<storage::Tuple> tuple( new storage::Tuple(catalog_table_->GetSchema(), true)); auto val0 = type::ValueFactory::GetIntegerValue(index_oid); auto val1 = type::ValueFactory::GetVarcharValue(index_name, nullptr); auto val2 = type::ValueFactory::GetIntegerValue(table_oid); auto val3 = type::ValueFactory::GetVarcharValue(schema_name, nullptr); auto val4 = type::ValueFactory::GetIntegerValue(static_cast<int>(index_type)); auto val5 = type::ValueFactory::GetIntegerValue(static_cast<int>(index_constraint)); auto val6 = type::ValueFactory::GetBooleanValue(unique_keys); std::stringstream os; for (oid_t indkey : index_keys) os << std::to_string(indkey) << " "; auto val7 = type::ValueFactory::GetVarcharValue(os.str(), nullptr); tuple->SetValue(IndexCatalog::ColumnId::INDEX_OID, val0, pool); tuple->SetValue(IndexCatalog::ColumnId::INDEX_NAME, val1, pool); tuple->SetValue(IndexCatalog::ColumnId::TABLE_OID, val2, pool); tuple->SetValue(IndexCatalog::ColumnId::SCHEMA_NAME, val3, pool); tuple->SetValue(IndexCatalog::ColumnId::INDEX_TYPE, val4, pool); tuple->SetValue(IndexCatalog::ColumnId::INDEX_CONSTRAINT, val5, pool); tuple->SetValue(IndexCatalog::ColumnId::UNIQUE_KEYS, val6, pool); tuple->SetValue(IndexCatalog::ColumnId::INDEXED_ATTRIBUTES, val7, pool); // Insert the tuple return InsertTuple(txn, std::move(tuple)); }
void identify_rise(struct cpudata *cpu) { rise_nameptr = cpu->name; switch (tuple(cpu) & 0xff0) { case 0x500: add_to_cpuname("iDragon (0.25um)"); break; case 0x520: add_to_cpuname("iDragon (0.18um)"); break; case 0x580: add_to_cpuname("iDragon II (0.25um)"); break; case 0x590: add_to_cpuname("iDragon II (0.18um)"); break; default: add_to_cpuname("Unknown CPU"); break; } }
void edit_select_rep::selection_set (string key, tree t, bool persistant) { selecting= shift_selecting= false; string mode= as_string (selection_get_env_value (MODE)); string lan = as_string (selection_get_env_value (MODE_LANGUAGE (mode))); tree sel= tuple ("texmacs", t, mode, lan); /* TODO: add mode="graphics" somewhere in the context of the <graphics> tag. To be done when implementing the different embeddings for nicely copying graphics into text, text into graphics, etc. */ string s; if (key == "primary" || key == "mouse") { if (selection_export == "verbatim") t= exec_verbatim (t, tp); if (selection_export == "html") t= exec_html (t, tp); if (selection_export == "latex") t= exec_latex (t, tp); if ((selection_export == "latex") && (mode == "math")) t= compound ("math", t); s= tree_to_generic (t, selection_export * "-snippet"); s= selection_encode (lan, s); } if (::set_selection (key, sel, s, selection_export) && !persistant) selection_cancel (); }
Array* Array::concat(STATE, Array* other) { size_t osize = other->size(); if(osize == 0) return this; if(is_frozen_p()) return force_as<Array>(Primitives::failure()); if(osize == 1) { set(state, size(), other->get(state, 0)); return this; } size_t new_size = size() + osize; Tuple* nt = Tuple::create(state, new_size); nt->copy_from(state, tuple_, start_, total_, Fixnum::from(0)); nt->copy_from(state, other->tuple(), other->start(), other->total(), total_); tuple(state, nt); start(state, Fixnum::from(0)); total(state, Fixnum::from(new_size)); return this; }
// INSERT HELPER FUNCTION void InsertTest(size_t scale_factor, catalog::Schema *schema, uint64_t thread_itr) { uint32_t base = thread_itr * base_scale * max_scale_factor; uint32_t tuple_count = scale_factor * base_scale; for (uint32_t tuple_itr = 1; tuple_itr <= tuple_count; tuple_itr++) { uint32_t tuple_offset = base + tuple_itr; storage::Tuple *tuple(new storage::Tuple(schema, true)); tuple->SetValue(0, ValueFactory::GetIntegerValue(tuple_offset), nullptr); key_type key; key.SetFromKey(tuple); value_type val = &foo; auto status = test_skip_list_map.Insert(key, val); EXPECT_TRUE(status); delete tuple; } }
edit_env_rep::edit_env_rep (drd_info& drd2, url base_file_name2, hashmap<string,tree>& local_ref2, hashmap<string,tree>& global_ref2, hashmap<string,tree>& local_aux2, hashmap<string,tree>& global_aux2): drd (drd2), env (UNINIT), back (UNINIT), src (path (DECORATION)), var_type (default_var_type), base_file_name (base_file_name2), cur_file_name (base_file_name2), secure (is_secure (base_file_name2)), local_ref (local_ref2), global_ref (global_ref2), local_aux (local_aux2), global_aux (global_aux2) { initialize_default_env (); initialize_default_var_type (); env= copy (default_env); style_init_env (); update (); complete= false; recover_env= tuple (); }
bool UnionSetOperator::processTuples() { // Set to keep candidate tuples. TupleSet tuples; // // For each input table, grab their TableIterator and then append all of its tuples // to our ouput table. Only distinct tuples are retained. // for (size_t ctr = 0, cnt = m_input_tablerefs.size(); ctr < cnt; ctr++) { Table* input_table = m_input_tablerefs[ctr].getTable(); assert(input_table); TableIterator iterator = input_table->iterator(); TableTuple tuple(input_table->schema()); while (iterator.next(tuple)) { if (m_is_all || needToInsert(tuple, tuples)) { // we got tuple to insert m_output_table->insertTempTuple(tuple); } } } return true; }
void read_wkt(std::string const& filename, std::vector<Tuple>& tuples, Box& box) { std::ifstream cpp_file(filename.c_str()); if (cpp_file.is_open()) { while (! cpp_file.eof() ) { std::string line; std::getline(cpp_file, line); Geometry geometry; boost::trim(line); if (! line.empty() && ! boost::starts_with(line, "#")) { std::string name; // Split at ';', if any std::string::size_type pos = line.find(";"); if (pos != std::string::npos) { name = line.substr(pos + 1); line.erase(pos); boost::trim(line); boost::trim(name); } Geometry geometry; boost::geometry::read_wkt(line, geometry); Tuple tuple(geometry, name); tuples.push_back(tuple); boost::geometry::combine(box, boost::geometry::make_envelope<Box>(geometry)); } } } }
void merge_vectors( const std::vector<std::vector<int>>& in, std::vector<int>* out) { typedef std::vector<int> Array; typedef Array::const_iterator Iterator; typedef std::tuple<Iterator, Iterator> Element; std::vector<Element> heap; for (int index = 0; index < in.size(); ++index) { if (!in[index].empty()) { Element tuple(in[index].begin(), in[index].end()); heap.push_back(tuple); } } auto comparator = [] (const Element& lhs, const Element& rhs) { return *std::get<0>(lhs) < *std::get<0>(rhs); }; std::make_heap(heap.begin(), heap.end(), comparator); while (!heap.empty()) { auto tuple = heap.front(); std::pop_heap( heap.begin(), heap.end(), comparator); out->push_back(*std::get<0>(tuple)); if (std::get<1>(tuple) != ++std::get<0>(tuple)) { heap.push_back(tuple); std::push_heap( heap.begin(), heap.end(), comparator); } } }
void HyperMatrix<T>::print_2D (const std::vector<int> & dimension, ostream& out) const // Library facilities used: assert { int ways = static_cast<int>(dimensions.size()); assert(int(dimension.size()) == ways); // get row and column ways vector<int> plane; for(int way = 0; way != ways; ++way) if(dimension[way] == -1) plane.push_back(way); assert(int(plane.size()) == 2); const int ROW = plane[0]; const int COL = plane[1]; assert(ROW < COL); // set indexer tuple vector<int> tuple(ways); for(int way = 0; way != ways; ++way) if(dimension[way] == -1) tuple[way] = 0; // build hyper-cube indexer std::vector<bool> mask(ways, true); mask[ROW] = mask[COL] = false; Indexer indexer(*this, tuple, mask); // print int ccount = 0; while(!indexer.end()) { out << operator[](indexer.index()); if(++ccount % dimensions[COL] == 0) out << " " << endl; indexer.forward(); } }
// Compute the dependencies of a given event. Returns a list of (thread,kind,event) triples. vector<Tuple<int,int,history_t>> event_dependencies(const vector<vector<Array<const history_t>>>& event_sorted_history, const int direction, const int thread, const int kind, const history_t source) { vector<Tuple<int,int,history_t>> deps; for (const auto kind_event : dependencies(direction,time_kind_t(kind),source.event)) { const int dep_kind = kind_event.x; const event_t dep_event = kind_event.y; // Search for event in each thread bool found = false; for (const int t : range((int)event_sorted_history.size())) { const auto& sorted_events = event_sorted_history.at(t).at(dep_kind); for (const int i : range(find_event(sorted_events,dep_event),sorted_events.size())) { const history_t& event = sorted_events[i]; if (event.event != dep_event) break; GEODE_ASSERT(!found || dep_kind==compute_kind); found = true; deps.push_back(tuple(t,dep_kind,event)); } } if (!found) { int count = 0; for (const int t : range((int)event_sorted_history.size())) { const auto& events = event_sorted_history[t].at(dep_kind); for (const int i : range(max(0,events.size()-1))) if (events[i].event > events[i+1].event) THROW(RuntimeError,"event_dependencies: order failure: thread %d, kind %d, i %d (%d), events %lld %lld",t,dep_kind,i,events.size(),events[i].event,events[i+1].event); for (auto& e : events) if (e.event==dep_event) count++; } THROW(RuntimeError,"event_dependencies: dependency not found, direction = %d, count %d, source = %d %s %s, dependency = %s %s", direction,count, thread,time_kind_names().at(kind),str_event(source.event), time_kind_names().at(dep_kind),str_event(dep_event)); } } return deps; }
bool Table::serializeTo(SerializeOutput &serialize_io) { // The table is serialized as: // [(int) total size] // [(int) header size] [num columns] [column types] [column names] // [(int) num tuples] [tuple data] /* NOTE: VoltDBEngine uses a binary template to create tables of single integers. It's called m_templateSingleLongTable and if you are seeing a serialization bug in tables of single integers, make sure that's correct. */ // a placeholder for the total table size std::size_t pos = serialize_io.position(); serialize_io.writeInt(-1); if (!serializeColumnHeaderTo(serialize_io)) return false; // active tuple counts serialize_io.writeInt(static_cast<int32_t>(m_tupleCount)); int64_t written_count = 0; TableIterator titer = iterator(); TableTuple tuple(m_schema); while (titer.next(tuple)) { tuple.serializeTo(serialize_io); ++written_count; } assert(written_count == m_tupleCount); // length prefix is non-inclusive int32_t sz = static_cast<int32_t>(serialize_io.position() - pos - sizeof(int32_t)); assert(sz > 0); serialize_io.writeIntAt(pos, sz); return true; }