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


C++ MyMap类代码示例

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


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

示例1: main

int main()
{
    MyMap *mymap = new MyMap();
    vector<int> *sum_vec;
    const Key *key;
    int len;
    int p[MaxLen];
    srand( unsigned(time(NULL)));
    for(int c = 0; c < MaxNum; ++c)
    {
        len = rand() % MaxLen + 1;
        int sum = 0;
        for(int i = 0; i < len; ++i)
        {
            p[i] = rand() % MaxNum;
            sum += p[i];
        }
        key = new Key(p, len);
        sum_vec = new vector<int>();
        sum_vec->push_back(sum);
        mymap->insert(make_pair(*key, sum_vec));
        delete key;
    }
    for(MyMap::iterator it = mymap->begin(); it != mymap->end(); ++it)
    {
        delete it->second;
    }
    delete mymap;
    return 0;
}
开发者ID:frankwangzheng,项目名称:MyTrivialProject,代码行数:30,代码来源:profiler_test.cpp

示例2: add_vertex

 static typename DerivedF::Scalar  add_vertex(const Eigen::Matrix<typename DerivedV::Scalar, Eigen::Dynamic, 1> &values,
                                              const Eigen::Matrix<typename DerivedV::Scalar, Eigen::Dynamic, 3> &points,
                                              unsigned int i0,
                                              unsigned int i1,
                                              PointMatrixType &vertices,
                                              int &num_vertices,
                                              MyMap &edge2vertex)
 {
   // find vertex if it has been computed already
   MyMapIterator it = edge2vertex.find(EdgeKey(i0, i1));
   if (it != edge2vertex.end()) 
     return it->second;
   ;
   
   // generate new vertex
   const Eigen::Matrix<typename DerivedV::Scalar, 1, 3> & p0 = points.row(i0);
   const Eigen::Matrix<typename DerivedV::Scalar, 1, 3> & p1 = points.row(i1);
   
   typename DerivedV::Scalar s0 = fabs(values[i0]);
   typename DerivedV::Scalar s1 = fabs(values[i1]);
   typename DerivedV::Scalar t  = s0 / (s0+s1);
   
   
   num_vertices++;
   if (num_vertices > vertices.rows())
     vertices.conservativeResize(vertices.rows()+10000, Eigen::NoChange);
   
   vertices.row(num_vertices-1)  = (1.0f-t)*p0 + t*p1;
   edge2vertex[EdgeKey(i0, i1)] = num_vertices-1;
   
   return num_vertices-1;
 }
开发者ID:AurelGruber,项目名称:Scalable-Locally-Injective-Mappings,代码行数:32,代码来源:marching_cubes.cpp

示例3: main

int main(int argc, char * argv[]) {
    if (argc == 0) {
        cout << "usage: " << argv[0] << "[File1 [File2 [File3 [...]]]]" << endl;
    }
    for (int i = 1; i < argc; i++) {
        cout << "File: " << argv[i] << endl;
        printNames(argv[i]);

        MyMap::iterator it = names.begin();
        while (it != names.end()) {
            //cout << it->first << ": " << it->second << endl;
            sortiert.push_back(it);
            it++;
        }
        //partial_sort (sortiert.begin(), sortiert.bein() + 20, sortiert.end(), mySort);
        partial_sort (sortiert.begin(), sortiert.begin() + 20, sortiert.end(), myObject);

        size_t c = 0;
        for (MyVec::iterator it = sortiert.begin(); it != sortiert.end() && c < 20; it++, c++) {
            cout << (*it)->first << ": " << (*it)->second << endl;
        }
        cout << "==============================" << endl;

        names.clear();
    }
}
开发者ID:cboettcher,项目名称:CPP,代码行数:26,代码来源:main.cpp

示例4: MyPair

