首页 > 其他分享 >0008容器之unordered_multimap

0008容器之unordered_multimap

时间:2023-04-15 09:14:11浏览次数:42  
标签:multimap snprintf 0008 long include buf unordered

#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>
#include <unordered_map>

using namespace std;
#define NUM 1000000

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

    long target = 99999;
    for (long i = 0; i < NUM; ++i)
    {
        snprintf(buf, 10, "%d", rand());
        c.insert(pair<long,string>(i,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->second << endl;
    }
    else
    {
        cout << "not find " << endl;
    }
    return 0;
}

标签:multimap,snprintf,0008,long,include,buf,unordered
From: https://www.cnblogs.com/gom-linwei/p/17320478.html

相关文章

  • C++性能优化——能用array就不要用unordered_map作为查询表
    unordered_map需要哈希值计算和表查询的开销,当key值为整数且连续,直接用数组作为查询表具有更高的效率。#include<iostream>#include<chrono>#include<unordered_map>usingnamespacestd;longlongcount=0;constexprintN=10;voidtimeMeasure(void(*f)()){a......
  • 『0008』- Solidity中public、internal、private在状态变量和函数中的使用以及Solidit
    作者:黎跃春,在上一小节中我们在函数参数中使用storage这个关键字时,当前的函数必须是internal或者private类型。在本小节中,我(微信:liyc1215)将重点为大家介绍属性和函数的使用权限。状态变量、函数的权限一、public备注:为了演示方便,我直接通过https://remix.ethereum.org/来进行演示。p......
  • 力扣 49 字母异位词分组 multimap
    classSolution{public:vector<vector<string>>groupAnagrams(vector<string>&strs){multimap<string,string>mp;//键排序,值没动intlen=s......
  • 0008 ALGO999-数的潜能
    试题算法训练数的潜能可以转换为将数分解为多少个3,再处理余数即可。为什么不分解为2,因为23=8<9=32。加上较小值得处理,输入值\(\le4\)时,直接输出即可。......
  • ruoyi-vue启动报错error:03000086:digital envelope routines::initialization error
    原因分析可能是因为node是最新版本导致ERR_OSSL_EVP_UNSUPPORTED错误SSL数字信封不支持解决措施(ps:网上找的)setNODE_OPTIONS=--openssl-legacy-provider亲测并......
  • 1. 两数之和 unordered_map使用
    https://leetcode.cn/problems/two-sum/ 给定一个整数数组nums 和一个整数目标值target,请你在该数组中找出和为目标值target 的那 两个 整数,并返回它们的数组......
  • kx00008-顺序表--顺序表尾插法
    一、顺序表结构定义#defineINIT_SIZE10 //顺序表初始容量typedefvoid(myOpFunType)(void*); //定义操作函数类型typedefintseqType; //定义顺序表元素类型......
  • STL-map/multimap容器
    简介:map中所有元素都是pairpair第一个元素为key键值,起到索引作用,第二个元素为value实质所有元素都会按照key键值自动排序本质:map/multimap属于关联式容器,底层结构使用二叉树......
  • error:03000086:digital
    运行老项目报错opensslErrorStack:[‘error:03000086:digitalenveloperoutines::initializationerror‘]vue.js前端npmnpmrunserve报错open......
  • C++ STL unordered_map
    #include<unordered_map>头文件usingnamespacestd;作用无序map容器。以pair形式存储数据。pair在#include<utility>头文件中定义。pair:<key,value>pair其实就是数据......