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


C++ HashMap::insert方法代码示例

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


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

示例1: main

int main()
{
    HashMap map;

    map.insert(1,10);
    map.insert(20,200);
    map.insert(3,30);
    map.insert(99,990);

    std::cout << "Expecting: 10" << std::endl;
    std::cout << "Got: " << map.get(1) << std::endl;

    std::cout << "Expecting: 200" << std::endl;
    std::cout << "Got: " << map.get(20) << std::endl;

    std::cout << "Expecting: 30" << std::endl;
    std::cout << "Got: " << map.get(3) << std::endl;

    std::cout << "Expecting: 990" << std::endl;
    std::cout << "Got: " << map.get(99) << std::endl;

    map.insert(99,888);

    std::cout << "Expecting: 888" << std::endl;
    std::cout << "Got: " << map.get(99) << std::endl;


    return 0;
}
开发者ID:bgianfo,项目名称:intervew-review,代码行数:29,代码来源:hashmap.cpp

示例2: main

int main(int argc, const char * argv[]) {
    // insert code here...
    vector<vector<int> > numbers = { {2, 4, 3, 6, 8, 10},
        {10, 2, 1, 2, 0, 1}, {8, 4, 9, 6, 0, 1},
        {8, 4, 3, 6, 8, 4}, {0, 9, 8, 7, 5, 2},
        {9, 4, 3, 6, 8, 10}, {1, 4, 3, 6, 8, 10},
        {2, 4, 3, 6, 8, 10}, {7, 4, 3, 6, 5, 2}};
    
    int length = int(numbers.size());
    for (int i = 0; i < length; ++i) {
        bool result = FindElement(numbers[i]);
        cout << "result: " << result << endl;
    }
    
    
    /********************test two*************************/
    HashMap sample;
    vector<long> keys = {1, 2, 3, 4, 5, 6, 7, 8};
    char a[16] = "test";
    int length1 = int(keys.size());
    for (int i = 0; i < length1; ++i) {
        sample.insert(keys[i], a);
    }
    Node *res = sample.find(1);
    cout << res->key << " " << res->value << endl;
    
    
    for (int i = 0; i < 32; i++) {
        int8_t a = static_cast<int8_t>(
                 static_cast<int>((rand() / static_cast<float>(RAND_MAX)) * 255));
        cout << a << endl;
    }
    
    return 0;
}
开发者ID:senspace,项目名称:leetcode,代码行数:35,代码来源:mayi.cpp

示例3: CountMaxContinusSequence

int CountMaxContinusSequence(int a[], int n)
{
    int maxLeng = 0;

    for (int i = 0; i < n; ++i)
    {
        // ignore duplicated elements
        if (hashMap.find(a[i]) != hashMap.end())
        {
            continue;
        }

        hashMap.insert(std::make_pair(a[i], 1));

        if (hashMap.find(a[i] - 1) != hashMap.end())
        {
            maxLeng = Max(maxLeng, Merge(a[i] - 1, a[i]));
        }

        if (hashMap.find(a[i] + 1) != hashMap.end())
        {
            maxLeng = Max(maxLeng, Merge(a[i], a[i] + 1));
        }
    }

    return maxLeng;
}
开发者ID:conradhuang,项目名称:ProgrammingPractices,代码行数:27,代码来源:count_longest_continus_sequence.cpp

示例4: isValid_

	bool ConnectivityBase::isValid_(AtomContainer& ac)
	{
		static HashMap<Handle, PreciseTime> mod_times;
		PreciseTime last_mod = ac.getModificationTime(); 
		Handle mol_handle = ac.getHandle();
		if (mod_times.has(mol_handle))
		{
			if (mod_times[mol_handle] == last_mod)
			{
				#ifdef BALL_QSAR_CONNECTIVITYBASE_DEBUG
				cerr << ">> ConnectivityBase::isValid: molcule valid!" << endl;
				#endif
				return true;
			}
			else
			{
				mod_times[mol_handle] = last_mod;
				#ifdef BALL_QSAR_CONNECTIVITYBASE_DEBUG
				cerr << ">> ConnectivityBase::isValid: atom container not valid, modified!" << endl; 
				#endif
				return false;
			}
		}
		else
		{
			mod_times.insert(std::make_pair(mol_handle, last_mod));
			#ifdef BALL_QSAR_CONNECTIVITYBASE_DEBUG
			cerr << ">> ConnectivityBase::isValid: atom container not valid, first call!" << endl;
			#endif
			return false;
		}
	}
开发者ID:HeyJJ,项目名称:ball,代码行数:32,代码来源:connectivityBase.C

