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; }
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; }
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); }
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; }
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_; }
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); }
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(); }
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; }
std::vector<typename MapT::mapped_type> map_values(MapT const& m) { return map_values<typename MapT::mapped_type>(m.begin(), m.end()); }
std::vector<typename MapT::key_type> map_key(MapT const& m) { return map_key<typename MapT::key_type>(m.begin(), m.end()); }
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; }
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; }