Ejemplo n.º 1
0
Archivo: map.hpp Proyecto: crafn/clover
MultiMap<V, K, C2> flippedMap(const Map<K, V, C1>& map){
	MultiMap<V, K, C2> flipped;
	for (const auto& pair : map){
		flipped.emplace(pair.second, pair.first);
	}
	return flipped;
}
Ejemplo n.º 2
0
void ServiceManager::sendNotification(int msg, int param1, int param2) {
  cs.enter();
  for (int x = 0; x < services.multiGetNumPairs(); x++) {
    for (int y = 0; ; y++) {
      waServiceFactory *svc;
      if (!services.multiGetItemDirect(x, y, &svc)) {
        break;
      }
      svc->serviceNotify(msg, param1, param2);
    }
  }
  cs.leave();
#ifdef WASABI_COMPILE_COMPONENTS
  // also notify components
  for (int i = 0; ; i++) {
    WaComponent *wac = ComponentManager::enumComponent(i);
    if (wac == NULL) break;
    wac->onNotify(WAC_NOTIFY_SERVICE_NOTIFY, msg, param1, param2);
  }
#endif
#ifdef WASABI_COMPILE_SYSCB
  // and syscallbacks
  CallbackManager::issueCallback(SysCallback::RUNLEVEL, msg);
#endif
}
Ejemplo n.º 3
0
int ServiceManager::registerService(waServiceFactory *service, GUID owner) {
  ASSERT(owner != INVALID_GUID);
  if (owner == INVALID_GUID) return 0;
  GUID svctype = GetServiceTypeL(service);
  cs.enter();
  if (!services.multiHaveItem(svctype, service)) {
    services.multiAddItem(svctype, service);

    ownermap.addItem(service, owner);

    GUID svcguid = service->getGuid();
    if (svcguid != INVALID_GUID) services_by_guid.addItem(svcguid, service);
  }
  cs.leave();

  service->serviceNotify(SvcNotify::ONREGISTERED);

#ifdef WASABI_COMPILE_SYSCB
  CallbackManager::issueCallback(SysCallback::SERVICE,
    SvcCallback::ONREGISTER,
    reinterpret_cast<long>(&svctype), reinterpret_cast<long>(service));
#endif

  return 1;
}
void PrintEqualProduct(int num) {

    typedef unordered_multimap<int, pair<int, int> > MultiMap;
    typedef unordered_map<int, int> ProductMap;
    MultiMap resultMap;
    ProductMap productMap;

    for (int i = 1; i <= num; ++i) {

        for (int j = 1; j <= num; ++j) {
        
            resultMap.insert( MultiMap::value_type(i*j, pair<int,int>(i, j)) );
            productMap.insert( pair<int,int>(i*j,i*j) );
        }

	}
    pair<MultiMap::const_iterator, MultiMap::const_iterator> eqRange;
    MultiMap::const_iterator it1;
    MultiMap::const_iterator it2;
    ProductMap::const_iterator it;

    for (it = productMap.begin(); it != productMap.end(); ++it) {

            eqRange = resultMap.equal_range(it->second);  //search value i*j in resultMap first element, return a range pairs 

            for (it1 = eqRange.first; it1 != eqRange.second; ++it1) {

                for (it2 = eqRange.first; it2 != eqRange.second; ++it2) {

                    cout<< it1->second.first <<" * "<<it1->second.second<<" = "<< it2->second.first <<" * "<<it2->second.second <<endl;
                }
            }
    }

}
 void lockThread(util::ThreadArgs& args) {
     MultiMap<std::string, std::string> *mm = (MultiMap<std::string, std::string> *)args.arg0;
     util::CountDownLatch *latch = (util::CountDownLatch *)args.arg1;
     if (!mm->tryLock("key1")) {
         latch->countDown();
     }
 }
 void tryLockThread2(util::ThreadArgs& args) {
     MultiMap<std::string, std::string> *mm = (MultiMap<std::string, std::string> *)args.arg0;
     util::CountDownLatch *latch = (util::CountDownLatch *)args.arg1;
     try {
         if (mm->tryLock("key1", 20 * 1000)) {
             latch->countDown();
         }
     } catch (...) {
         std::cerr << "Unexpected exception at ClientMultiMapTest lockThread2" << std::endl;
     }
 }
