当前位置: 首页>>代码示例>>C++>>正文


C++ container::flat_map类代码示例

本文整理汇总了C++中boost::container::flat_map的典型用法代码示例。如果您正苦于以下问题:C++ flat_map类的具体用法?C++ flat_map怎么用?C++ flat_map使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了flat_map类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: TakeInSectionLL

void FloorSampler::TakeInSectionLL(
    const boost::container::flat_map<topic_t, std::pair<int, int> >& floor2c_t,
    int add_customers,
    int add_tables,
    int current_k,
    int depth) {
  int s = pdf_.size();
  auto it = floor2c_t.begin();
  int j = 0;
  if (!include_zero_) {
    j = 1;
    if (it != floor2c_t.end() && (*it).first == 0) ++it;
  }
  for (; j < s; ++j) {
    if (it == floor2c_t.end() || (*it).first > j) {
      assert(j != current_k); // current restaurant should never be empty
      pdf_[j] += arrangement_part_[depth]->log_p(add_customers, add_tables, 0, 0);
    } else {
      assert((*it).first == j);
      int c = (*it).second.first;
      int t = (*it).second.second;
      if (j == current_k) {
        c -= add_customers;
        t -= add_tables;
      }
      pdf_[j] += arrangement_part_[depth]->log_p(add_customers, add_tables, c, t);
      ++it;
    }
  }
}
开发者ID:nozyh,项目名称:topiclm,代码行数:30,代码来源:floor_sampler.cpp

示例2: heroProfiles

 std::vector<HeroProfile*> heroProfiles()
 {
     std::vector<HeroProfile*> profiles;
     profiles.reserve(globalHeroTable.size());
     
     transform(globalHeroTable.begin(), globalHeroTable.end(), back_inserter(profiles),
               [](boost::container::flat_map<int, HeroProfile*>::const_reference value){ return value.second; });
     
     std::sort(profiles.begin(), profiles.end(), [](HeroProfile* first, HeroProfile* second){
         return (first->tableId-9999.5)*(second->tableId-9999.5) < 0 ? first->tableId >= 10000 : first->tableId < second->tableId; });
     
     return profiles;
 }
开发者ID:13609594236,项目名称:ph-open,代码行数:13,代码来源:HeroTable.cpp

示例3: assert

std::pair<double,double> FermiTable::calcAverageAtomicProperties
(const boost::container::flat_map<string,double>& tracers) const
{
  double total = 0;
  double aa = 0;
  double zz = 0;
  for(std::map<string,std::pair<double,double> >::const_iterator it=
	atomic_properties_.begin();
      it!=atomic_properties_.end();++it){
    assert(tracers.count(it->first)==1);
    const double mass_frac = tracers.find(it->first)->second;
    const double A = it->second.first;
    const double Z = it->second.second;
    total += mass_frac;
    aa += mass_frac/A;
    zz += mass_frac*Z/A;
  }
  return std::pair<double,double>(total/aa,zz/aa);
}
开发者ID:eladtan,项目名称:white_dwarf_nova,代码行数:19,代码来源:fermi_table.cpp

示例4: is_better_armor

bool is_better_armor(const std::string &item_tag, boost::container::flat_map<item_location_t, float> &ac_by_loc) {
	auto finder = get_clothing_by_tag(item_tag);
	if (!finder) return false;

	const float item_ac = finder->armor_class;
	item_location_t loc = INVENTORY;
	if (finder->slot == "head") loc = HEAD;
	if (finder->slot == "torso") loc = TORSO;
	if (finder->slot == "legs") loc = LEGS;
	if (finder->slot == "shoes") loc = FEET;

	auto tester = ac_by_loc.find(loc);
	if (tester == ac_by_loc.end()) {
		return true;
	} else {
		if (item_ac > tester->second) return true;
	}

	return false;
}
开发者ID:thebracket,项目名称:bgame,代码行数:20,代码来源:inventory_system.cpp

示例5: EraseAndShrink

void EraseAndShrink(boost::container::flat_map<Key, Value>& x, Key& k) {
  x.erase(k);
  // if (x.size() < x.capacity() / 4) {
  //   boost::container::flat_map<Key, Value> y;
  //   y.reserve(x.capacity() / 2);
  //   for (auto& datum : x) {
  //     y.insert(datum);
  //   }
  //   x.swap(y);
  // }
}
开发者ID:nozyh,项目名称:topiclm,代码行数:11,代码来源:util.hpp

示例6: main

