Esempio n. 1
0
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;
}
Esempio n. 2
0
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;
}
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;
}
Esempio n. 4
0
	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;
		}
	}
Esempio n. 5
0
		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);
		};
Esempio n. 6
0
    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);
    };
Esempio n. 7
0
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();
}
Esempio n. 8
0
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;
}
Esempio n. 9
0
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;
}
Esempio n. 10
0
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;
}
Esempio n. 11
0
// 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";	
}	
Esempio n. 12
0
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);
		}
Esempio n. 13
0
	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));
		}
	}
Esempio n. 14
0
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;
}
Esempio n. 15
0
/* 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;
}
Esempio n. 16
0
TEST(HashTest, ObjectHash) {
	using namespace eoaix;
	HashMap<TestKey, TestKey> htable;

	TestKey t1(1, "1str");
	TestKey t2(2, "2str");
	TestKey t4(4, "4str");

	htable.insert(t1, t2);
	htable.insert(t2, t1);

	TestKey* t3 = htable.find_val(t1);
	
//	std::cout << t3->toString() << std::endl;
	//std::cout << t2.toString() << std::endl;
	EXPECT_EQ(t3->toString(), t2.toString());
	EXPECT_EQ(htable.contains(t1), true);
	EXPECT_EQ(htable.contains(t4), false) << "htable.contains(t4) != true\n";
}
Esempio n. 17
0
HashMap::iterator find_entry(const Sym& sym, string& str, 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_entry(args[i], str, map)->second;
	}

	string var = make_var(map.size()); // map.size(): unique id
	string code;	
	// write out the code
	const FunDef& fun = get_element(sym.token());
	code = fun.c_print(argstr, vector<string>() );
	    
	str += "double " + var + "=" + code + ";\n";
	result = map.insert( make_pair(sym, var ) ).first; // only want iterator
    }
    
    return result;
}
Esempio n. 18
0
//the functions for both procedures...
//--------------------1.get word-list---------------------------
HashMap *load_wordlist(const char *fname)
{
	//lists of the vocabularies
	cout << "---Opening vocab file '" << fname << "'" << endl;
	ifstream ifs;
	ifs.open(fname,ios::in);
	CHECK_FILE(ifs,fname);
	int num=0;
	HashMap *res = new HashMap(CONS_vocab_map_size);
	while (!ifs.eof()){
		string buf;
		ifs >> buf;
		if (buf=="") continue; // HACK
		string* tmp = new string(buf);
		res->insert(pair<string*, int>(tmp, num++));
	}
	if(res->size() != num){
		//sth wrong
		Error("Something wrong with vocab file.");
	}
	cout << "---Done with loading vocab, all is " << num << endl;
	return res;
}
Esempio n. 19
0
	void hashMap() {
		HashMap<String, String> m;

		//insert
		assert("HashMap::insert()", m.insert("foo", "F00").second);
		assert("HashMap::insert()", m.insert("bar", "B4R").second);
		assert("HashMap::insert()", m.insert("baz", "B4Z").second);
		assert("HashMap::size()", m.size() == 3);

		//dupe insert
		Pair<HashMap<String, String>::Iterator, bool> res = m.insert("foo", "whatev");
		assert("HashMap::insert()", !res.second);
		assert("HashMap::insert()", res.first != m.end());
		assert("HashMap::insert()", res.first->first == "foo");
		assert("HashMap::insert()", res.first->second == "F00");

		//find
		HashMap<String, String>::Iterator itr = m.find("bar");
		assert("HashMap::find()", itr != m.end());
		assert("HashMap::find()", itr->first == "bar");
		assert("HashMap::find()", itr->second == "B4R");

		//iterate
		itr = m.begin();
		assert("HashMap::begin()", itr != m.end());
		++itr;
		itr++;
		++itr;
		assert("HashMap::Iterator", itr == m.end());

		//const iterator
		HashMap<String, String>::ConstIterator citr = m.find("baz");
		assert("cHashMap::find()", citr != m.end());
		assert("cHashMap::find()", citr->first == "baz");
		assert("cHashMap::find()", citr->second == "B4Z");

		citr = m.begin();
		assert("cHashMap::begin()", citr != m.end());
		++citr;
		citr++;
		++citr;
		assert("cHashMap::Iterator", citr == m.end());

		//erase
		assert("HashMap::erase()", m.erase("bar"));
		assert("HashMap::erase()", m.size() == 2);

		//copy constuctor
		HashMap<String, String> copy(m);
		assert("HashMap::HashMap(HashMap)", copy.size() == 2);
		
		//erase by iterator
		m.erase(m.find("baz"));
		assert("HashMap::erase(Iterator)", m.size() == 1);

		//clear
		m.clear();
		assert("HashMap::clear()", m.size() == 0);
		itr = m.find("baz");
		assert("HashMap::clear()", itr == m.end());
		assert("HashMap::clear()", m.begin() == m.end());

		//assignment operator
		m = copy;
		assert("HashMap::operator=", m.size() == 2);
		
		//square bracket operator
		m["norg"] = "N07G";
		assert("HashMap::operator[]", m["foo"] == "F00");
	}
Esempio n. 20
0
    void insertDfaOrigins(DfaVertex* dfaStatep) {
	// Record the NFA states this dfa came from
	uint32_t hash = hashDfaOrigins(dfaStatep);
	m_hashMap.insert(make_pair(hash,dfaStatep));
    }
Esempio n. 21
0
bool SplitStrByIpay(const char *pcstr, UINT size, HashMap<UINT, std::string> & strList)
{
	const char *pcend = pcstr + size;
	if (strncmp(pcstr, TRANS_BEGIN, TRANS_COUNT) == 0)
	{
		pcstr += TRANS_COUNT;
	}
	while (pcstr < pcend)
	{
		while ((*pcstr == '"' || *pcstr == ',' || *pcstr=='{') && pcstr < pcend)
			++pcstr;
		//key;
		string key, value;
		const char *ps = pcstr;
		while (ps < pcend)
		{
			if (*ps == '"')
				break;
			else
				++ps;
		}
		if (*ps != '"')
			break;

		key.append(pcstr, ps - pcstr);

		//value;
		pcstr = ps + 2;
		if (*pcstr == '"')
			++pcstr;
		if (pcstr >= pcend)
			break;
		ps = pcstr;
		while (ps < pcend)
		{
			if (*ps == '"' || *ps == ',' || *ps == '}')
				break;
			else
				++ps;
		}
		if (ps == pcend)
			break;
		value.append(pcstr, ps - pcstr);

		//Log("Key:%s, Value:%s", key.c_str(), value.c_str());
		for (UINT i = 0; i < key.size(); ++i)
			((char*)key.c_str())[i] = ::tolower(key.c_str()[i]);
		UINT crc = AECrc32(key.c_str(), key.size(), 0);
		strList.insert(make_pair(crc, value));
		pcstr = ps;
		if (*pcstr == '}')
		{
			++pcstr;
			break;
		}
	}
	while (*pcstr == '}' || *pcstr == '&')
		++pcstr;
	if (pcstr < pcend && strncmp(pcstr, SIGN_STR, SIGN_COUNT) == 0)
	{
		pcstr += SIGN_COUNT;
		if (pcstr >= pcend)
			return false;
		const char *ps = strchr(pcstr, '&');
		if (ps < pcend)
		{
			string value;
			value.append(pcstr, ps - pcstr);
			//Log("Key:sign, Value:%s", value.c_str());
			strList.insert(make_pair(SIGN_CRC, value));
		}
	}
	return true;
}
Esempio n. 22
0
int main(int argc, char **argv)
{
  size_t nkeys = (1 << 16);
  size_t nlookup = 100000;
  double lf = 0.75;
  
  if (argc >= 2)
  {
    int n;
    if (sscanf(argv[1], "%d", &n) == 1)
    {
      std::cout << "Use " << n << " keys" << std::endl;
      nkeys = size_t(n);
    }
  }
  if (argc >= 3)
  {
    int l;
    if (sscanf(argv[2], "%d", &l) == 1)
    {
      std::cout << "Do " << l << " lookups" << std::endl;
      nlookup = size_t(l);
    }
  }
  if (argc >= 4)
  {
    double d;
    if (sscanf(argv[3], "%lf", &d) == 1)
    {
      std::cout << "Use max load factor: " << d << std::endl;
      lf = d;
    }
  }
  
  size_t ndups = 0;
  std::cout << "Testing insertion and search with " << nkeys << " keys" << std::endl;
  
  HashMap<std::string, std::string> hmap;
  
  hmap.setMaxLoadFactor(lf);
  
  std::vector<std::string> allKeys;
  
  allKeys.resize(nkeys);
  
  for (size_t i=0; i<nkeys; ++i)
  {
    std::string s = RandomString();
    allKeys[i] = s;
    if (!hmap.insert(s, s))
    {
      std::cout << "Duplicate key found: \""  << s << "\"" << std::endl;
      ++ndups;
    }
  }
  
  std::cout << hmap.size() << " entries (" << ndups << " keys were duplicate)" << std::endl;
  std::cout << "Load Factor of " << hmap.loadFactor() << std::endl;
  
  for (size_t i=0; i<nkeys; ++i)
  {
    size_t ik = rand() % nkeys;
    const std::string &k = allKeys[ik];
    const std::string &v = hmap[k];
    if (v != k)
    {
      throw std::runtime_error("key/value mistmatch");
    }
  }
  
  HashMap<std::string, std::string>::KeyVector keys;
  HashMap<std::string, std::string>::ValueVector vals;
  
  hmap.keys(keys);
  hmap.values(vals);
  
  assert(hmap.size() == keys.size());
  assert(hmap.size() == vals.size());
  
  for (size_t i=0; i<hmap.size(); ++i)
  {
    if (keys[i] != vals[i])
    {
      throw std::runtime_error("key/value pair mismatch");
    }
  }
  
  {
    HashMap<std::string, std::string> hmap;
    std::map<std::string, std::string> smap;
    size_t numhits = 0;
    
    hmap.setMaxLoadFactor(lf);
    
    std::vector<std::string> allKeys, extraKeys;
    std::string val;
    
    allKeys.resize(nkeys);
    extraKeys.resize(nkeys);
    
    for (size_t i=0; i<nkeys; ++i)
    {
      allKeys[i] = RandomString();
      extraKeys[i] = RandomString();
    }
    
    clock_t st, et;
    
    std::cout << "Insert " << nkeys << " values in HashMap...";
    st = clock();
    for (size_t i=0; i<nkeys; ++i)
    {
      std::string &s = allKeys[i];
      hmap.insert(s, s);
    }
    et = clock();
    std::cout << double(et - st) / CLOCKS_PER_SEC << "(s)" << std::endl;
    
    std::cout << "Do " << nlookup << " random access in HashMap ";
    HashMap<std::string, std::string>::iterator hit;
    st = clock();
    numhits = 0;
    for (size_t i=0; i<nlookup; ++i)
    {
      int keyi = RandomNumber(0, int(nkeys)-1);
      std::string &k = (RandomNumber(0, 1) == 0 ? allKeys[keyi] : extraKeys[keyi]);
      hit = hmap.find(k);
      if (hit != hmap.end())
      {
        ++numhits;
        val = hit.value();
      }
    }
    et = clock();
    std::cout << double(et - st) / CLOCKS_PER_SEC << "(s) [" << numhits << " hit(s)]" << std::endl;
    
    std::cout << "Insert " << nkeys << " values in std::map...";
    st = clock();
    for (size_t i=0; i<nkeys; ++i)
    {
      std::string &s = allKeys[i];
      smap[s] = s;
    }
    et = clock();
    std::cout << double(et - st) / CLOCKS_PER_SEC << "(s)" << std::endl;
    
    std::cout << "Do " << nlookup << " random access in std::map ";
    std::map<std::string, std::string>::iterator it;
    st = clock();
    numhits = 0;
    for (size_t i=0; i<nlookup; ++i)
    {
      int keyi = RandomNumber(0, int(nkeys)-1);
      std::string &k = (RandomNumber(0, 1) == 0 ? allKeys[keyi] : extraKeys[keyi]);
      it = smap.find(k);
      if (it != smap.end())
      {
        ++numhits;
        val = it->second;
      }
    }
    et = clock();
    std::cout << double(et - st) / CLOCKS_PER_SEC << "(s) [" << numhits << " hit(s)]" << std::endl;
    
    
    std::cout << "Check HashMap consistency... ";
    bool consistent = true;
    for (size_t i=0; i<nkeys; ++i)
    {
      int keyi = RandomNumber(0, int(nkeys)-1);
      std::string &k = (RandomNumber(0, 1) == 0 ? allKeys[keyi] : extraKeys[keyi]);
      hit = hmap.find(k);
      it = smap.find(k);
      if (it == smap.end())
      {
        if (hit != hmap.end())
        {
          consistent = false;
          break;
        }
      }
      else
      {
        if (hit == hmap.end())
        {
          consistent = false;
          break;
        }
        if (hit.value() != it->second)
        {
          consistent = false;
          break;
        }
      }
    }
    std::cout << (consistent ? "Yes" : "No") << std::endl;
    
    if (hmap.size() <= 100)
    {
      HashMap<std::string, std::string>::const_iterator cit = hmap.begin();
      while (cit != hmap.end())
      {
        std::cout << cit.key() << " => " << cit.value() << std::endl;
        ++cit;
      }
    }
  }
  
  return 0;
}
Esempio n. 23
0
void HaggleKernel::log_eventQueue(Metadata *m) {

	HashMap<string, size_t> counts;
	HashMap<string, size_t>::iterator cit;
	Heap theHeap;

	Metadata *dm = m->addMetadata("Events");
	if (!dm) {
		return;
	}

	List<Event *> list = getEventList();
	for (List<Event *>::iterator it = list.begin(); it != list.end(); it++) {
		Event *e = *it;
		theHeap.insert(*it);

		cit = counts.find(e->getName());
		if (cit == counts.end()) {
			counts.insert(make_pair(e->getName(), 1));
		} else {
			size_t count = (*cit).second;
			counts.erase(cit);
			counts.insert(make_pair(e->getName(), count+1));
		}
	}

	for (size_t i = 0; i < list.size(); i++) {

		Event *e = static_cast<Event *>(theHeap.extractFirst());

		if (e) {
			if (i < 200) {
				Metadata *dmm = dm->addMetadata("Event");
				dmm->setParameter("name", e->getName());
				dmm->setParameter("time", e->getTimeout().getAsString());
				dmm->setParameter("canceled", e->isCanceled() ? "true" : "false");
				
				if (e->getDataObject()) {
					dmm->setParameter("dObj", e->getDataObject()->getIdStr());
				}
				if (e->getNode()) {
					dmm->setParameter("node", e->getNode()->getIdStr());
				}
				if (e->getInterface()) {
					dmm->setParameter("iface", e->getInterface()->getIdentifierStr());
				}
				if (e->getNodeList().size() > 0) {
					dmm->setParameter("nodeListSize", e->getNodeList().size());
				}
				if (e->getDataObjectList().size() > 0) {
					dmm->setParameter("dataObjectListSize", e->getDataObjectList().size());
				}

				if (strcmp(e->getName(), "BFRemoveDelay") == 0) {
					const DataObjectId_t *id = (DataObjectId_t *) e->getData();
					if (id) {
						dmm->setParameter("dObj", DataObject::idString(*id));
					}
				}
			}

			delete e;
		}
	}

	dm = m->addMetadata("Counts");
	if (!dm) {
		return;
	}

	for (cit = counts.begin(); cit != counts.end(); cit++) {
		Metadata *dmm = dm->addMetadata("Event");

		if (dmm) {
			dmm->setParameter("name", (*cit).first);
			dmm->setParameter("count", (*cit).second);
		}
	}

}
Esempio n. 24
0
	void hashMapInt() {
		HashMap<int, int> m;

		//insert
		assert("HashMap::insert()", m.insert(2, 5).second);
		assert("HashMap::insert()", m.insert(3, 6).second);
		assert("HashMap::insert()", m.insert(4, 7).second);
		assert("HashMap::size()", m.size() == 3);

		//dupe insert
		Pair<HashMap<int, int>::Iterator, bool> res = m.insert(4, 8);
		assert("HashMap::insert()", !res.second);
		assert("HashMap::insert()", res.first != m.end());
		assert("HashMap::insert()", res.first->first == 4);
		assert("HashMap::insert()", res.first->second == 7);

		//find
		HashMap<int, int>::Iterator itr = m.find(3);
		assert("HashMap::find()", itr != m.end());
		assert("HashMap::find()", itr->first == 3);
		assert("HashMap::find()", itr->second == 6);

		//iterate
		itr = m.begin();
		assert("HashMap::begin()", itr != m.end());
		++itr;
		itr++;
		++itr;
		assert("HashMap::Iterator", itr == m.end());

		//const iterator
		HashMap<int, int>::ConstIterator citr = m.find(2);
		assert("cHashMap::find()", citr != m.end());
		assert("cHashMap::find()", citr->first == 2);
		assert("cHashMap::find()", citr->second == 5);

		citr = m.begin();
		assert("cHashMap::begin()", citr != m.end());
		++citr;
		citr++;
		++citr;
		assert("cHashMap::Iterator", citr == m.end());

		//erase
		assert("HashMap::erase()", m.erase(3));
		assert("HashMap::erase()", m.size() == 2);

		//copy constuctor
		HashMap<int, int> copy(m);
		assert("HashMap::HashMap(HashMap)", copy.size() == 2);
		
		//erase by iterator
		m.erase(m.find(2));
		assert("HashMap::erase(Iterator)", m.size() == 1);

		//clear
		m.clear();
		assert("HashMap::clear()", m.size() == 0);
		itr = m.find(4);
		assert("HashMap::clear()", itr == m.end());
		assert("HashMap::clear()", m.begin() == m.end());

		//assignment operator
		m = copy;
		assert("HashMap::operator=", m.size() == 2);
		
		//square bracket operator
		m[9] = 10;
		assert("HashMap::operator[]", m[2] == 5);
	}
Esempio n. 25
0
#include "catch.hpp"
#include "hashmap.hpp"
#include "bucketmap.hpp"
#include "hashmap_enhanced.cpp"
#include "bucketmap_enhanced.cpp"
#include "rbst.cpp"

TEST_CASE ( "Testing hashmap", "[HashMap]" ) {
    HashMap map(5);
    SECTION ( "Test insert method", "[insert]" ) {
        map.insert( 1,  'a' );
        map.insert( 6,  'f' );
        map.insert( 11, 'k' );
        map.insert( 2,  'b' );
        map.insert( 45,  'd' );
        bool failed = map.insert( 72,  'r' );
        REQUIRE( failed == false );
        char val;
        map.print(std::cout);
        REQUIRE( map.search(1, val) == true );
        REQUIRE( val == 'a' );
        REQUIRE( map.search(2, val) == true );
        REQUIRE( val == 'b' );
        std::cout << std::endl;
        map.remove(6 , val);
        REQUIRE( val == 'f' );
        map.print(std::cout);
        std::cout << std::endl;
        REQUIRE( map.isEmpty() == false );
        map.clear();
        REQUIRE( map.isEmpty() == true );