void VS10Inst::ValidateDestMask()
{
    char temp[256];
    typedef std::map<char, int> MyMap;
    typedef MyMap::value_type MyPair;
    static const MyPair pairs[] = 
    {
        MyPair('x',1),
        MyPair('y',2),
        MyPair('z',3),
        MyPair('w',4),
    };
    static const MyMap swizzleMap(pairs, pairs+(sizeof(pairs)/sizeof(pairs[0])));

    if ( dst.mask[0] == 0 ) return;
    int i = 1;
    while ( i < 4 && dst.mask[i] != 0 )
    {
        MyMap::const_iterator lastMaskIt = swizzleMap.find(dst.mask[i-1]);
        MyMap::const_iterator curMaskIt = swizzleMap.find(dst.mask[i]);
        if (lastMaskIt == swizzleMap.end() || curMaskIt == swizzleMap.end() ||
            lastMaskIt->second >= curMaskIt->second)
//        if ( dst.mask[i-1] >= dst.mask[i] )
        {
            char mask[5];
            strncpy( mask, dst.mask, 4 );
            mask[4] = 0;
            sprintf( temp, "(%d) Error: destination register has invalid mask: %s\n", line, mask );
            errors.set( temp );
            break;
        }
        i++;
    }
}
开发者ID:jjiezheng,项目名称:pap_full,代码行数:34,代码来源:vs1.0_inst.cpp

示例5: getFrequencyTable

/* Function: getFrequencyTable
 * Usage: MyMap<ext_char, int> freq = getFrequencyTable(file);
 * --------------------------------------------------------
 * This function will also set the frequency of the EOF
 * character to be 1, which ensures that any future encoding
 * tree built from these frequencies will have an encoding for
 * the EOF character.
 */
MyMap<ext_char, int> getFrequencyTable(ibstream& infileStream) {
    MyMap<ext_char, int> resultFrequenciesMap;
    ext_char nextChar;

    while ((nextChar = infileStream.get()) != EOF) {
        modifyMap(resultFrequenciesMap, nextChar);
    }

    resultFrequenciesMap.add(EOF, 1);
    return resultFrequenciesMap;
}
开发者ID:shpp-ekuryatenko,项目名称:cs-b-assignment5_Collections,代码行数:19,代码来源:HuffmanEncoding.cpp

示例6: modifyMap

/* Function: modifyMap
 * -------------------
 * Modifies param frequenciesMap entries
 * for current char key.
 */
void modifyMap(MyMap<ext_char, int>& frequenciesMap,
               ext_char nextSymbol) {
    if (frequenciesMap.containsKey(nextSymbol)) {
        /* Modifies map entry - increments symbol value */
        int symbValue = frequenciesMap[nextSymbol];
        frequenciesMap.put(nextSymbol, ++symbValue);
    }else{
        /* Adds new map entry for this symbol */
        int symbApearence = 1;
        frequenciesMap.put(nextSymbol, symbApearence);
    }
}
开发者ID:shpp-ekuryatenko,项目名称:cs-b-assignment5_Collections,代码行数:17,代码来源:HuffmanEncoding.cpp

示例7: Test_STL

bool Test_STL()
{
    TTRACE(_T("====================================================="));
    typedef std::map<int, char> MyMap;
    MyMap map;
    map.insert(std::make_pair(1, 'A'));
    map.insert(std::make_pair(2, 'B'));
    std::for_each(map.begin(), map.end(), pair_second(Printer()));
    std::for_each(map.begin(), map.end(), pair_second(&Print));

    return true;
}
开发者ID:erio-nk,项目名称:MyCxxProgram2011,代码行数:12,代码来源:Test.cpp

示例8: outfile

bool IndexerImpl::save(string filenameBase)
{
    ofstream outfile(filenameBase+".txt");
    if ( ! outfile )		 
	{
	    cerr << "Error: Cannot create data.txt!" << endl;
	    return false;
	}
    //Map to store locations to grab from array
    MyMap<int, int>* h2pull = new MyMap<int, int>;
    //Save size of urlToCount to outfile
    outfile << urlToCount->size() << endl;
    string word;
    vector<point>* value = urlToCount->getFirst(word);
    while (value!=NULL)
    {
        //save word and size of vector
        outfile << word << " " << value->size() << endl;
        vector<point>::iterator it = value->begin();
        while (it!=value->end())
        {
            int hash = it->m_hash;
            outfile << hash << " " << it->m_count << endl;
            h2pull->associate(hash%MAX_MAP_SIZE, hash%MAX_MAP_SIZE);
            it++;
        }
        value = urlToCount->getNext(word);
    }
    //Save size of h2pull (number of elements in array to visit)
    outfile << h2pull->size() << endl;
    int temp;
    int* location = h2pull->getFirst(temp);
    while (location!=NULL)
    {
        int size = idToUrl[temp]->size();
        outfile << temp << " " << size <<endl;
        int hash;
        string* url = idToUrl[temp]->getFirst(hash);
        while(url!=NULL)
        {
            outfile << hash << " "<< *url << endl;
            url = idToUrl[temp]->getNext(hash);
        }
        location = h2pull->getNext(temp);
    }
    
    delete h2pull;
    return true;
}
开发者ID:thecalvinchan,项目名称:oogle,代码行数:49,代码来源:Indexer.cpp