int main() {
    std::cout << "Element size: " << sizeof(map_element) << std::endl;

    std::cout << "std::map: ";
    run_tests(packet_collector_thread_std_map);
    DataCounter.clear();

#ifndef __APPLE__
    std::cout << "tbb::concurrent_unordered_map: ";
    run_tests(packet_collector_thread_unordered_concurrent_map);
    DataCounterUnorderedConcurrent.clear();
#endif

    // Boost unordered map
    std::cout << "boost::unordered_map: ";
    run_tests(packet_collector_thread_boost_unordered_map);
    DataCounterBoostUnordered.clear();

    // Boost flat_map
    DataCounterBoostFlatMap.reserve( number_of_ips );
    std::cout << "boost::container::flat_map with preallocated elements: ";
    run_tests(packet_collector_thread_flat_map_preallocated);
    DataCounterBoostFlatMap.clear();

    std::cout << "std::unordered_map C++11: ";
    run_tests(packet_collector_thread_unordered_map);
    DataCounterUnordered.clear();

    // Preallocate hash buckets
    DataCounterUnorderedPreallocated.reserve( number_of_ips );
    std::cout << "std::unordered_map C++11 preallocated buckets: ";
    run_tests(packet_collector_thread_unordered_map_preallocated);
    DataCounterUnorderedPreallocated.clear();

    // Preallocate vector
    DataCounterVector.reserve( number_of_ips );
    std::cout << "std::vector preallocated: ";
    run_tests(packet_collector_thread_vector);
    DataCounterVector.clear();
}
开发者ID:RolexColocat,项目名称:fastnetmon,代码行数:40,代码来源:traffic_structures_performance_tests.cpp

示例7: addHero

 int addHero(HeroProfile* h)
 {
     assert(globalHeroTable.count(h->tableId)==0 && "duplicate HeroProfile");
     globalHeroTable[h->tableId] = h;
     
     return globalHeroTable.size();
 }
开发者ID:13609594236,项目名称:ph-open,代码行数:7,代码来源:HeroTable.cpp

示例8: FillInPredictivesNonGraphical

inline void Restaurant::FillInPredictivesNonGraphical(
    const std::vector<double>& parent_predictives,
    int type,
    int depth,
    const HPYParameter& hpy_parameter,
    std::vector<double>& predictives) const {
  for (size_t i = 0; i < parent_predictives.size(); ++i) {
    predictives[i] = parent_predictives[i];
  }
  for (auto floor_it = floor2c_t_.begin(); floor_it != floor2c_t_.end(); ++floor_it) {
    auto floor_id = (*floor_it).first;
    auto& c_t = (*floor_it).second;
    tmp_c_[floor_id] = c_t.first;
    predictives[floor_id] *=
        (hpy_parameter.concentration(depth, floor_id)
         + hpy_parameter.discount(depth, floor_id) * c_t.second)
        / (c_t.first + hpy_parameter.concentration(depth, floor_id));
  }
  auto type_it = type2internal_.find(type);
  if (type_it == type2internal_.end()) return;

  auto& sections = (*type_it).second.sections_;
  auto section_it = sections.begin();
  for (; section_it != sections.end(); ++section_it) {
    auto floor_id = (*section_it).first;
    auto& section = (*section_it).second;
    auto cw = section.customers;
    auto tw = section.tables;
    predictives[floor_id] +=
        (cw - hpy_parameter.discount(depth, floor_id) * tw)
        / (tmp_c_[floor_id] + hpy_parameter.concentration(depth, floor_id));
  }
}
开发者ID:nozyh,项目名称:topiclm,代码行数:33,代码来源:restaurant.hpp

示例9: CreateExtSaveData

ResultCode CreateExtSaveData(MediaType media_type, u32 high, u32 low, VAddr icon_buffer,
                             u32 icon_size, const FileSys::ArchiveFormatInfo& format_info) {
    // Construct the binary path to the archive first
    FileSys::Path path =
        FileSys::ConstructExtDataBinaryPath(static_cast<u32>(media_type), high, low);

    auto archive = id_code_map.find(media_type == MediaType::NAND ? ArchiveIdCode::SharedExtSaveData
                                                                  : ArchiveIdCode::ExtSaveData);

    if (archive == id_code_map.end()) {
        return UnimplementedFunction(ErrorModule::FS); // TODO(Subv): Find the right error
    }

    auto ext_savedata = static_cast<FileSys::ArchiveFactory_ExtSaveData*>(archive->second.get());

    ResultCode result = ext_savedata->Format(path, format_info);
    if (result.IsError())
        return result;

    if (!Memory::IsValidVirtualAddress(icon_buffer))
        return ResultCode(-1); // TODO(Subv): Find the right error code

    std::vector<u8> smdh_icon(icon_size);
    Memory::ReadBlock(icon_buffer, smdh_icon.data(), smdh_icon.size());
    ext_savedata->WriteIcon(path, smdh_icon.data(), smdh_icon.size());
    return RESULT_SUCCESS;
}
开发者ID:FenrisulfrX,项目名称:citra,代码行数:27,代码来源:archive.cpp

