本文整理汇总了C++中MultiMap类的典型用法代码示例。如果您正苦于以下问题:C++ MultiMap类的具体用法?C++ MultiMap怎么用?C++ MultiMap使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了MultiMap类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: flippedMap
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;
}
示例2: PrintEqualProduct
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;
}
}
}
}
示例3: lockThread
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();
}
}
示例4: tryLockThread2
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;
}
}
示例5: main
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();
}
示例6: Show
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;
}
}
示例7: putGetRemoveTestThread
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();
}
示例8: _Frush
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;
}
}
示例9: main
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();
}
}
示例10: Poses
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;
}
示例11: main
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 = "Jasoniful";
//.........这里部分代码省略.........
示例12: forceUnlockThread
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();
}
示例13: sendNotification
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
}
示例14: registerService
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;
}
示例15: deregisterService
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;
}