std::set<typename MapT::key_type> key_set(const MapT& m) { std::set<typename MapT::key_type> answer; for (auto it = m.begin(); it != m.end(); ++it) { answer.insert(it->first); } return answer; }
std::set<typename MapT::mapped_type> value_set(const MapT& m) { std::set<typename MapT::mapped_type> answer; for (auto it = m.begin(); it != m.end(); ++it) { answer.insert(it->second); } return answer; }
double Note2FreqTable::operator[](string str) const { MapT::const_iterator iter = m_rep.find(str); assert(iter != m_rep.end()); return iter->second; }
static void load_and_init_with_map(const char* file, double* cpu_times, MapT& M) { FILE* f = fopen(file,"r"); if(f == NULL){ fprintf(stderr, "Could not open %s file: %s", file, strerror(errno)); exit(-1); } double nanosec; char ops[48]; char line[512]; std::string tmp = ""; while(fgets(line,sizeof(line),f)){ unsigned op; if (sscanf(line, "%47[^:]:\t%lf nanoseconds", ops, &nanosec) == 2) { tmp = ops; auto ite = M.find(ops); if (ite != M.end()) { op = ite->second; cpu_times[op] = nanosec; } else continue; } } fclose(f); }
void DSF(TMap const & maze, MapKeyT const & cur, MapKeyT const & prev, Cell const & target, MapT & data, vector<vector<int>> const & bonuses) { bool IsOpposite = GetOppositeDirection(prev.second) == cur.second; double to_add = (IsOpposite ? 3 : 1); if (bonuses[cur.first.m_x][cur.first.m_y] == 1) to_add -= 0.5; bool need_update = data.count(cur) == 0; need_update |= data[cur].first > data[prev].first + to_add; if (need_update) { double prev_dist = data.count(prev) == 0 ? 0 : data[prev].first; data[cur] = {prev_dist + to_add, prev}; } if (cur.first == target) return; if (need_update) { if (CanPass(maze, cur.first, cur.second)) DSF(maze, {cur.first.GetNeibor(cur.second), cur.second}, cur, target, data, bonuses); for (auto const & dir: AllDirections()) if (CanPass(maze, cur.first, dir)) DSF(maze, {cur.first.GetNeibor(dir), dir}, cur, target, data, bonuses); } }
typename MapT::const_iterator find_nearest(MapT const& m, typename MapT::key_type const& query, typename MapT::key_type const& tolerance) { typename MapT::const_iterator cur, min, max, best; min = m.lower_bound(query - tolerance); max = m.lower_bound(query + tolerance); if (min == m.end() || fabs(query - min->first) > tolerance) return m.end(); else if (min == max) return min; else best = min; double minDiff = fabs(query - best->first); for (cur = min; cur != max; ++cur) { double curDiff = fabs(query - cur->first); if (curDiff < minDiff) { minDiff = curDiff; best = cur; } } return best; }
vector<Cell> GetClosestPath(const model::World& world, Cell const & start, Direction const start_dir, Cell const & finish, Game const & game) { static map<cashe_key, vector<Cell> > cacshe; static int bonus_hash = 0; int bonus_hash_cur = 0; auto const & map = world.getTilesXY(); vector<vector<int>> bonuses(map.size(), vector<int>(map[0].size(), 0)); for (Bonus const & bonus: world.getBonuses()) { bonus_hash_cur += bonus.getX() * bonus.getX() + bonus.getY() * bonus.getY(); auto bonus_cell= GetCell(bonus, game); bonuses[bonus_cell.m_x][bonus_cell.m_y] = (bonus.getType() == PURE_SCORE || bonus.getType() == REPAIR_KIT) ? 1 : 0; } if (bonus_hash != bonus_hash_cur) { bonus_hash = bonus_hash_cur; cacshe.clear(); } cashe_key ck = {start, start_dir, finish}; if (cacshe.count(ck) == 1) return cacshe[ck]; MapT data; DSF(world.getTilesXY(), {start, start_dir}, {start, start_dir}, finish, data, bonuses); // PrintMap(world.getTilesXY(), data); vector<Cell> res; int const INF = 1000000; int best = INF; MapKeyT cur = {finish, LEFT}; for (auto dir: AllDirections()) { if (data.count({finish,dir}) == 0) continue; if (data[{finish,dir}].first < best) { best = data[{finish,dir}].first; cur = {finish,dir}; } } if (best == INF) return res; while (cur.first != start) { res.push_back(cur.first); cur = data[cur].second; } res.push_back(start); reverse(res.begin(), res.end()); cacshe[ck] = res; return res; }
inline index_type map_processor_index(MapT const& map, processor_type pid) { for (index_type i=0; i<map.processor_set().size(); ++i) if (map.processor_set().get(i) == pid) return i; return no_index; }
void wxsItemEditor::BuildPalette(wxNotebook* Palette) { Palette->DeleteAllPages(); bool AllowNonXRCItems = (m_Data->GetPropertiesFilter() & flSource); // First we need to split all widgets into groups // it will be done using multimap (map of arrays) MapT Map; for ( const wxsItemInfo* Info = wxsItemFactory::GetFirstInfo(); Info; Info = wxsItemFactory::GetNextInfo() ) { if ( !Info->Category.empty() ) { Map[Info->Category].Add(Info); } } for ( MapT::iterator i = Map.begin(); i!=Map.end(); ++i ) { wxScrolledWindow* CurrentPanel = new wxScrolledWindow(Palette,-1,wxDefaultPosition,wxDefaultSize,0/*wxALWAYS_SHOW_SB|wxHSCROLL*/); CurrentPanel->SetScrollRate(1,0); Palette->AddPage(CurrentPanel,i->first); wxSizer* RowSizer = new wxBoxSizer(wxHORIZONTAL); ItemsT& Items = i->second; Items.Sort(PrioritySort); for ( size_t j=Items.Count(); j-->0; ) { const wxsItemInfo* Info = Items[j]; const wxBitmap& Icon = ( PalIconSize() == 16L ) ? Info->Icon16 : Info->Icon32; if ( AllowNonXRCItems || Info->AllowInXRC ) { wxWindow* Btn; if ( Icon.Ok() ) { Btn = new wxBitmapButton(CurrentPanel,-1,Icon, wxDefaultPosition,wxDefaultSize,wxBU_AUTODRAW, wxDefaultValidator, Info->ClassName); RowSizer->Add(Btn,0,wxALIGN_CENTER); } else { Btn = new wxButton(CurrentPanel,-1,Info->ClassName, wxDefaultPosition,wxDefaultSize,0, wxDefaultValidator,Info->ClassName); RowSizer->Add(Btn,0,wxGROW); } Btn->SetToolTip(Info->ClassName); } } CurrentPanel->SetSizer(RowSizer); RowSizer->SetVirtualSizeHints(CurrentPanel); } }
void show_map_contents(OStreamT& os, MapT& m, const std::string& title) { os<< "<h3>" << title << "</h3>"; if (m.empty()) os<< "NONE<br />"; else for (typename MapT::const_iterator i = m.begin(); i != m.end(); ++i) os<< "<b>" << i->first << "</b> = <i>" << i->second << "</i><br />"; }
void Module::process_f_lit_map(MapT& map, vector<LitT>& vec) { vec.assign(map.begin(), map.end()); sort(vec.begin(), vec.end(), [](const LitT& lhs, const LitT& rhs) { return lhs.second > rhs.second; }); size_t new_size = vec.size(); for (; new_size > 0 && vec[new_size - 1].second <= 3; new_size--) map.erase(vec[new_size - 1].first); vec.resize(new_size); for (size_t i = 0; i < vec.size(); i++) map[vec[i].first] = static_cast<uint32_t>(i); }
std::vector<typename MapT::mapped_type> map_values(MapT const& m, KeyIterT key_first, KeyIterT key_last) { std::vector<typename MapT::mapped_type> res; while (key_first != key_last) { if (m.count(*key_first) > 0) { res.push_back(m.at(*key_first)); } ++key_first; } return res; }
bool Cstore::VarRef::getValue(string& value, vtw_type_e& def_type) { vector<string> result; MapT<string, bool> added; def_type = ERROR_TYPE; for (size_t i = 0; i < _paths.size(); i++) { if (_paths[i].first.size() == 0) { // empty path continue; } if (added.find(_paths[i].first.back()) != added.end()) { // already added continue; } if (_paths[i].second == ERROR_TYPE && !_cstore->cfgPathExists(_paths[i].first, _active)) { // path doesn't exist => empty string added[""] = true; result.push_back(""); continue; } if (_paths[i].second != ERROR_TYPE) { // set def_type. all types should be the same if multiple entries exist. def_type = _paths[i].second; } added[_paths[i].first.back()] = true; result.push_back(_paths[i].first.back()); } if (result.size() == 0) { // got nothing return false; } if (result.size() > 1 || def_type == ERROR_TYPE) { /* if no type is available or we are returning "joined" multiple values, * treat it as text type. */ def_type = TEXT_TYPE; } value = ""; for (size_t i = 0; i < result.size(); i++) { if (i > 0) { value += " "; } value += result[i]; } return true; }
//! @internal template <class Archive, class MapT> inline void save( Archive & ar, MapT const & map ) { ar( make_size_tag( static_cast<size_type>(map.size()) ) ); for( const auto & i : map ) ar( make_map_item(i.first, i.second) ); }
typename MapT::const_iterator next_proton(typename MapT::const_iterator& iter_, const MapT& object) { while( iter_ != object.end() && (*iter_).second == identity_element<typename MapT::codomain_type>::value()) ++iter_; return iter_; }
//! @internal template <class Archive, class MapT> inline void load( Archive & ar, MapT & map ) { size_type size; ar( make_size_tag( size ) ); map.clear(); map.reserve( size ); for( size_type i = 0; i < size; ++i ) { typename MapT::key_type key; typename MapT::mapped_type value; ar( make_map_item(key, value) ); map.insert( {key, value} ); } }
//! @internal template <class Archive, class MapT> inline void load( Archive & ar, MapT & map ) { size_type size; ar( make_size_tag( size ) ); map.clear(); auto hint = map.begin(); for( size_t i = 0; i < size; ++i ) { typename MapT::key_type key; typename MapT::mapped_type value; ar( make_map_item(key, value) ); hint = map.emplace_hint( hint, std::move( key ), std::move( value ) ); } }
//! @internal template <class Archive, class MapT> inline void load( Archive & ar, MapT & map ) { size_type size; ar( make_size_tag( size ) ); map.clear(); auto hint = map.begin(); for( size_t i = 0; i < size; ++i ) { typename MapT::key_type key; typename MapT::mapped_type value; ar( make_map_item(key, value) ); #ifdef CEREAL_OLDER_GCC hint = map.insert( hint, std::make_pair(std::move(key), std::move(value)) ); #else // NOT CEREAL_OLDER_GCC hint = map.emplace_hint( hint, std::move( key ), std::move( value ) ); #endif // NOT CEREAL_OLDER_GCC } }
typename enable_if < mpl::and_< mpl::not_<is_total<Type> > , is_concept_compatible<is_interval_map, Type, MapT> > , void >::type add_intersection(Type& section, const Type& object, const MapT& operand) { typedef typename Type::segment_type segment_type; typedef typename Type::interval_type interval_type; typedef typename MapT::const_iterator const_iterator; if(operand.empty()) return; const_iterator common_lwb, common_upb; if(!Set::common_range(common_lwb, common_upb, operand, object)) return; const_iterator it_ = common_lwb; while(it_ != common_upb) add_intersection(section, object, *it_++); }
bool lexicographical_distinct_equal(const MapT& left, const MapT& right) { if(&left == &right) return true; typename MapT::const_iterator left_ = left.begin(); typename MapT::const_iterator right_ = right.begin(); left_ = next_proton(left_, left); right_ = next_proton(right_, right); while(left_ != left.end() && right_ != right.end()) { if(!(left_->first == right_->first && left_->second == right_->second)) return false; ++left_; ++right_; left_ = next_proton(left_, left); right_ = next_proton(right_, right); } return left_ == left.end() && right_ == right.end(); }
int ProcessError( IdType error_type, IdType error_Id, IdType error_ref, IdType error_cond, NetVT* net_values_FF, NetVT* net_values_E, IdType &start_module_Id, ForestT* forest, int thread_num) { int retval = 0; start_module_Id = NULL_Id; IdType sum_Id2 = NULL_Id; MapT* map2 = &net_values_FF[error_cond].root_Ids; for (ValueType i=0; i<1; i++) { MapTI it = map2->find( i==0? 0 : (1<<net_widths[error_ref]) -1); if (it != map2->end()) { if (sum_Id2 == NULL_Id) sum_Id2 = it->second; else { IdType temp_Id = NULL_Id; forest->AddTree(thread_num, it->second, sum_Id2, temp_Id, 0); } } } if (sum_Id2 == NULL_Id) return retval; switch (error_type) { case 0: // Bus line struck { net_values_E[error_Id].root_Ids.clear(); IdType sum_Id = NULL_Id; MapT* map = &net_values_FF[error_Id].root_Ids; for (MapTI it = map->begin(); it != map->end(); it++) { if (sum_Id == NULL_Id) sum_Id = it->second; else { IdType sum_Id2 = NULL_Id; forest->AddTree(thread_num, it->second, sum_Id, sum_Id2, 0); sum_Id = sum_Id2; } } net_values_E[error_Id].root_Ids.insert(MapTP(error_ref, sum_Id)); start_module_Id = nets[error_Id]->to_module; break; } case 1: // Bus order error { //IdType sum_Id = NULL_Id; MapT* map_ff = &net_values_FF[error_Id].root_Ids; MapT* map_e = &net_values_E [error_Id].root_Ids; map_e->clear(); for (MapTI it = map_ff->begin(); it != map_ff->end(); it++) { map_e->insert(MapTP(Reverse(it->first), it->second)); } start_module_Id = nets[error_Id]->to_module; break; } case 2: // Bus source error { //IdType sum_Id = NULL_Id; MapT* map_ff = &net_values_FF[error_ref].root_Ids; MapT* map_e = &net_values_E [error_Id].root_Ids; map_e->clear(); for (MapTI it = map_ff->begin(); it != map_ff->end(); it++) { map_e->insert(MapTP(it->first, it->second)); } start_module_Id = nets[error_Id]->to_module; break; } case 3: // Bus count error { //IdType sum_Id = NULL_Id; MapT* map_ff = &net_values_FF[error_Id].root_Ids; MapT* map_e = &net_values_E [error_Id].root_Ids; map_e->clear(); for (MapTI it_ff = map_ff->begin(); it_ff != map_ff->end(); it_ff++) { ValueType value = it_ff->first & ((1<<error_ref)-1); MapTI it = map_ff->find(value); if (it == map_ff->end()) map_e->insert(MapTP(value, it_ff->second)); else { IdType temp_Id = NULL_Id; retval = forest->AddTree(thread_num, it_ff->second, it->second, temp_Id, 0); it->second = temp_Id; } } start_module_Id = nets[error_Id]->to_module; break; } case 4: // conditional bus stuck line { net_values_E[error_Id].root_Ids.clear(); IdType sum_Id = NULL_Id; MapT* map = &net_values_FF[error_Id].root_Ids; for (MapTI it = map->begin(); it != map->end(); it++) { if (sum_Id == NULL_Id) sum_Id = it->second; else { IdType sum_Id2 = NULL_Id; forest->AddTree(thread_num, it->second, sum_Id, sum_Id2, 0); sum_Id = sum_Id2; } } if (sum_Id == NULL_Id) break; IdType temp_Id = NULL_Id; forest->AndTree(thread_num, sum_Id, sum_Id2, temp_Id, 0); if (temp_Id != NULL_Id) { net_values_E[error_Id].root_Ids.insert(MapTP(error_ref,temp_Id)); } start_module_Id = nets[error_Id]->to_module; break; } case 5: // conditional bus order error { MapT* map_ff = &net_values_FF[error_Id].root_Ids; MapT* map_e = &net_values_E [error_Id].root_Ids; map_e->clear(); for (MapTI it = map_ff->begin(); it != map_ff->end(); it++) { IdType temp_Id = NULL_Id; forest->AndTree(thread_num, it->second, sum_Id2, temp_Id, 0); if (temp_Id == NULL_Id) continue; map_e->insert(MapTP(Reverse(it->first), temp_Id)); } start_module_Id = nets[error_Id]->to_module; break; } case 6: // conditional bus source error { //IdType sum_Id = NULL_Id; MapT* map_ff = &net_values_FF[error_ref].root_Ids; MapT* map_e = &net_values_E [error_Id].root_Ids; map_e->clear(); for (MapTI it = map_ff->begin(); it != map_ff->end(); it++) { IdType temp_Id = NULL_Id; forest->AndTree(thread_num, it->second, sum_Id2, temp_Id, 0); if (temp_Id == NULL_Id) continue; map_e->insert(MapTP(it->first, temp_Id)); } start_module_Id = nets[error_Id]->to_module; break; } case NUM_NET_ERRORS + 0: // bypass module { ModuleT* module = modules[error_Id]; MapT* map_input = &net_values_FF[module->input_Ids[error_ref]].root_Ids; MapT* map_output = &net_values_E[module->output_Ids[error_cond]].root_Ids; map_output->clear(); for (MapTI it= map_input->begin(); it!= map_input->end(); it++) { map_output->insert(MapTP(it->first, it->second)); } start_module_Id = nets[module->output_Ids[error_cond]]->to_module; break; } case NUM_NET_ERRORS + 1: // Add not to outputs { ModuleT* module = modules[error_Id]; IdType net_Id = module->output_Ids[error_ref]; MapT* map_ff = &net_values_FF[net_Id].root_Ids; MapT* map_e = &net_values_E [net_Id].root_Ids; map_e->clear(); for (MapTI it = map_ff->begin(); it != map_ff->end(); it++) { map_e->insert(MapTP(~(it->first), it->second)); } start_module_Id = nets[net_Id]->to_module; break; } case NUM_NET_ERRORS + 2: // Module substituation { break; } default: break; } return retval; }
ValueT get_value_or(const MapT &map, const KeyT &key, ValueT def) { typename MapT::const_iterator it(map.find(key)); return it != map.end() ? it->second : def; }
std::vector<typename MapT::key_type> map_key(MapT const& m) { return map_key<typename MapT::key_type>(m.begin(), m.end()); }
std::vector<typename MapT::mapped_type> map_values(MapT const& m) { return map_values<typename MapT::mapped_type>(m.begin(), m.end()); }
int main(int argc, char* argv[]) { int retval = 0; ForestT* forest = NULL; NetVT* net_values_FF = NULL; int* retvals = NULL; IdType** thread_modules = NULL; NetVT** net_values_E = NULL; do { if ((retval = ReadInput(argc, argv))) break; if ((retval = MakeOrder() )) break; if ((retval = GetDependency() )) break; #pragma omp parallel { int thread_num = omp_get_thread_num(); int num_threads = omp_get_num_threads(); #pragma omp single { do { retvals = new int[num_threads]; memset(retvals, 0, sizeof(int) * num_threads); forest = new ForestT; if ((retvals[thread_num] = forest->Init(num_threads, num_inputs, net_widths))) break; thread_inputs = new ValueType*[num_threads]; thread_outputs = new ValueType*[num_threads]; thread_modules = new IdType*[num_threads]; for (SizeType i=0; i<num_threads; i++) { thread_inputs[i] = new ValueType[max_num_inputs]; thread_outputs[i] = new ValueType[max_num_outputs]; thread_modules[i] = new IdType[num_modules]; } net_values_FF = new NetVT[num_nets]; //prepare the inputs for (SizeType i=0; i<num_inputs; i++) { MapT* map = &net_values_FF[i].root_Ids; for (ValueType j=0; j< (1<<net_widths[i]); j++) { IdType temp_Id = NULL_Id; retvals[thread_num] = forest->NewTree(thread_num, i, j, temp_Id); if (retvals[thread_num] != 0) break; map->insert(MapTP(j, temp_Id)); } } for (IdType i=0; i<num_modules; i++) thread_modules[thread_num][i] = i; // Evaluate the FF cicuit if ((retvals[thread_num] = Evaluate(num_modules, thread_modules[thread_num], net_values_FF, NULL, forest, thread_num))) break; if ((retvals[thread_num] = GenerateErrors())) break; net_values_E = new NetVT*[num_errors]; for (SizeType i=0; i<num_errors; i++) net_values_E[i] = new NetVT[num_nets]; } while(0); } #pragma omp for for (IdType i=0; i<num_errors; i++) { if (retvals[thread_num] != 0) continue; IdType error_type = error_types.find(i)->second; IdType error_Id = error_Ids .find(i)->second; IdType error_ref = error_refs .find(i)->second; IdType error_cond = error_conds.find(i)->second; IdType start_module_Id = NULL_Id; SizeType module_count = 0; // Place the error if ((retvals[thread_num] = ProcessError(error_type, error_Id, error_ref, error_cond, net_values_FF, net_values_E[i], start_module_Id, forest, thread_num))) continue; if (start_module_Id == NULL_Id) continue; // Get list of modules to evaluate if ((retvals[thread_num] = GetModuleList(start_module_Id, module_count, thread_modules[thread_num]))) continue; // Evaluate the faulty circuit if ((retvals[thread_num] = Evaluate(module_count, thread_modules[thread_num], net_values_FF, net_values_E[i], forest, thread_num))) continue; } if (retvals[thread_num] != 0) cerr<<"Thread "<<thread_num<<" terminated with error code "<<retvals[thread_num]<<endl; } } while(0); if (retval != 0) cerr<<"Terminated with error code "<<retval<<endl; return retval; }