Ejemplo n.º 7
0
int main(){
	MultiMap mmap = MultiMap();
	mmap.set("key1",5);
	mmap.set("key2", 4);
	mmap.set("key2",7);
	mmap.set("key1",9);
	mmap.printMap();
	cout<< "After removeAll"<<endl;
	mmap.removeAll("key1");
	mmap.printMap();

	cout<< "Count 'key2': "<< mmap.count("key2")<<endl;
	cout<< "getAll Function output: ";
	mmap.getAll("key2")->display();
}
Ejemplo n.º 8
0
void xRenderSettingPane::Show(bool b)
{
	m_wndPropList.RemoveAll();

	if (!b)
		return ;

	IPropertyObj * obj = xRenderSetting::Instance();

	int propSize = obj->GetPropertySize();

	MultiMap<TString128, const Property *> mmap;

	for (int i = 0; i < propSize; ++i)
	{
		const Property * p = obj->GetProperty(i);
		mmap.Insert(p->group, p);
	}

	MultiMap<TString128, const Property *>::Iterator whr = mmap.Begin();
	MultiMap<TString128, const Property *>::Iterator end = mmap.End();

	while (whr != end)
	{
		CMFCPropertyGridProperty * gp = new CMFCPropertyGridProperty(whr->first.c_str());

		List<const Property *>::Iterator w = whr->second.Begin();
		List<const Property *>::Iterator e = whr->second.End();

		while (w != e)
		{
			const Property * p = *w;

			_ToCtrl(gp, obj, p);

			++w;
		}

		m_wndPropList.AddProperty(gp);

		++whr;
	}
}
                void putGetRemoveTestThread(util::ThreadArgs& args) {
                    MultiMap<std::string, std::string> *mm = (MultiMap<std::string, std::string > *)args.arg0;
                    HazelcastClient *client = (HazelcastClient *)args.arg1;
                    util::CountDownLatch *latch = (util::CountDownLatch *)args.arg2;
                    std::string key = util::IOUtil::to_string(util::Thread::getThreadID());
                    client->getMultiMap<std::string, std::string>("testPutGetRemove").put(key, "value");
                    TransactionContext context = client->newTransactionContext();
                    context.beginTransaction();
                    TransactionalMultiMap<std::string, std::string> originalMultiMap = context.getMultiMap<std::string, std::string >("testPutGetRemove");
                    client::adaptor::RawPointerTransactionalMultiMap<std::string, std::string> multiMap(originalMultiMap);
                    ASSERT_FALSE(multiMap.put(key, "value"));
                    ASSERT_TRUE(multiMap.put(key, "value1"));
                    ASSERT_TRUE(multiMap.put(key, "value2"));
                    ASSERT_EQ(3, (int)multiMap.get(key)->size());
                    context.commitTransaction();

                    ASSERT_EQ(3, (int)mm->get(key).size());

                    latch->countDown();
                }
