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


C++ unordered_map::emplace方法代码示例

本文整理汇总了C++中unordered_map::emplace方法的典型用法代码示例。如果您正苦于以下问题:C++ unordered_map::emplace方法的具体用法?C++ unordered_map::emplace怎么用?C++ unordered_map::emplace使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在unordered_map的用法示例。


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

示例1: beFriend

		void beFriend(string s1, string s2){
			if(graph.find(s1) == graph.end())//Finish statment
				graph.emplace(s1,node(s1));
			if(graph.find(s2) == graph.end())
				graph.emplace(s2, node(s2));
			graph.at(s1).attach(&graph.at(s2));
		}
开发者ID:cbkrunch,项目名称:myCode,代码行数:7,代码来源:p2.cpp

示例2: thread_pinned_buffer

void* GPUMemory::thread_pinned_buffer(size_t size, int group) {
  CHECK_GT(size, 0);
  auto host_buffer_cleaner = [&](void* buffer) {
    shared_lock<shared_mutex> lock(GPUMemory::read_write_mutex());
    CUDA_CHECK(cudaFreeHost(buffer));
  };
  auto device_buffer_cleaner = [&](void* buffer) {};
  static thread_local
  unordered_map<int, unique_ptr<void, decltype(host_buffer_cleaner)>> host_buffers;
  static thread_local
  unordered_map<int, unique_ptr<void, decltype(device_buffer_cleaner)>> device_buffers;
  static thread_local vector<size_t> sizes;
  if (group + 1U > sizes.size()) {
    sizes.resize(group + 1U);
  }
  if (size > sizes[group]) {
    void* hptr;
    void* dptr;
    CUDA_CHECK(cudaHostAlloc(&hptr, size, cudaHostAllocMapped));
    CUDA_CHECK(cudaHostGetDevicePointer(&dptr, hptr, 0));
    host_buffers.emplace(std::make_pair(group,
        unique_ptr<void, decltype(host_buffer_cleaner)>(hptr, host_buffer_cleaner)));
    device_buffers.emplace(std::make_pair(group,
        unique_ptr<void, decltype(device_buffer_cleaner)>(dptr, device_buffer_cleaner)));
    sizes[group] = size;
  }
  return device_buffers.find(group)->second.get();
}
开发者ID:Caffe-MPI,项目名称:Caffe-MPI.github.io,代码行数:28,代码来源:gpu_memory.cpp

示例3: mk_contractor_gsl

contractor mk_contractor_gsl(box const & box, shared_ptr<ode_constraint> const ctr, contractor const & eval_ctc, ode_direction const dir, bool const use_cache, double const timeout) {
    if (!use_cache) {
        return contractor(make_shared<contractor_gsl>(box, ctr, eval_ctc, dir, timeout));
    }
    if (dir == ode_direction::FWD) {
        static unordered_map<shared_ptr<ode_constraint>, contractor> gsl_fwd_ctc_cache;
        auto it = gsl_fwd_ctc_cache.find(ctr);
        if (it == gsl_fwd_ctc_cache.end()) {
            contractor ctc(make_shared<contractor_gsl>(box, ctr, eval_ctc, dir, timeout));
            gsl_fwd_ctc_cache.emplace(ctr, ctc);
            return ctc;
        } else {
            return it->second;
        }
    } else {
        static unordered_map<shared_ptr<ode_constraint>, contractor> gsl_bwd_ctc_cache;
        auto it = gsl_bwd_ctc_cache.find(ctr);
        if (it == gsl_bwd_ctc_cache.end()) {
            contractor ctc(make_shared<contractor_gsl>(box, ctr, eval_ctc, dir, timeout));
            gsl_bwd_ctc_cache.emplace(ctr, ctc);
            return ctc;
        } else {
            return it->second;
        }
    }
}
开发者ID:scungao,项目名称:dreal-next,代码行数:26,代码来源:contractor_gsl.cpp

示例4: read

  shared_ptr<Event> read()
  {
    uint8_t buffer_in[3];
    snd_rawmidi_read(handle_in, &buffer_in, 3);

    shared_ptr<NoteOnEvent> note_on, note_off;

    switch ( buffer_in[0] & 0xF0 )
    {
      case MIDI_NOTE_ON:
        if ( buffer_in[2] )
        {
          note_on = shared_ptr<NoteOnEvent>(new NoteOnEvent { buffer_in[1], buffer_in[2] });
          open_notes.emplace(buffer_in[1], note_on);
          return note_on;
        }
        else
        {
          note_on = open_notes.at(buffer_in[1]);
          open_notes.erase(buffer_in[1]);
          return shared_ptr<Event>(new NoteOffEvent { note_on });
        }

      case MIDI_NOTE_OFF:
        note_on = open_notes.at(buffer_in[1]);
        open_notes.erase(buffer_in[1]);
        return shared_ptr<Event>(new NoteOffEvent { note_on });

      case MIDI_CONTROL:
        return shared_ptr<Event>(new ControlEvent { static_cast<ControlEvent::Controller>(buffer_in[1]), buffer_in[2] });
      
      default:
        return shared_ptr<Event>(new Event {});
    }
  }