示例5: _Report_history

		virtual void _Report_history(std::shared_ptr<library::XML> xml)
		{
			library::UniqueWriteLock uk(system_array_->getMutex());

			//--------
			// CONSTRUCT HISTORY
			//--------
			std::shared_ptr<PRInvokeHistory> history(new PRInvokeHistory());
			history->construct(xml);

			// IF THE HISTORY IS NOT EXIST IN PROGRESS, THEN TERMINATE REPORTING
			auto progress_it = progress_list_.find(history->getUID());
			if (progress_it == progress_list_.end())
				return;

			// ARCHIVE FIRST AND LAST INDEX
			history->first_ = std::dynamic_pointer_cast<PRInvokeHistory>(progress_it->second.second)->getFirst();
			history->last_ = std::dynamic_pointer_cast<PRInvokeHistory>(progress_it->second.second)->getLast();

			// ERASE FROM ORDINARY PROGRESS AND MIGRATE TO THE HISTORY
			progress_list_.erase(progress_it);
			history_list_.insert({ history->getUID(), history });

			// NOTIFY TO THE MANAGER, SYSTEM_ARRAY
			((base::ParallelSystemArrayBase*)system_array_)->_Complete_history(history);
		};
开发者ID:betterwaysystems,项目名称:packer,代码行数:26,代码来源:ParallelSystem.hpp

示例6: _Reply_data

    virtual void _Reply_data(std::shared_ptr<protocol::Invoke> invoke) override final
    {
        if (invoke->has("_History_uid") == true)
        {
            // REGISTER THIS PROCESS ON HISTORY LIST
            std::shared_ptr<slave::InvokeHistory> history(new slave::InvokeHistory(invoke));
            progress_list_.insert({ history->getUID(), history });

            if (invoke->has("_Piece_first") == true)
            {
                // PARALLEL PROCESS
                size_t first = invoke->get("_Piece_first")->getValue<size_t>();
                size_t last = invoke->get("_Piece_last")->getValue<size_t>();

                invoke->erase(invoke->end() - 2, invoke->end());
                ((base::ParallelSystemArrayBase*)system_array_)->sendPieceData(invoke, first, last);
            }
            else if (invoke->has("_Process_name") == true)
            {
                // DISTRIBUTED PROCESS
                auto ds_system_array = (distributed::base::DistributedSystemArrayBase*)system_array_;

                // FIND THE MATCHED ROLE
                const std::string &process_name = invoke->get("_Process_name")->getValue<std::string>();
                if (ds_system_array->hasProcess(process_name) == false)
                    return;

                // SEND DATA VIA THE ROLE
                auto process = ds_system_array->getProcess(process_name);
                ((distributed::base::DistributedProcessBase*)(process.get()))->sendData(invoke, 1.0);
            }
        }
        else
            replyData(invoke);
    };
开发者ID:samchon,项目名称:framework,代码行数:35,代码来源:MediatorSystem.hpp

示例7: key

void
CirMgr::strash()
{
  HashMap<myStrashKey, CirGate*> myHash;

  for (size_t i = 0, dfsSize = _dfsOrder.size(); i < dfsSize; ++i)
  {
    CirGate* gate = _dfsOrder.at(i);

    if (gate->getTypeStr() != "AIG") {
      continue;
    }

    CirGate* existedGate = new Aig();
    myStrashKey key(gate);

    if (myHash.check(key, existedGate)) {
      cout << "Strashing: " << existedGate->getId() << " merging " << gate->getId() << "..." << endl;

      AigGateV newFanin(existedGate, 0);
      gate->connectFaninToEachFanout(newFanin);

      // clean up
      deleteAndCleanUpGate(gate);

      /* _dfsOrder.erase(_dfsOrder.begin() + i); */
      /* --i, --dfsSize; */
    } else {
      myHash.insert(key, gate);
    }
  }

  _dfsOrder.clear();
  topoSort();
}
开发者ID:lazywei,项目名称:dsnp_14_fall,代码行数:35,代码来源:cirFraig.cpp

示例8: main

int main() {
  HashMap<unsigned long, string> hmap;
  hmap.insert(2, "Harsh");
  string value;
  hmap.find(2, value);
  cout << value <<endl;
  cout <<"Hash table size is "<<hmap.size()<<endl;
  hmap.remove(2);
  hmap.find(2, value);
  cout <<"Hash table size is "<<hmap.size()<<endl;
}
开发者ID:LazyGetter,项目名称:codeless-code,代码行数:11,代码来源:hashTable.cpp

示例9:

void HashMap<K, T>::rehash(int i){
    HashMap<K, T>* t = new HashMap<K, T>(i);
    for(iterator it = this->begin(); it!=this->end(); ++it)
         t->insert(it->key, it->value);
    delete[] this->bucket;
    this->bucket = t->bucket;
    this->size = t->size;
    this->deleted_counter = 0;
    t->bucket=nullptr;
    delete t;
}
开发者ID:kameronton,项目名称:adamant,代码行数:11,代码来源:hash.cpp

示例10: main

int main()
{
	//freopen("in.txt","r",stdin);
	//freopen("out.txt","w",stdout);

	int n,m;
	long long val;
	int len;
	long long seed=13131313;
	long long base=1;
	bool ok;

	myh.init();

	scanf("%d %d",&n,&m);

	while(n--)
	{
		scanf("%s",s);
		myh.insert(myh.hash(s));
	}

	while(m--)
	{
		base=1;
		ok=0;
		scanf("%s",s);
		val=myh.hash(s);
		len=strlen(s);

		for(int i=len-1;i>=0;--i)
		{
			for(int j=0;j<3;++j)
				if(j!=s[i]-'a')
					if(myh.match(((val+base*(j-(s[i]-'a'))%MOD+MOD)%MOD)))
					{
						ok=1;
						break;
					}

			if(ok)
				break;

			base=(base*seed)%MOD;
		}

		if(ok)
			puts("YES");
		else
			puts("NO");
	}
	
	return 0;
}
开发者ID:Why-Why,项目名称:ACM-ICPC-Code,代码行数:54,代码来源:C_1.cpp

示例11:

// Test string version.
TEST(HashTest, STRINGHash) {				
	using namespace eoaix;				
	HashMap<std::string, TestKey> htable;			
	TestKey t1(1, "1str");					
	TestKey t2(2, "2str");					
	TestKey t4(4, "4str");					
	htable.insert(std::string("2"), t2);				
	htable.insert(std::string("1"), t1);				
	TestKey* t3 = htable.find_val(std::string("1"));	
	EXPECT_EQ(t3->toString(), t1.toString());	
	EXPECT_EQ(htable.contains(std::string("1")), true);	
	EXPECT_EQ(htable.contains(std::string("4")), false) << "htable.contains(t4) != true\n";	
}	
开发者ID:rt77789,项目名称:basic_tool_lib,代码行数:14,代码来源:test_hash.cpp

示例12: main

int main()
{
	ifstream cin("linkedmap.in");
	ofstream cout("linkedmap.out");

	string command, key;
	while (cin >> command >> key)
		if (command == "put")
		{
			string value;
			cin >> value;

			hashMap.insert(key, value);
		}
开发者ID:artemohanjanyan,项目名称:university,代码行数:14,代码来源:C.cpp

示例13:

	void calculateResidueChi2Angles
		(const Chain& fragment, HashMap<const Residue*,float>& residue_angles)
	{
		float angle = 0; //FLOAT_VALUE_NA;
		
		// extract all residues: iterate over all composites and
		// check whether they are Residues
		ResidueConstIterator	it = fragment.beginResidue();
		for (; +it; ++it)
		{
			angle =  calculateResidueChi2Angles(*it);
			residue_angles.insert(std::pair<const Residue*, float>(&*it, angle));
		}
	}
开发者ID:HeyJJ,项目名称:ball,代码行数:14,代码来源:NMRDescriptors.C

示例14: main

int main(int argc, const char * argv[]) {
    // insert code here...
    
    HashMap sample;
    vector<long> keys = {1, 2, 3, 4, 5, 6, 7, 8};
    char a[16] = "test";
    int length1 = int(keys.size());
    for (int i = 0; i < length1; ++i) {
        sample.insert(keys[i], a);
    }
    Node *res = sample.find(1);
    cout << res->key << " " << res->value << endl;
    
    return 0;
}
开发者ID:senspace,项目名称:leetcode,代码行数:15,代码来源:tesst.cpp

示例15: find_code

/* finds and inserts the full code in a hashmap */
HashMap::iterator find_code(Sym sym, HashMap& map) {
    HashMap::iterator result = map.find(sym);

    if (result == map.end()) { // new entry
	const SymVec& args = sym.args();
	vector<string> argstr(args.size());
	for (unsigned i = 0; i < args.size(); ++i) {
	    argstr[i] = find_code(args[i], map)->second;
	}

	// write out the code
	const FunDef& fun = get_element(sym.token());
	string code = fun.c_print(argstr, vector<string>());
	result = map.insert( make_pair(sym, code) ).first; // only want iterator
    }
    
    return result;
}
开发者ID:AdeleH,项目名称:paradiseo,代码行数:19,代码来源:sym_compile.cpp


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