Ejemplo n.º 10
0
void xEnvironmentPane::_Frush(CMFCPropertyGridCtrl & PropertyGrid, IPropertyObj * obj)
{
	PropertyGrid.RemoveAll();

	if (!obj)
		return ;

	int propSize = obj->GetPropertySize();

	MultiMap<TString128, const Property *> mmap;

	for (int i = 0; i < propSize; ++i)
	{
		const Property * p = obj->GetProperty(i);
		mmap.Insert(p->group, p);
	}

	MultiMap<TString128, const Property *>::Iterator whr = mmap.Begin();
	MultiMap<TString128, const Property *>::Iterator end = mmap.End();

	while (whr != end)
	{
		CMFCPropertyGridProperty * gp = new CMFCPropertyGridProperty(whr->first.c_str());

		List<const Property *>::Iterator w = whr->second.Begin();
		List<const Property *>::Iterator e = whr->second.End();

		while (w != e)
		{
			const Property * p = *w;

			_ToCtrl(gp, obj, p);

			++w;
		}

		PropertyGrid.AddProperty(gp);

		++whr;
	}
}
Ejemplo n.º 11
0
int ServiceManager::deregisterService(waServiceFactory *service, int internal) {
  GUID svctype = GetServiceTypeL(service);
  // make sure it was there
  cs.enter();
  if (services.multiHaveItem(svctype, service)) {
    // make sure there aren't still services issued by this guy
    //  ASSERT(internal || !lockmap.reverseGetItem(service));
    services.multiDelItem(svctype, service);
    ownermap.delItem(service);
    services_by_guid.reverseDelItem(service);
  }
  cs.leave();
  service->serviceNotify(SvcNotify::ONDEREGISTERED);

#ifdef WASABI_COMPILE_SYSCB
  CallbackManager::issueCallback(SysCallback::SERVICE,
    SvcCallback::ONDEREGISTER,
    reinterpret_cast<long>(&svctype), reinterpret_cast<long>(service));
#endif

  return 1;
}
Ejemplo n.º 12
0
void ServiceManager::onShutdown() {
  /*
  ownermap.purge();
  services.purge();
  services_by_guid.purge();
  clientmap.purge();
  */

  int nlocks = lockmap.getNumPairs();
  if (nlocks <= 0) {
    //lockmap.purge();
#ifdef GEN_FF // i need this to have clean session restart, feel free to remove the ifdef if you fgeel that should always be done
    ownermap.deleteAll();
    services.multiRemoveAll();
    services_by_guid.deleteAll();
    lockmap.deleteAll();
#endif
    return;
  }

#ifndef _DEBUG
  DebugString("-----------------\n");
  for (int i = 0; i < nlocks; i++) {
    void *ptr = lockmap.enumIndexByPos(i, NULL); ASSERT(ptr != NULL);
    StringPrintf s("lock: %d type:'", (int)ptr);

    //    GUID g = lockermap.enumItemByPos(i, INVALID_GUID);ASSERT(g != INVALID_GUID);
    //    s += g;
    //    WaComponent *wac = ComponentManager::getComponentFromGuid(g);

    waServiceFactory *was=NULL;
    was = lockmap.enumItemByPos(i, NULL);
    ASSERT(was != NULL);
    GUID type = safe_getServiceType(was);
    const char *tname = ServiceManager::getServiceTypeName(type);
    if (tname != NULL) {
      s += tname;
    } else {
      /*
      FOURCC v = BSWAP(type);
      unsigned char bleh[5]="    ";
      MEMCPY(bleh, &v, 4);
      s += String((char *)bleh);
      */
      s += Guid(type).toChar();
    }
    s += "' from service:'";
    s += safe_getServiceName(was);

    //    s += " wac:";
    //    if (wac) s += wac->getName();
#ifdef WASABI_COMPILE_COMPONENTS
    s += "' owned by:'";

    GUID g = INVALID_GUID;
    ownermap.getItem(was, &g);
    if (g != INVALID_GUID) {
      s += g;
      WaComponent *wac = ComponentManager::getComponentFromGuid(g);
      if (wac) s += wac->getName();
    } else s += "(unregistered)";
#else
    GUID g;
#endif

    s += "' registered lock to '";
    g = INVALID_GUID;
    //clientmap.getItem(ptr, &g);
    s += g;

    s += "'\n";
    DebugString(s.v());
  }
  DebugString("-----------------\n");
#endif
#ifdef GEN_FF // i need this to have clean session restart, feel free to remove the ifdef if you fgeel that should always be done
  ownermap.deleteAll();
  services.multiRemoveAll();
  services_by_guid.deleteAll();
  lockmap.deleteAll();
#endif
}
Ejemplo n.º 13
0
int main()
{
	MultiMap<int, int> m;

	m[1] = 10;
	m[1] += 20;
	m[1] += 20;
	m[2] = 30;
	m[2] += 30;
	m[3] = 40;
	m[2] = 40;
	m.erase(3);
	m.erase(1, 20);
	m.erase(2, 123);

	cout << m[1].getValueCount() << endl;
	cout << m[2].getValueCount() << endl;
	cout << m[3].getValueCount() << endl;
	return 0;

	for (int i = 0; i < 100; ++i) {
		int n = rand() % 1000000;
		if (rand() % 2 == 1) {
			cout << "Insert " << n << endl;
			m.insert(n, i % 100);
		} else {
			cout << "Erase Value" << endl;
			m[rand() % 1000000].eraseValue();
		}
	}
//	sleep(100);
	return 0;
	
	for (int i = 0; i < 20; ++i) {
		int n = rand() % 10;
		cout << "inserted: " << n << ", " << i << endl;
		m.insert(n, i);
	}
	for (int i = 0; i < 20; ++i) {
		cout << "inserted: " << i << ", " << i << endl;
		m.insert(i, i);
	}
	

	cout << "insertion completed" << endl;

	ConstCursor<int, int> cx = m[2];

	cout << cx.keyOk() << endl;
	cout << cx.valueOk() << endl;
	cout << cx.getKey() << endl;
	cout << cx.getKeyCount() << endl;
	cout << cx.getValue() << endl;
	cout << cx.getValueCount() << endl;
	cout << m[2].getKey() << " (" << m[2].getKeyCount() << ")" << endl;
	cout << m[2].getKey() << " (" << m[2].getKeyCount() << ")" << endl;
	cout << m[2].getKey() << " (" << m[2].getKeyCount() << ")" << endl;
	cout << "array access completed" << endl;

	m[2].insertValue(8);
	m[2].insertValue(7);
	m[2].insertValue(8);
	m[2][7].eraseValue();

	m[7].eraseKey();

	MultiMap<int, int> n = m;
	
	Cursor<int, int> csr(&n);
	while (csr.keyOk()) {
		cout << csr.getKey() << " (" << csr.getKeyCount() << "): ";
		while (csr.valueOk()) {
			cout << csr.getValue() << " [" << csr.getValueCount() << "] ";
			csr.nextValue();
		}
		cout << endl;
		
		csr.nextKey();
	}
	
}
Ejemplo n.º 14
0
bool Hdf5Dataset::getMultimap(MultiMap &mMap)
{
  hsize_t dims_out[2], count[2], offset[2];
  hid_t dataspace = H5Dget_space(this->poses_dataset_); /* dataspace handle */
  int rank = H5Sget_simple_extent_ndims(dataspace);
  herr_t status_n = H5Sget_simple_extent_dims(dataspace, dims_out, NULL);
  herr_t status;
  int chunk_size, chunk_itr;
  if (dims_out[0] % 10)
  {
    chunk_itr = 11;
  }
  else
  {
    chunk_itr = 10;
  }
  chunk_size = (dims_out[0] / 10);
  offset[0] = 0;

  for (int it = 0; it < chunk_itr; it++)
  {
    offset[1] = 0;
    if ((dims_out[0] - (chunk_size * it)) / chunk_size != 0)
    {
      count[0] = chunk_size;
      offset[0] = chunk_size * it;
    }
    else
    {
      count[0] = (dims_out[0] - (chunk_size * it));
      offset[0] = count[0];
    }
    count[1] = 10;

    double data_out[count[0]][count[1]];

    status = H5Sselect_hyperslab(dataspace, H5S_SELECT_SET, offset, NULL, count, NULL);
    hsize_t dimsm[2];
    dimsm[0] = count[0];
    dimsm[1] = count[1];
    hid_t memspace;
    memspace = H5Screate_simple(RANK_OUT, dimsm, NULL);
    status = H5Dread(this->poses_dataset_, H5T_NATIVE_DOUBLE, memspace, dataspace, H5P_DEFAULT, data_out);

    for(int i=0; i<count[0]; i++)
    {
      std::vector<double> sphere_center(3);
      std::vector<double> Poses(7);
      for(int j=0; j<3;j++)
      {
        sphere_center[j] = data_out[i][j];
        }
      for(int k=3;k<10; k++)
      {
        Poses[k-3] = data_out[i][k];
        }
      mMap.insert(std::make_pair(sphere_center, Poses));
      }
  }
return 0;
}
Ejemplo n.º 15
0
int ServiceManager::isValidService(GUID svctype, waServiceFactory *service) {
  INCRITICALSECTION(cs);
  return services.multiHaveItem(svctype, service);
}
Ejemplo n.º 16
0
int main()
{
	/*Database db;
	db.loadFromURL("http://cs.ucla.edu/classes/winter14/cs32/Projects/4/Data/census.csv");
*/
	MultiMap m;
	m.insert("D", 8);
	m.insert("B", 4);
	m.insert("F", 12);
	m.insert("A", 1);
	m.insert("C", 5);
	m.insert("E", 9);
	m.insert("G", 13);
	m.insert("A", 2);
	m.insert("C", 6);
	m.insert("E", 10);
	m.insert("G", 14);
	m.insert("A", 3);
	m.insert("C", 7);
	m.insert("E", 11);
	m.insert("G", 15);

	MultiMap::Iterator c(m.findEqual("D"));
	assert(c.valid());
	MultiMap::Iterator d;
	for (; c.valid(); c.prev())
		d = c;
	for (; d.valid(); d.next())
		cout << d.getKey() << " " << d.getValue() << endl;

	cout << endl;

	MultiMap::Iterator a(m.findEqual("D"));
	assert(a.valid());
	MultiMap::Iterator b;
	for (; a.valid(); a.next())
		b = a;
	for (; b.valid(); b.prev())
		cout << b.getKey() << " " << b.getValue() << endl;

	MultiMap::Iterator t;
	t = m.findEqual("A");
	if (t.valid())
	{
		cout << endl;
		cout << t.getKey() << " " << t.getValue() << endl;
		t.next();
		cout << t.getKey() << " " << t.getValue() << endl;
		t.next();
		cout << t.getKey() << " " << t.getValue() << endl;
	}
	t = m.findEqualOrSuccessor("Fz");
	if (t.valid())
	{
		cout << endl;
		cout << t.getKey() << " " << t.getValue() << endl;
		t.next();
		cout << t.getKey() << " " << t.getValue() << endl;
		t.next();
		cout << t.getKey() << " " << t.getValue() << endl;
	}
	t = m.findEqualOrPredecessor("E");
	t.next();
	MultiMap::Iterator after = t;
	t.next();
	MultiMap::Iterator afterafter = t;
	t.prev();
	t.prev();
	if (t.valid() && after.valid() && afterafter.valid())
	{
		cout << endl;
		cout << t.getKey() << " " << t.getValue() << endl;
		t.next();
		cout << t.getKey() << " " << t.getValue() << endl;
		t.next();
		cout << t.getKey() << " " << t.getValue() << endl;
	}

	Database database;

	Database::FieldDescriptor fd1, fd2, fd3;

	fd1.name = "username";
	fd1.index = Database::it_indexed;	//	username	is	an	indexed	field	

	fd2.name = "phonenum";
	fd2.index = Database::it_indexed;	//	phone	#	is	an	indexed	field	

	fd3.name = "age";
	fd3.index = Database::it_none;	//	age	is	NOT	an	indexed	field	

	std::vector<Database::FieldDescriptor>	schema;
	schema.push_back(fd1);
	schema.push_back(fd2);
	schema.push_back(fd3);

	database.specifySchema(schema);

	vector<string> row;
	string username = "******";
	string phonenum = "6265375521";
	string age = "17";
	row.push_back(username);
	row.push_back(phonenum);
	row.push_back(age);

	database.addRow(row);

	vector<string> row2;
	username = "******";
	phonenum = "5403317654";
	age = "20";
	row2.push_back(username);
	row2.push_back(phonenum);
	row2.push_back(age);

	database.addRow(row2);

	vector<string> row3;
	username = "******";
	phonenum = "6265375521";
	age = "25";
	row3.push_back(username);
	row3.push_back(phonenum);
	row3.push_back(age);

	database.addRow(row3);

	vector<int> results;
	vector<Database::SortCriterion> sortCrit;
	vector<Database::SearchCriterion> searchCrit;
	
	Database::SearchCriterion s1;
	s1.fieldName = "username";
	s1.minValue = "A";
	s1.maxValue = "C";

	Database::SearchCriterion s2;
	s2.fieldName = "phonenum";
	s2.minValue = "6000000000";
	s2.maxValue = "";

	searchCrit.push_back(s1);
	searchCrit.push_back(s2);


	database.search(searchCrit, sortCrit, results);

	cout << endl << "Passed all tests" << endl;
}
Ejemplo n.º 17
0
int ServiceManager::getNumServices(GUID svc_type) {
  INCRITICALSECTION(cs);
  return services.multiGetNumItems(svc_type);
}
Ejemplo n.º 18
0
int ServiceManager::getNumServices() {
  return services.getNumItems(); 
}
 void forceUnlockThread(util::ThreadArgs& args) {
     MultiMap<std::string, std::string> *mm = (MultiMap<std::string, std::string> *)args.arg0;
     util::CountDownLatch *latch = (util::CountDownLatch *)args.arg1;
     mm->forceUnlock("key1");
     latch->countDown();
 }
Ejemplo n.º 20
0
waServiceFactory *ServiceManager::enumService(GUID svc_type, int n) {
  INCRITICALSECTION(cs);
  waServiceFactory *ret = NULL;
  services.multiGetItem(svc_type, n, &ret);
  return ret;
}