示例9: saveMyMap

bool saveMyMap(string filename, MyMap<KeyType, ValueType>& m)
{
    // save contents of m to a file
    ofstream stream("filename");    // Create an ofstream object to create the file
    if (! stream) return false;     // Return false if we can't create the file
    writeItem(stream, m.size());    // Save the number of associations in m to stream
    KeyType x;
    ValueType* y = m.getFirst(x);
    for (int i = 0; i < m.size(); i++) {
        writeItem(stream, x);
        writeItem(stream, *y);
        y = m.getNext(x);
    }
    return true;
}
开发者ID:jeffreytai,项目名称:Basic-Search-Engine,代码行数:15,代码来源:Indexer.cpp

示例10: main

int main ()
{
  MyMap amap;
  amap.insert("one", 1);
  amap.insert("two", 2);
  amap.insert("three", 3);
  //amap["three"].push_back(3);
  //amap["three"].push_back(3);
  //cout << amap["one"];
  amap.find("one");
  amap.find("two");
  amap.find("three");

  return 0;
}
开发者ID:speedkumo,项目名称:c_plus_map_second,代码行数:15,代码来源:mapL3.cpp

示例11: clear

void tst_QMap::clear()
{
    {
	MyMap map;
	map.clear();
	QVERIFY( map.isEmpty() );
	map.insert( "key", MyClass( "value" ) );
	map.clear();
	QVERIFY( map.isEmpty() );
	map.insert( "key0", MyClass( "value0" ) );
	map.insert( "key0", MyClass( "value1" ) );
	map.insert( "key1", MyClass( "value2" ) );
	map.clear();
	QVERIFY( map.isEmpty() );
    }
    QCOMPARE( MyClass::count, int(0) );
}
开发者ID:,项目名称:,代码行数:17,代码来源:

示例12: loadMyMap

bool loadMyMap(string filename, MyMap<KeyType, ValueType>& m)
{
    m.clear();
    ifstream stream("filename");
    if (!stream) return false;
    int size = m.size();
    if (!readItem(stream, size)) return false; // Read the number of associations in m from stream, returning false if we can't
    KeyType x;
    ValueType y;
    for (int i = 0; i < size; i++) {
        if (!readItem(stream, x)) return false;
        stream.ignore(10000, '\n');
        if (!readItem(stream, y)) return false;
        stream.ignore(10000, '\n');
        m.associate(x, y);
    }
    return true;
}
开发者ID:jeffreytai,项目名称:Basic-Search-Engine,代码行数:18,代码来源:Indexer.cpp

示例13: exceptionMap

