0007容器之unordered_multiset

发布时间 2023-04-15 08:44:15作者: 寂静_星空
#include <list>                                                                                                                                                                                                  
#include<iostream>
#include<vector>
#include<stdexcept>
#include<string>
#include<cstdlib>//abort()
#include<cstdio>//snprintf();整数转字符
#include<ctime>
#include<algorithm>
#include<array>
#include<string>
#include <set>
#include <map>
#include <unordered_set>

using namespace std;
#define NUM 1000000

int main()
{
    unordered_multiset<string> c;
    char buf[10];
    clock_t timeStart = clock();

    string target = "66666";
    for (long i = 0; i < NUM; ++i)
    {   
        snprintf(buf, 10, "%d", rand());
        c.insert(string(buf));
        target =  buf;
    }   
    cout << "毫秒: " << (double((clock() - timeStart))/CLOCKS_PER_SEC * 1000 ) << endl;
    cout << "undered_multiset.size() = " << c.size() << endl;
    cout << "undered_multiset.max_size()= " << c.max_size() << endl;
    cout << "undered_multiset.bucket_count()= " << c.bucket_count() << endl;
    cout << "undered_multiset.load_factor()= " << c.load_factor() << endl;
    cout << "undered_multiset.max_load_factor()= " << c.max_load_factor() << endl;
    cout << "undered_multiset.max_bucket_count()= " << c.max_bucket_count() << endl;
    for (unsigned i = 0; i < 20; ++i)
    {   
      cout << "bucket #" << i << " has " << c.bucket_size(i) << " elements." << endl;
    }

    timeStart = clock();

    auto pItem = c.find(target);
    cout << "c.find() 毫秒: " << (double((clock() - timeStart))/CLOCKS_PER_SEC * 1000 ) << endl;

    if (pItem != c.end())
    {
        cout << "find value: " << (*pItem) << endl;
    }
    else
    {
        cout << "not find " << endl;
    }

    timeStart = clock();
    auto pItem1 = ::find(c.begin(),c.end(),target);
    cout << "::find() 毫秒: " << (double((clock() - timeStart))/CLOCKS_PER_SEC * 1000 ) << endl;
    cout << "::findvalue: " << *pItem1 << endl;

    return 0;
}