示例10: addPSkill

	int addPSkill(SkillInfo* skill)
	{
		assert(globalSkillTable.count(skill->sid)==0 && "duplicate HeroProfile");
        globalSkillTable[skill->sid] = skill;
        
        return globalSkillTable.size();
	}
开发者ID:13609594236,项目名称:ph-open,代码行数:7,代码来源:HeroTable.cpp

示例11: FormatArchive

ResultCode FormatArchive(ArchiveIdCode id_code, const FileSys::ArchiveFormatInfo& format_info,
                         const FileSys::Path& path) {
    auto archive_itr = id_code_map.find(id_code);
    if (archive_itr == id_code_map.end()) {
        return UnimplementedFunction(ErrorModule::FS); // TODO(Subv): Find the right error
    }

    return archive_itr->second->Format(path, format_info);
}
开发者ID:FenrisulfrX,项目名称:citra,代码行数:9,代码来源:archive.cpp

示例12:

/*
 * Retrieve a material by tag
 */
boost::optional<std::size_t> get_material_by_tag(const std::string &tag) noexcept {
    boost::optional<std::size_t> result;

    auto finder = material_defs_idx.find(tag);
    if (finder != material_defs_idx.end()) {
        result = finder->second;
    }
    return result;
}
开发者ID:thebracket,项目名称:bgame,代码行数:12,代码来源:materials.cpp

示例13: UnimplementedFunction

ResultVal<FileSys::ArchiveFormatInfo> GetArchiveFormatInfo(ArchiveIdCode id_code,
                                                           FileSys::Path& archive_path) {
    auto archive = id_code_map.find(id_code);
    if (archive == id_code_map.end()) {
        return UnimplementedFunction(ErrorModule::FS); // TODO(Subv): Find the right error
    }

    return archive->second->GetFormatInfo(archive_path);
}
开发者ID:FenrisulfrX,项目名称:citra,代码行数:9,代码来源:archive.cpp

示例14: if

boost::optional<reaction_task_t> find_automatic_reaction_task(const settler_ai_t &ai) {
    if (automatic_reactions.empty()) return boost::optional<reaction_task_t>{};

    boost::optional<reaction_task_t> result;

    // Iterate through available reactions
    for (auto outerit=automatic_reactions.begin(); outerit != automatic_reactions.end(); ++outerit) {
        // Is the workshop busy?
        auto busy_finder = workshop_claimed.find(outerit->first);
        if (busy_finder == workshop_claimed.end()) {
            // Iterate available automatic reactions
            for (const std::string &reaction_name : outerit->second) {
                auto reaction = reaction_defs.find(reaction_name);
                if (reaction != reaction_defs.end()) {
                    // Is the settler allowed to do this?
                    int target_category = -1;
                    if (reaction->second.skill == "Carpentry") {
                        target_category = JOB_CARPENTRY;
                    } else if (reaction->second.skill == "Masonry") {
                        target_category = JOB_MASONRY;
                    }
                    if (target_category == -1 || ai.permitted_work[target_category]) {
                        // Are the inputs available?
                        bool available = true;
                        std::vector<std::pair<std::size_t,bool>> components;
                        for (auto &input : reaction->second.inputs) {
                            const int n_available = available_items_by_reaction_input(input);
                            if (n_available < input.quantity) {
                                available = false;
                            } else {
                                // Claim an item and push its # to the list
                                std::size_t item_id = claim_item_by_reaction_input(input);
                                components.push_back(std::make_pair(item_id,false));
                            }
                        }

                        if (available) {
                            // Components are available, build job and return it
                            result = reaction_task_t{outerit->first, reaction->second.name, reaction->second.tag, components};
                            workshop_claimed.insert(outerit->first);
                            return result;
                        } else {
                            for (auto comp : components) {
                                unclaim_by_id(comp.first);
                            }
                        }
                    }
                }
            }
        }
    }

    return result;
}
开发者ID:thebracket,项目名称:bgame,代码行数:54,代码来源:workflow_system.cpp

示例15: ResultCode

ResultVal<std::unique_ptr<FileSys::FileSystemBackend>> OpenFileSystem(Type type,
                                                                      FileSys::Path& path) {
    LOG_TRACE(Service_FS, "Opening FileSystem with type=%d", type);

    auto itr = filesystem_map.find(type);
    if (itr == filesystem_map.end()) {
        // TODO(bunnei): Find a better error code for this
        return ResultCode(-1);
    }

    return itr->second->Open(path);
}
开发者ID:restonexyz,项目名称:yuzu-NintendoSwitchEmulator,代码行数:12,代码来源:filesystem.cpp


注:本文中的boost::container::flat_map类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。