本文整理汇总了C++中MyMap::size方法的典型用法代码示例。如果您正苦于以下问题:C++ MyMap::size方法的具体用法?C++ MyMap::size怎么用?C++ MyMap::size使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MyMap
的用法示例。
在下文中一共展示了MyMap::size方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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;
}
示例2: 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
}
示例3: save
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;
}
示例4: 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;
}
示例5: main
int main()
{
MyMap<string, int> months;
months["january"] = 31;
months["february"] = 28;
months["march"] = 31;
months["april"] = 30;
months["may"] = 31;
months["june"] = 30;
months["july"] = 31;
months["august"] = 31;
months["september"] = 30;
months["october"] = 31;
months["november"] = 30;
months["december"] = 31;
cout << "Map size: " << months.size() << endl;
if (months.empty())
cout << "Map is empty!" << endl;
else
cout << "Map is not empty!" << endl;
cout << "june -> " << months["june"] << endl;
cout << "blabla -> " << months["blabla"] << endl;
cout << endl;
display(months);
MyMap<string, int>::iterator it;
it = months.find("blabla");
months.erase(it);
display(months);
return 0;
}