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


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

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


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

示例1: 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;
                }
            }
    }

}
开发者ID:CppOpenSourceProjects,项目名称:coding-questions,代码行数:35,代码来源:Print+all+the+solutions.cpp

示例2: 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;
}
开发者ID:jontromanab,项目名称:reuleaux_moveit,代码行数:61,代码来源:hdf5_dataset.cpp

示例3: 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();
	}
	
}
开发者ID:github-ssi,项目名称:libssi,代码行数:81,代码来源:test_multimap.cpp

示例4: 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";
//.........这里部分代码省略.........
开发者ID:JasonYang96,项目名称:DataBase,代码行数:101,代码来源:main.cpp


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