首页 > 其他分享 >0007容器之unordered_multiset

0007容器之unordered_multiset

时间:2023-04-15 09:14:21浏览次数:40  
标签:0007 snprintf clock multiset 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>

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;
}

标签:0007,snprintf,clock,multiset,include,buf,unordered
From: https://www.cnblogs.com/gom-linwei/p/17320475.html

相关文章

  • 0008容器之unordered_multimap
    #include<list>#include<iostream>#include<vector>#include<stdexcept>#include<string>#include<cstdlib>//abort()#include<cstdio>//snprintf();整数转字符#include<ctime>#include<algorithm>#include<ar......
  • C++性能优化——能用array就不要用unordered_map作为查询表
    unordered_map需要哈希值计算和表查询的开销,当key值为整数且连续,直接用数组作为查询表具有更高的效率。#include<iostream>#include<chrono>#include<unordered_map>usingnamespacestd;longlongcount=0;constexprintN=10;voidtimeMeasure(void(*f)()){a......
  • COMP20007 Task 2: C Problem
    Task2:CProblemAssignment1GeneralTask1:AlgorithmicDesignTask2:CProblemAssignmentSubmissionAcademicHonestyLatePolicyRequirements:CProgrammingProgrammingStyleMarkBreakdownAdditionalSupportAcknowledgementsTask2:CProblemOlivia'sgrandfa......
  • 6.Java HotSpot(TM) 64-Bit Server VM warning: INFO: os::commit_memory(0x000000079
    这个问题引起的原因是:服务器上物理内存太小,大部分都是应为程序太多,内存吃紧,而给jvm分配的内存太大(java程序启动需要的内存,linux不能给),最好调整java程序jvm内存吧(测试环......
  • 0007 ALGO1000-kAc给糖果你吃
    试题算法训练kAc给糖果你吃比较简单,排序后拿数量多的importjava.util.Arrays;importjava.util.Scanner;/***@authorHuaWang135608*@date2023.03.1613:1......
  • 1. 两数之和 unordered_map使用
    https://leetcode.cn/problems/two-sum/ 给定一个整数数组nums 和一个整数目标值target,请你在该数组中找出和为目标值target 的那 两个 整数,并返回它们的数组......
  • WIN11无法访问win7的共享打印机,(操作不能完成(错误0x00000709)),WIN10能正常访问该共享打
    1、问题描述:WIN11无法访问win7的共享打印机(操作不能完成(错误0x00000709)),win10可以访问。三台电脑都在同一个局域网内,分别为win7,win10,win11。WIN7系统为旗舰版,作为共......
  • Gym100078H-History-of-Football题解
    题目传送门题意:有\(n\)支球队,每两支球队之间都会进行一场较量,赢者积\(3\)分,输者积\(0\)分,如果平局则各积\(1\)分。给出每支球队的最终积分,求方案数。\(n\le8\)......
  • [ARC107D] Number of Multisets
    \(\text{Solution}\)学习到了一些\(dp\)的\(trick\)设\(f_{i,j}\)表示用了\(i\)的元素,当前和为\(j\)的方案数\(dp\)有两样不好处理的东西第一是当前和不一定......
  • kx00007-顺序表--插入函数
    一、顺序表结构定义#defineINIT_SIZE10 //顺序表初始容量typedefvoid(myOpFunType)(void*); //定义操作函数类型typedefintseqType; //定义顺序表元素类型......