开发者ID:analoq,项目名称:seq,代码行数:35,代码来源:MidiDevice.hpp

示例5: mineTree

//从构造好的树中挖掘频繁项集
void FPTree::mineTree(string &prefix, unordered_map<string,int> &frequent)
{
	//头指针列表head中存储的实际是单频繁项。根据项值和计数值构造节点,插入到集合
	//不同于建树时,此时是按照计数值从低到高顺序排序
	vector<node> key_count;
	for (auto iter = head.begin(); iter != head.end(); ++iter)
		key_count.emplace_back(node(iter->first, iter->second->count));
	sort(key_count.begin(), key_count.end(), node::comparer::less());
	for (auto iter = key_count.begin(); iter != key_count.end(); ++iter)
	{//对于每一个单频繁项
		prefix.append(iter->key);
		frequent.emplace(prefix + ')',iter->count); //发现一个频繁项
		unordered_map<string, int> subdata;

		//以当前单频繁项为尾,在树中上溯挖掘条件基,也就是在已出现prefix的情况下挖掘记录
		findPrefixPath(iter->key, subdata); 
		FPTree subtree(eps);
		subtree.create(subdata); //根据挖掘到的记录构造的子数据集创建子FP树,以用于挖掘更复杂的频繁项
		if (!subtree.empty())
		{//如果树不空,即存在更复杂的频繁项
			prefix += ' ';//用于分隔记录项
			subtree.mineTree(prefix, frequent); //继续递归挖掘
			prefix.pop_back(); //删除空格
		}
		int index = prefix.rfind(' ');
		if (index == string::npos) prefix.resize(1); //删除iter->key
		else prefix.resize(index + 1);
	}
}
开发者ID:bravepam,项目名称:machine-learning-models,代码行数:30,代码来源:FPTree.cpp

示例6: appendProyectionParametrized

pairSet appendProyectionParametrized( pairSet candidates,       vector <seq_pointer_hash> &database, //
                            int threshold,              sequence_hash &prefix,          //
                            unordered_map <hashConv, vector<seq_pointer_hash> > &exit,
							unordered_map <string, int> &options){
    pairSet::iterator candStart, candEnd; candStart = candidates.begin(); candEnd = candidates.end();
    pairSet output;
    vector<seq_pointer_hash>::iterator dataStart, dataEnd, reset; dataStart = database.begin(); dataEnd = database.end();
    //Best spot for parallelism, do all of candidate threads and only thread 3 or 4 proyections at a time
    //to not bother with things that fail threshold pretty fast
    int limit = database.size() - threshold;
    while(candStart!=candEnd){
        vector <seq_pointer_hash> projectionResult;
        int complement =0;
        while((complement<=limit) && (dataStart!=dataEnd)){
            seq_pointer_hash p1 = dataStart->proyect(candStart->first, candStart->second);
            if (p1.null()){++complement;}
            else{projectionResult.push_back(p1);}
            ++dataStart;
        }if(complement<=limit){
            exit.emplace(convert(*candStart), projectionResult);
            output.insert(*candStart);
        }
        dataStart = database.begin();
        ++candStart;
    }
    return output;
}
开发者ID:zshwuhan,项目名称:PatternExtraction,代码行数:27,代码来源:prefixSpan_hash_parameterized.cpp

示例7: insert

	/** Inserts a value to the set. Returns true if the set did not already contain the specified element. */
	bool insert(int val) {
		if (hash.find(val) != hash.end())
			return false;
		nums.push_back(val);
		hash.emplace(val, nums.size() - 1);
		return true;
	}
开发者ID:whguo,项目名称:LeetCode,代码行数:8,代码来源:380.Insert+Delete+GetRandom+O(1).cpp

示例8: compressStringHelper

	string compressStringHelper(string in, unordered_map<string, string>& record) {	
		if (in.empty()) {
			return "";
		}
		auto it = record.find(in);
		if (it != record.end()) {
			return it->second;
		}
		const int s = in.size();
		string res;
		res = in[0] + compressStringHelper(in.substr(1), record);
		for (int i = 1; i < s; ++i) {
			string tmp_r = compressStringHelper(in.substr(i + 1), record);
			int w_size = 1;
			string tmp_l = in.substr(0, i + 1);
			for (int w_size = 1; w_size <= (i + 1) / 2; ++w_size) {
				string tmp = encode(in.substr(0, i + 1), w_size);
				if (tmp.size() < tmp_l.size()) {
					tmp_l = tmp;
				}
			}
			if (res.size() > tmp_l.size() + tmp_r.size()) {
				res = tmp_l + tmp_r;
			}
		}
		record.emplace(move(in), res);
		return res;
	}
开发者ID:ydu525,项目名称:CodingPractice,代码行数:28,代码来源:CompressString.cpp

示例9: copyGraph

 void copyGraph(
     unordered_map<UndirectedGraphNode *, UndirectedGraphNode *> &mapping,
     UndirectedGraphNode *vertex) {
   if (mapping.find(vertex) == mapping.end()) {
     mapping.emplace(vertex, new UndirectedGraphNode(vertex->label));
     for (auto *neighbor : vertex->neighbors) {
       copyGraph(mapping, neighbor);
     }
   }
 }
