• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

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

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



在下文中一共展示了flat_map类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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: HPT


//.........这里部分代码省略.........
                double val;
                boost::tie(effect, val) = pair;
                
                if(effect == HP)
                    h.health += refH.health * val;
                else if(effect == STRENGTH)
                    h.attack += refH.attack * val;
                else if(effect == REGEN)
                    h.regen += refH.regen * val;
                else
                    LOGD("Unknown relation effect %d", effect);
            }
        }
        return h;
    }
    
    //---------------
    // Hero
    //---------------
    Hero::Hero(std::string uid, int hid, int lvl, int ex) :id(uid), heroId(hid), level(lvl), exp(ex)
    {
        profile = &HPT(hid);
        
        eliteLevel = 0;
        health = profile->health.eval(level);
        attack = profile->attack.eval(level);
        regen  = profile->regen.eval(level);
        expCap = level > profile->maxLevel ? -1 : profile->exp.eval(level);
        maxEnergy = profile->activeSkillId != -1 ? AST(profile->activeSkillId).energy : 0;
        skillBonus = 0;
        trainPrice = lvl * 100;
    }
    
    static boost::container::flat_map<int, HeroProfile*> globalHeroTable;
	static boost::container::flat_map<int, SkillInfo*> globalSkillTable;
    
    const SkillInfo& AST(int i)
    {
        assert(globalSkillTable.count(i) && "Skill does not exist");
        return *globalSkillTable[i];
    }
    
    const SkillInfo& PST(int i)
    {
        assert(globalSkillTable.count(i) && "Skill does not exist");
        return *globalSkillTable[i];
    }
    
    const HeroProfile& HPT(int i)
    {
        assert(globalHeroTable.count(i) && "HeroProfile does not exist");
        return *globalHeroTable[i];     }
    
    int HPTN(const HeroProfile *profile)
    {
        std::vector<HeroProfile*> profiles = heroProfiles();
        for(int i = 0 ; i < profiles.size() ; i++)
        {
            if(profiles[i] && profiles[i]->tableId == profile->tableId)return i;
        }
        return -1;
    }
    
    std::vector<HeroProfile*> heroProfiles()
    {
        std::vector<HeroProfile*> profiles;
开发者ID:13609594236,项目名称:ph-open,代码行数:67,代码来源:HeroTable.cpp


示例8: 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


示例9: 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


示例10: 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


示例11: 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


示例12: 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


示例13:

/*
 * 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


示例14: 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


示例15: 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


示例16: 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


示例17: ResultCode

ResultVal<ArchiveHandle> OpenArchive(ArchiveIdCode id_code, FileSys::Path& archive_path) {
    LOG_TRACE(Service_FS, "Opening archive with id code 0x%08X", id_code);

    auto itr = id_code_map.find(id_code);
    if (itr == id_code_map.end()) {
        // TODO: Verify error against hardware
        return ResultCode(ErrorDescription::NotFound, ErrorModule::FS, ErrorSummary::NotFound,
                          ErrorLevel::Permanent);
    }

    CASCADE_RESULT(std::unique_ptr<ArchiveBackend> res, itr->second->Open(archive_path));

    // This should never even happen in the first place with 64-bit handles,
    while (handle_map.count(next_handle) != 0) {
        ++next_handle;
    }
    handle_map.emplace(next_handle, std::move(res));
    return MakeResult<ArchiveHandle>(next_handle++);
}
开发者ID:FenrisulfrX,项目名称:citra,代码行数:19,代码来源:archive.cpp


示例18: RegisterFileSystem

ResultCode RegisterFileSystem(std::unique_ptr<FileSys::FileSystemFactory>&& factory, Type type) {
    auto result = filesystem_map.emplace(type, std::move(factory));

    bool inserted = result.second;
    ASSERT_MSG(inserted, "Tried to register more than one system with same id code");

    auto& filesystem = result.first->second;
    LOG_DEBUG(Service_FS, "Registered file system %s with id code 0x%08X",
              filesystem->GetName().c_str(), static_cast<u32>(type));
    return RESULT_SUCCESS;
}
开发者ID:restonexyz,项目名称:yuzu-NintendoSwitchEmulator,代码行数:11,代码来源:filesystem.cpp


示例19: RegisterArchiveType

// TODO(yuriks): This might be what the fs:REG service is for. See the Register/Unregister calls in
// http://3dbrew.org/wiki/Filesystem_services#ProgramRegistry_service_.22fs:REG.22
ResultCode RegisterArchiveType(std::unique_ptr<FileSys::ArchiveFactory>&& factory,
                               ArchiveIdCode id_code) {
    auto result = id_code_map.emplace(id_code, std::move(factory));

    bool inserted = result.second;
    ASSERT_MSG(inserted, "Tried to register more than one archive with same id code");

    auto& archive = result.first->second;
    LOG_DEBUG(Service_FS, "Registered archive %s with id code 0x%08X", archive->GetName().c_str(),
              id_code);
    return RESULT_SUCCESS;
}
开发者ID:FenrisulfrX,项目名称:citra,代码行数:14,代码来源:archive.cpp


示例20: predictive_probability

double Restaurant::predictive_probability(topic_t floor_id,
                                          int type,
                                          double parent_probability,
                                          double discount,
                                          double concentration) const {
  int cw = 0;
  int tw = 0;
  int c = 0;
  int t = 0;

  auto section_it = type2internal_.find(type);
  if (section_it != type2internal_.end()) {
    cw = (*section_it).second.customers(floor_id);
    tw = (*section_it).second.tables(floor_id);
  }
  auto floor_it = floor2c_t_.find(floor_id);
  if (floor_it != floor2c_t_.end()) {
    c = (*floor_it).second.first;
    t = (*floor_it).second.second;
  }
  return ComputePYPPredictive(cw, tw, c, t, parent_probability, discount, concentration);
}
开发者ID:nozyh,项目名称:topiclm,代码行数:22,代码来源:restaurant.hpp



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ container::vector类代码示例发布时间:2022-05-31
下一篇:
C++ compute::device类代码示例发布时间:2022-05-31
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap