int main () { summer.read_in(); //function to read in from external file cout << endl << endl; cout << "Welcome to the summer activity searcher! " << endl; cout << "This is the list of possible activities to do: " << endl; summer.display_all(); //function to display all activities cout << "Enter a possible location: "; cin.get(temp,1000,'\n'); cin.ignore(100,'\n'); char * location = new char[strlen(temp+1)]; strcpy(location,temp); summer.retrieve(location); //function to retrieve a certain data's info and will display that info cout << endl; cout << "Would you like to delete a certain location's activities? Y/N. "; cin >> answer; cin.ignore(100,'\n'); if ('Y' == toupper(answer)) { cout << "Please enter the location: "; cin.get(temp,1000,'\n'); cin.ignore(100,'\n'); char * location2 = new char[strlen(temp+1)]; strcpy(location2,temp); summer.remove(location2); //function to remove a certain activity summer.display_all(); //final display } return 0; }
static void require_valid_table(const mesh& Mesh, const string_t& Name, const table& Table) { if(Name == "constant" && Table.column_count() && Table.row_count() != 1) throw std::runtime_error("'constant' table must have length 1."); for(mesh::table_t::const_iterator array_iterator = Table.begin(); array_iterator != Table.end(); ++array_iterator) { const array* const current_array = array_iterator->second.get(); if(!current_array) throw std::runtime_error("NULL table array."); const array* const first_array = Table.begin()->second.get(); if(current_array->size() != first_array->size()) throw std::runtime_error("Array length mismatch for table [" + Name + "]"); if(current_array->get_metadata_value(metadata::key::domain()) == metadata::value::point_indices_domain()) { if(!Mesh.points) throw std::runtime_error("Mesh missing points array."); if(!Mesh.point_selection) throw std::runtime_error("Mesh missing point selections array."); require_valid_points(Mesh); const mesh::indices_t* const indices = dynamic_cast<const mesh::indices_t*>(current_array); if(!indices) throw std::runtime_error("Point indices array must be an index type."); const mesh::indices_t::const_iterator max = std::max_element(indices->begin(), indices->end()); if(max != indices->end() && *max >= Mesh.points->size()) throw std::runtime_error("Point indices array out-of-bounds."); } } }
/** * Adds the gradient of the expected log-likelihood of the specified * data point to the gradient table g. * * \param phead the distribution over a leading set of indices of f * \param tail a fixed assignment to the remaining indices of f * \param w the weight of the data point */ void add_gradient(const table<T>& phead, const uint_vector& tail, T w, table<T>& g) const { assert(phead.arity() + tail.size() == g.arity()); std::size_t index = g.offset().linear(tail, phead.arity()); for (std::size_t i = 0; i < phead.size(); ++i) { g[index + i] += phead[i] * w; } }
// Save the given table in a text file with its number as name, return the name // of this file. std::string do_save_as_text_file(table const& t) { std::ostringstream oss; oss << t.number() << ".txt"; std::string const filename = oss.str(); t.save_as_text(filename); return filename; }
/** * Adds the diagonal of the Hessia of the expected log-likelihoood of * the specified data point to the Hessian diagonal h. */ void add_hessian_diag(const table<T>& phead, const uint_vector& tail, T w, table<T>& h) const { assert(phead.arity() + tail.size() == h.arity()); std::size_t index = h.offset().linear(tail, phead.arity()); for (std::size_t i = 0; i < phead.size(); ++i) { h[index + i] -= phead[i] * w / (f[index + i] * f[index + i]); } }
void insert(table &fTable, char c) { bool inserted = false; for(table::iterator it = fTable.begin(); it != fTable.end(); ++it) { if (it->first == c) { ++(it->second); inserted = true; break; } } if (!inserted) { pair<char, int> ins(c, 1); fTable.push_back(ins); } }
void require_table_row_count(const mesh::primitive& Primitive, const table& Table, const string_t& TableName, const uint_t RowCount) { if(TableName == "constant") throw std::runtime_error("'constant' tables are automatically tested, and must have length 1."); if(0 == Table.column_count()) return; if(Table.row_count() != RowCount) { std::ostringstream buffer; buffer << "[" << Primitive.type << "] table [" << TableName << "] incorrect length [" << Table.row_count() << "], expected [" << RowCount << "]"; throw std::runtime_error(buffer.str()); } }
void clear() { _table.clear(); _columns = _rows = 0; _rules.clear(); _captures.clear(); }
void assign(table const& x, true_type) { if (node_alloc() == x.node_alloc()) { allocators_.assign(x.allocators_); assign(x, false_type()); } else { set_hash_functions new_func_this(*this, x); // Delete everything with current allocators before assigning // the new ones. delete_buckets(); allocators_.assign(x.allocators_); // Copy over other data, all no throw. new_func_this.commit(); mlf_ = x.mlf_; bucket_count_ = min_buckets_for_size(x.size_); max_load_ = 0; // Finally copy the elements. if (x.size_) { static_cast<table_impl*>(this)->copy_buckets(x); } } }
bool contains(const table& tbl, int val) { // return true if tbl contains val int hash_val = hash(val) % tbl.size(); bucket::const_iterator first = tbl[hash_val].begin(); bucket::const_iterator last = tbl[hash_val].end(); return find(first, last, val) != last; }
void draw_loop_text(HDC * dc, table<object_text> table) { object_text pivot = table.getPivot(); FOREACH_TABLE(table, it, object_text) if (it->visible) drawText(dc, pivot.x + it->x, pivot.y + it->y, it->w, it->h, it->size, it->text); }
void move_assign(table& x, false_type) { if (node_alloc() == x.node_alloc()) { delete_buckets(); set_hash_functions new_func_this(*this, x); // No throw from here. mlf_ = x.mlf_; max_load_ = x.max_load_; move_buckets_from(x); new_func_this.commit(); } else { set_hash_functions new_func_this(*this, x); new_func_this.commit(); mlf_ = x.mlf_; recalculate_max_load(); if (!size_ && !x.size_) return; if (x.size_ >= max_load_) { create_buckets(min_buckets_for_size(x.size_)); } else { clear_buckets(); } static_cast<table_impl*>(this)->move_assign_buckets(x); } }
table create_table(T&& key, int narr = 0, int nrec = 0) { lua_createtable(L.get(), narr, nrec); table result(L.get()); lua_pop(L.get(), 1); global.set(std::forward<T>(key), result); return result; }
state& new_userdata(const std::string& name, Args&&... args) { constructors<types<CTor...>> ctor; classes.emplace_back(std::make_shared<userdata<Class>>(name, ctor, std::forward<Args>(args)...)); auto&& ptr = classes.back(); auto udata = std::static_pointer_cast<userdata<Class>>(ptr); global.set_userdata(*udata); return *this; }
void operator++() { ++col_index_; if( col_index_ % val_->col_cnt() == 0 ) { ++row_index_; if( row_index_ == val_->row_cnt() && col_index_ == val_->col_cnt() ) { is_eof_ = true; return; } col_index_ = 0; } }
table(table const& x, node_allocator const& a) : functions(x), allocators_(a,a), bucket_count_(x.min_buckets_for_size(x.size_)), size_(0), mlf_(x.mlf_), max_load_(0), buckets_() {}
void swap_allocators(table& other, false_type) { boost::unordered::detail::func::ignore_unused_variable_warning(other); // According to 23.2.1.8, if propagate_on_container_swap is // false the behaviour is undefined unless the allocators // are equal. BOOST_ASSERT(node_alloc() == other.node_alloc()); }
void show(const table& tbl) { // show contents of buckets in table for (int i = 0; i < tbl.size(); ++i) { // show contents of bucket i cout << "bucket " << setw(2) << i << ": "; copy(tbl[i].begin(), tbl[i].end(), ostream_iterator<int>(cout, " ")); cout << '\n'; } }
void move_init(table& x) { if(node_alloc() == x.node_alloc()) { move_buckets_from(x); } else if(x.size_) { // TODO: Could pick new bucket size? static_cast<table_impl*>(this)->move_buckets(x); } }
void database::create_structure(table& structure_table, bool key) { std::unique_ptr<std::list<unsigned long>> _all_column_table_tupleID = structure_table.internalID(); for (std::list<unsigned long>::const_iterator it = _all_column_table_tupleID->begin(); it != _all_column_table_tupleID->end(); it++) { std::unique_ptr<std::unordered_map<std::string, std::string>> tuple = structure_table.current(*it); std::string schema_name = tuple->find(column_field_name.table_schema)->second; std::string table_name = tuple->find(column_field_name.table_name)->second; std::string column_name = tuple->find(column_field_name.column_name)->second; std::string udt_name = tuple->find(column_field_name.udt_name)->second; std::string character_maximum = tuple->find(column_field_name.character_maximum_length)->second; std::string numeric_precision = tuple->find(column_field_name.numeric_precision)->second; std::string numeric_scale = tuple->find(column_field_name.numeric_scale)->second; sqlType::type_base* type = column_type(udt_name, character_maximum, numeric_precision, numeric_scale); if (!find_schema(schema_name)) add_schema(schema_name); schema& _schema = get_schema(schema_name); if (!_schema.find_table(table_name)) _schema.add_table(table_name); table& _table = _schema.get_table(table_name); _table.add_column(column_name, type, key); } }
bool table::operator==(const table & another) const { return this->size == another.get_size() && this->pot == another.get_pot() && this->street == another.get_street() && this->shared == another.get_cards() && this->players == another.get_players() && this->blinds == another.get_blinds(); }
void customer() // arriving customer { float t1; create("cust"); t1 = clock; // record start time qtbl.note_entry(); // note arrival f.reserve(); // reserve facility hold(expntl(SRV_TM)); // service interval f.release(); // release facility tbl.record(clock - t1); // record response time qtbl.note_exit(); // note departure if(--cnt == 0) done.set(); // if last customer, set done }
table table::operator=(const table & another) { this->size = another.get_size(); this->pot = another.get_pot(); this->street = another.get_street(); this->shared = another.get_cards(); this->players = another.get_players(); this->blinds = another.get_blinds(); return *this; }
void state::update(table & table) { street = table.get_street(); dealer_pos = table.get_dealer_pos(); active_players = table.active_players_count(); if (table.my_player_exists()) { pocket = table.get_my_player().get_hand(); equity = table.calculate_equity(); } else { pocket = make_hand(); equity = 0.f; } }
void table::merge(const table& src) { // if two tables are merged, the const of a const_column no longer // applies. std::map<std::string, column_ptr> converted_columns; for(auto& my_kv : m_columns) { if(my_kv.second->is_constant()) { converted_columns.insert( std::pair<std::string, column_ptr>(my_kv.first, column_ptr(new nonconst_column(my_kv.second)))); } } for(auto& converted_column : converted_columns) { m_columns.erase(converted_column.first); m_columns.insert(std::pair<std::string, column_ptr>( converted_column.first, converted_column.second)); } for(uint32_t i = 0; i < src.rows(); ++i) { add_row(); for(const auto& kv : src.m_columns) { auto name = kv.first; if (!has_column(name)) add_column(name); auto column = kv.second; set_value(name, column->value(i)); } } }
// Loads activitiess from external file "activities.txt" // into the hash table. int load_activities(activities & to_add, table & hash ) { ifstream fin; char * name = new char[45]; char * description = new char[150]; char * location = new char[21]; int difficulty = 0; char gear = 'Y'; char * key; fin.open("activities.txt"); if(fin) { fin.get(name,45, ':'); while(!fin.eof()) { fin.ignore(100,':'); fin.get(description, 150, ':'); fin.ignore(150,':'); fin.get(location, 21, ':'); fin.ignore(100,':'); fin >> difficulty; fin.ignore(100,':'); fin >> gear; fin.ignore(100,'\n'); key = new char[strlen(location) +1]; strcpy(key, location); to_add.add_activities(name, description, location, difficulty, gear); hash.insert(key, to_add); delete [] key; name = new char[45]; description = new char[150]; location = new char[21]; fin.get(name,45, ':'); } }fin.close(); return 1; }
state& set_userdata(userdata<T>& user) { global.set_userdata(user); return *this; }
state& set_function(T&& key, TFx&& fx, TObj&& obj) { global.set_function(std::forward<T>(key), std::forward<TFx>(fx), std::forward<TObj>(obj)); return *this; }
state& set_function(T&& key, TFx&& fx) { global.set_function(std::forward<T>(key), std::forward<TFx>(fx)); return *this; }
state& set(T&& key, U&& value) { global.set(std::forward<T>(key), std::forward<U>(value)); return *this; }