void tst_ExceptionSafety::exceptionMap() {

    {
        MyMap map;
        MyMap map2;
        MyMap map3;

        throwType = ThrowNot;
        for (int i = 0; i<10; i++)
            map[ FlexibleThrowerSmall(i) ] = FlexibleThrowerSmall(i);

        return; // further test are deactivated until Map is fixed.

        for( int i = ThrowAtCopy; i<=ThrowAtComparison; i++ ) {
            try {
                throwType = (ThrowType)i;
                map[ FlexibleThrowerSmall(10) ] = FlexibleThrowerSmall(10);
            } catch(...) {
            }
            QCOMPARE( map.size(), 10 );
            QCOMPARE( map[ FlexibleThrowerSmall(1) ], FlexibleThrowerSmall(1) );
        }

        map2 = map;
        try {
            throwType = ThrowLater;
            map2[ FlexibleThrowerSmall(10) ] = FlexibleThrowerSmall(10);
        } catch(...) {
        }
        /* qDebug("%d %d", map.size(), map2.size() );
        for( int i=0; i<map.size(); i++ )
            qDebug( "Value at %d: %d",i, map.value(FlexibleThrowerSmall(i), FlexibleThrowerSmall()).value() );
        QCOMPARE( map.value(FlexibleThrowerSmall(1), FlexibleThrowerSmall()), FlexibleThrowerSmall(1) );
        qDebug( "Value at %d: %d",1, map[FlexibleThrowerSmall(1)].value() );
        qDebug("%d %d", map.size(), map2.size() );
        */
        QCOMPARE( map[ FlexibleThrowerSmall(1) ], FlexibleThrowerSmall(1) );
        QCOMPARE( map.size(), 10 );
        QCOMPARE( map2[ FlexibleThrowerSmall(1) ], FlexibleThrowerSmall(1) );
        QCOMPARE( map2.size(), 10 );

    }
    QCOMPARE(objCounter, 0 ); // check that every object has been freed
}
开发者ID:mpvader,项目名称:qt,代码行数:44,代码来源:tst_exceptionsafety.cpp

示例14: changeMap

void GameScene::changeMap(Point startPoint,int mapPoint){
	this->removeChildByName("map");
	this->removeChildByTag(sGlobal->mapNum);
	sGlobal->mapNum = mapPoint;
	MyMap* myMap = MyMap::create();
	sGlobal->map = myMap->m_map;
	sGlobal->myMap = myMap;
	myMap->setPosition(Point(100, 100));
	myMap->m_map->setPosition(Point(-100, -100));
	this->addChild(myMap, 5, sGlobal->mapNum);
	this->addChild(myMap->m_map,6,"map");
	/*myMap->setPosition(Point(0, 0));*/
	myMap->m_map->addChild(sGlobal->hero);
	/*sGlobal->map->addChild(sGlobal->hero);*/
	sGlobal->hero->setTiledMap(sGlobal->map);
	sGlobal->hero->setPosition(sGlobal->myMap->positionForTileCoord(startPoint));
	/*this->addHero(sGlobal->map, sGlobal->myMap->positionForTileCoord(startPoint-Point(2,2)));*/
	CocosDenshion::SimpleAudioEngine::getInstance()->playBackgroundMusic("WhenInSchool.mp3", true);
}
开发者ID:Mr-Fuyj,项目名称:MyFirstGame,代码行数:19,代码来源:GameScene.cpp

示例15: hashurl

bool IndexerImpl::incorporate(string url, WordBag& wb)
{

    int hash;
    //Generates a hash of url as well as index for linear probing
    int modhash = hashurl(url,hash);
    //If the head bucket of the array is not initialized, initialize it
    if (idToUrl[modhash]==NULL)
        idToUrl[modhash]=new MyMap<int,string>;
    //Checks to see if this url has already been passed to incorporate
    if (idToUrl[modhash]->find(hash)!=NULL)
        return false;
    //Adds url to hash-url map
    if (idToUrl[modhash]->size()==0)
        indexes.push_back(modhash);
    idToUrl[modhash]->associate(hash,url);
    
    
    string word;
    int count;
    //Iterates through W distinct words in wordbag. O(W)
    bool gotAWord = wb.getFirstWord(word, count);
    while (gotAWord)
    {
        //Accounts for case-insensitive indexing.
        strToLower(word);
        point bucket = point(hash,count);
        //Find if word already exists. O(log N).
        vector<point>* temp = urlToCount->find(word);
        if (temp==NULL)
        {
            //The word does not yet exist in the index
            //Create a temp vector
            temp = new vector<point>;
        }
        temp->push_back(bucket);
        //Map word to temp Map of urlhash to wordcount
        urlToCount->associate(word, *temp);
        gotAWord = wb.getNextWord(word,count);
    }
    //Final BigO is O(WlogN) which is less than O(WN)
    return true;
}
开发者ID:thecalvinchan,项目名称:oogle,代码行数:43,代码来源:Indexer.cpp


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