开发者ID:imxiaobo,项目名称:leetcode-solutions,代码行数:10,代码来源:133_cloneGraph.cpp

示例10: testNadd

inline int testNadd(const char *s) {
	auto p = map.find(s);
	if (p == map.end()) {
		parent[cnt] = cnt;
		sizes[cnt] = 1;
		map.emplace(s, cnt);
		return cnt++;
	}
	else return p->second;
}
开发者ID:isac322,项目名称:BOJ,代码行数:10,代码来源:4195.cpp14.cpp

示例11: mk_contractor_eval

contractor mk_contractor_eval(box const & box, nonlinear_constraint const * const ctr) {
    static thread_local unordered_map<nonlinear_constraint const *, contractor> cache;
    auto const it = cache.find(ctr);
    if (it == cache.cend()) {
        contractor ctc(make_shared<contractor_eval>(box, ctr));
        cache.emplace(ctr, ctc);
        return ctc;
    } else {
        return it->second;
    }
}
开发者ID:kquine,项目名称:dreal3,代码行数:11,代码来源:contractor_basic.cpp

示例12: findPrefixPath

//挖掘条件基,实际上是(条件)路径
void FPTree::findPrefixPath(const string& tail, unordered_map<string, int> &paths)
{
	treeNode *first = head[tail]->ptreenode;
	while (first)
	{//对于当前键为tail的节点
		string prefix;
		ascendTree(first, prefix);//由此上溯到根获得条件基
		if (!prefix.empty())//如果条件基存在
			paths.emplace(move(prefix), first->count);
		first = first->next;
	}
}
开发者ID:bravepam,项目名称:machine-learning-models,代码行数:13,代码来源:FPTree.cpp

示例13: transform

    // Returns a resource by name. Creates the resource
    //  if it doesn't yet exist.
    T& operator[](string name)
    {
      // Convert the string to lowercase.
      transform(name.begin(), name.end(), name.begin(), tolower);

      // Create the object if it doesn't exist.
      auto it = objects.find(name);
      if (it == objects.end())
      {
        it = objects.emplace(name, name).first;
      }
      return it->second;
    }
开发者ID:ItsRoyScott,项目名称:Lite,代码行数:15,代码来源:GraphicsResourceManager.hpp

示例14: Audio

    // Initializes FMOD Studio and loads all sound banks.
    Audio() :
      Listener(system)
    {
      // Create the FMOD Studio system.
      FmodCall(fmod::System::create(&system));
      // Initialize the system.
      FmodCall(system->initialize(
        maxChannels,               // max channels capable of playing audio
        FMOD_STUDIO_INIT_NORMAL,   // studio-specific flags
        FMOD_INIT_3D_RIGHTHANDED,  // regular flags
        nullptr));                 // extra driver data

      vector<fmod::Bank*> banks;

      // For each file in the Sounds directory with a *.bank extension:
      for (const string& file : PathInfo(config::Sounds).FilesWithExtension("bank"))
      {
        // Load the sound bank from file.
        fmod::Bank* bank = nullptr;
        FmodCall(system->loadBankFile(file.c_str(), FMOD_STUDIO_LOAD_BANK_NORMAL, &bank));

        banks.push_back(bank);
      }

      for (fmod::Bank* bank : banks)
      {
        // Get the number of events in the bank.
        int eventCount = 0;
        FmodCall(bank->getEventCount(&eventCount));
        if (eventCount == 0) continue;

        // Get the list of event descriptions from the bank.
        auto eventArray = vector<fmod::EventDescription*>(static_cast<size_t>(eventCount), nullptr);
        FmodCall(bank->getEventList(eventArray.data(), eventArray.size(), nullptr));

        // For each event description:
        for (fmod::EventDescription* eventDescription : eventArray)
        {
          // Get the path to the event, e.g. "event:/Ambience/Country"
          auto path = string(512, ' ');
          int retrieved = 0;
          FmodCall(eventDescription->getPath(&path[0], path.size(), &retrieved));
          path.resize(static_cast<size_t>(retrieved - 1)); // - 1 to account for null character

          // Save the event description in the event map.
          eventDescriptionMap.emplace(path, EventDescription(eventDescription, path));
        }
      }

      Note(*this);
    }
开发者ID:ItsRoyScott,项目名称:Lite,代码行数:52,代码来源:Audio.hpp

示例15: populate_hashmap

int populate_hashmap(int i)
{
	std::this_thread::sleep_for(std::chrono::nanoseconds(i*i*i*i*i*i*i));
	cout<<"Move-assigned thread creation for value "<<i<<" ..."<<endl;
	hashmap.emplace(std::make_pair(std::to_string(i),i));
	if (i%2 == 0)
	{
		hashmap.max_load_factor(hashmap.max_load_factor()*3);
	}
	else
	{
		hashmap.rehash(3);
	}
}
开发者ID:shrinivaasanka,项目名称:Grafit,代码行数:14,代码来源:threads.cpp


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