STL常用操作:unordered_map

STL-unordered_set和unordered_map的基本使用 unordered_set和unordered_map的基本使用unordered_setunordered_set的使用unordered_set的定义方式unordered_set的常用接口unordered_multisetunordered_mapunordered_map的定义方式unordered_map的主要接口使用unordered_multimap ????快速导航关联在一起的文章???? 文章名称 链接 二叉搜索树 点击直达文章 set和map的基本使用 点击直达文章 阅读详情

1.初始化

unordered_map<string, int> map1; map1[string("abc")] = 1; map1["def"] = 2;//创建空map,再赋值
unordered_map<string, int> map2(map1);    //拷贝构造
unordered_map<string, int> map3(map1.find("abc"), map1.end());    //迭代器构造
unordered_map<string, int> map4(move(map2));    //移动构造
unordered_map<string, int> map5 {{"this", 100},{"can", 100},};//使用initializer_list初始化

2.常用操作

map1.at("abc");	//查找具有指定key的元素,返回value
map1.find("abc");    //查找键为key的元素,找到返回迭代器,失败返回end()
map1.count("abc");    //返回指定key出现的次数,0或1
map1.emplace(make_pair("str1", 1));    //使用pair的转换移动构造函数,返回pair<unordered_map<string, int>::iterator, bool>
map1.emplace("str2", 2);    //使用pair的模板构造函数,如果key已经存在则什么都不做
map1.insert(pair<string ,int>("sex", 1));//插入元素,返回pair<unordered_map<string, int>::iterator, bool>
map1.insert(unordered_map<string, int>::value_type("sex", 1));//插入元素,如果key已经存在则什么都不做
map1.insert(make_pair("sex", 1));//插入元素,返回pair<map<string, int>::iterator, bool>,插入成功second为true,失败为flase
map1.insert({"sex", 1});    //使用initializer_list插入元素
map1.insert(map1.end(), {"sex", 1});//指定插入位置,如果位置正确会减少插入时间
map1.insert(map2.begin(), map2.end());//使用范围迭代器插入
map1.erase("abc");	    //删除操作,成功返回1,失败返回0
map1.erase(map1.find("abc"));	    //删除操作,成功返回下一个pair的迭代器
map1.erase(map1.begin(), map1.end());    //删除map1的所有元素,返回指向end的迭代器
map1.empty();        //是否为空
map1.size();        //大小
map1.bucket_count();    //返回容器中的桶数
map1.bucket_size(1);    //返回1号桶中的元素数
map1.bucket("abc");    //abc这个key在哪一个桶
map1.load_factor();    //负载因子,返回每个桶元素的平均数,即size/float(bucket_count);
map1.max_load_factor();//返回最大负载因子
map1.max_load_factor(2);//设置最大负载因子为2,rehash(0)表示强制rehash
map1.rehash(20);//设置桶的数量为20,并且重新rehash
map1.reserve(20);//将容器中的桶数设置为最适合元素个数,如果20大于当前的bucket_count乘max_load_factor,则增加容器的bucket_count并强制重新哈希。如果20小于该值,则该功能可能无效。
unordered_map<string, int>::iterator it = map1.begin();	    //返回指向map1首元素的迭代器
unordered_map<string, int>::const_iterator c_it = map1.cbegin();	    //返回指向map1首元素的常量迭代器
unordered_map<string, int>::local_iterator it = map1.begin(1);//返回1号桶中的首元素迭代器
unordered_map<string, int>::const_local_iterator c_it = map1.cbegin(1);//返回1号桶中的首元素的常量迭代器
pair<unordered_map<string, int>::iterator, unordered_map<string, int>::iterator> it = map1.equal_range("abc");//返回一个pair,pair里面第一个变量是lower_bound返回的迭代器,第二个迭代器是upper_bound返回的迭代器
map1.clear();        //清空

3.不常用操作

map1.emplace_hint(map1.end(),"abc",12);//提示插入的位置,如果指定的位置是真正要插入的位置,会减少插入时间
map1.try_emplace("abc",12);//如果abc键不存在则插入,如果存在则什么都不做,C++17支持
map1.insert_or_assign("sex", 1);    //如果key不存在则插入,如果存在则赋值,C++17支持
map1.swap(map2);    //交换,要求两个map的类型相同
map1.get_allocator();    //返回分配器
map1.max_size();          //返回可以容纳的最大元素个数
map1.max_bucket_count();    //返回可以容纳的最大桶数
unordered_map<string, int>::hasher hash = map1.hash_function();//返回hash函数
unordered_map<string, int>::key_equal eql = map1.key_eq();///返回比较key是否相等的函数,接收两个string参数
auto nh = map1.extract("sex"); nh.key() = "gender"; map1.insert(move(nh));//改变key,而不改变对应的值,nh是结点把柄
map1.merge(map2);    //合并两个map,C++17支持

4.遍历

  • 迭代器
for(unordered_map<string, int>::iterator it = map1.begin(); it != map1.end(); it++) {
    cout << it->first << "\t" << it->second << endl;
}
  • C11
for(auto m : map1) {
    cout << m.first << ", " << m.second << '\n';
}

 

5.算法

【C++实战篇】C++中使用哈希表(unordered_map)的一些常用操作方法(哈希表的建立、添加元素、成员函数、遍历、实际应用) 这篇文章介绍了C++中unordered_map哈希表的常用操作方法及其实际应用。主要内容包括:1) 基本哈希表的创建和元素添加方法;2) 常用成员函数如find、count、size等;3) 两种遍历哈希表的方式;4) 三个典型应用案例:字母异位词判断、两数之和问题、数组中出现次数超过一半的数字查找。文章通过代码示例详细说明了每种操作的使用方法,并提供了LeetCode相关题目的参考解法,对理解和使用unordered_map有很好的参考价值。 阅读详情

相关推荐

STM32版CCD线性摄像头寻线寻迹小车_stm32接ccd

目前大多数的小车寻线寻迹都是用红外对管寻线,这是比较简单也比较成熟的技术方案,且成本也低。本文将介绍使用CCD线性摄像头寻线寻迹。TSL1401 线性传感器由一个 1x128 的光电二极管阵列、相关的电荷放大电路以及一个内部像素数据保功能组成。内部像素数据保功能可以为所有像素点提供同时积分的开始和停止时间。该阵列由 128 个像素组成,每个像素的感光面积为 3,524.3 平方微米。像素之间的间隔为 8μm。内部控制逻辑简化了操作,该模块需要串行输入(SI)信号和时钟信号(CLK)。

2401_87557129的博客 3233

C++中map用法

map的用法总结如上,还有类似用途的unordered_map和multimap用法基本一致,区别就是unordered_map的key值可以无序,multimap一个key可以对应多个value。

qq_46809063的博客 4407

史上最全的Logisim存储系统实验教程(基于华中科技大学计算机组成原理实验)内赋源码下载

本博客是最全的最好的解释的华中科技大学计算机组成实验存储系统实验,本博客给出了电路实现,也给出了使用电路的原因有利于新手学习十分详细。并且内赋源码下载。

qq_62325622的博客 2万+

unordered_map的赋值方式

**unordered_map的赋值方式 代码: 代码中有注释。 #include <iostream> #include <unordered_map> using namespace std; int main() { unordered_map<int, int> map; //使用insert插入 map.insert(pair<int, int>(1, 10)); map.insert(pair<int, int>(2, 20)

发如雪 4248

通过PXE的方式实现Ubuntu 24.04 自动安装

之前都是通过PXE来自动化安装Redhat系列的,例如:Rocky9、Rocky10、CentOS7、银河麒麟 Kylin-V10、Kylin-V11、OpenEuler 24.03等。现在安装Ubuntu系列的跟红帽的不太一样,所以在这里介绍下。

邢宇宇的博客 1496

实战教程:用DETR+超分辨率搞定红外小目标检测(附完整代码)

本文提供了一套完整的红外小目标检测实战方案,通过融合EDSR超分辨率技术与改进型DETR深度学习算法,有效解决了红外图像中小目标检测的难题。文章详细介绍了从环境搭建、数据预处理、模型定制(如引入EMA注意力与S2特征层)到训练调优的全流程,并附有完整代码,旨在帮助开发者将前沿算法高效落地于安防、自动驾驶等实际场景。

weixin_29057163的博客 538

C++ STL unordered_map

个人学习记录

yearning_mjw的博客 814

Keil调试技巧:3种方法查看Cortex-M4的SCB寄存器(含CPUID内存映射解析)

本文详细介绍了在Keil MDK中查看Cortex-M4内核SCB寄存器的三种实战方法:使用Watch窗口进行符号化观察、通过Memory窗口直接查看物理内存映射,以及利用SFR寄存器浏览器解析位域信息。文章重点解析了CPUID寄存器的内存映射地址(0xE000ED00)及其位域含义,帮助开发者深入理解处理器身份识别与底层调试技巧,提升嵌入式系统调试效率。

h6i7j8的博客 575

C++ std::unordered_map怎么用

#include <iostream> #include <unordered_map> #include <map> #include <string> using namespace std; int main() { //注意:C++11才开始支持括号初始化 unordered_map<int, string> myMap={{ 5, "张大" },{ 6, "李五" }};//使用{}赋值 ...

软件工程小施同学 的专栏 920

Steam崩溃:ntdll.dll报错0xc0000374...如何解决?

🏆本文收录于 《全栈 Bug 调优(实战版)》 专栏。专栏聚焦真实项目中的各类疑难 Bug,从成因剖析 → 排查路径 → 解决方案 → 预防优化全链路拆解,形成一套可复用、可沉淀的实战知识体系。无论你是初入职场的开发者,还是负责复杂项目的资深工程师,都可以在这里构建一套属于自己的「问题诊断与性能调优」方法论,助你稳步进阶、放大技术价值。

**My Coding Family** 1172

C++软件异常分析概述

本文将详细讲述Windows系统中软件异常的分类以及常用的排查方法,给大家提供一个借鉴与参考。

dvlinker的技术专栏 4万+

C++ STL库map,unordered_map,multimap,unordered_multimap详解

本文摘要:文章系统介绍了C++ STL中的关联容器,重点分析map、unordered_map及其变体multimap的特性与使用。map基于红黑树实现,保持元素有序性,提供O(logn)操作复杂度;unordered_map基于哈希表,提供平均O(1)访问但无序存储。详细对比了两者在构造、访问、查找、删除等方面的差异,并介绍了multimap允许重复键的特性。

我的博客主要是用来给我自己复习的,主要是上传一些知识点,小型的项目和功能模块,如果有什么问题或错误麻烦联系我! 822

C# WinForm 基于DirectShow.dll编写的程序,可边预览边保存视频,音频和图片

基于微软的DirectShow.dll的二次开发1.自动识别连接的摄像头跟麦克风且可以对其进行选择(默认选中第一个)2.可录制wmv和avi两种格式的视频并且都带有音频,avi可以录制的分辨率和帧数进行选择,wmv默认进行了淸晰度优化如不喜欢可去除代码中有相关提示3.可在预览点开之后进行拍照,也可边录制视频边拍照4.添加了视频和音频的压缩功能(酌情使用)这次二次开发发现C#对DirectShow的相关信息太少,这次做完也不敢藏私共享出来,还望大家指正

C++ STL 系列(三):map vs unordered_map —— 红黑树与哈希表

本文介绍了STL中两种重要的键值对容器:map和unordered_map。map基于红黑树实现,元素自动排序,查找复杂度为O(logn),适用于需要排序的场景;unordered_map基于哈希表实现,元素无序但查找速度快,平均复杂度为O(1),适合快速查找需求。两者的主要区别在于底层结构和元素顺序特性。文章还对比了它们的适用场景,并列举了常用操作方法。建议根据具体需求选择:需要排序时用map,追求查找速度时用unordered_map。

Mark Wu 的博客 301

jre9下载 jdk9

(Java SE Runtime Environment 9.0) 9.0u175 官方最新版 【x86|x64】

大中型超市收银系统(可直接运行)

光步前台收银系统系统功能:商品销售、商品退货、挂单、收银员权限、会员销售、单品取消、整单取消、商品查询、脱机销售、脱机数据上传,基本资料下载,开钱箱、小票打印、收款结算,支持多币种付款方式(现金、储值卡、礼券、微信等),支持多种促销。运行环境:.net 4.0登陆信息用户名:1001 密码:123456内置商品信息,商品编码可输入00001000 - 00010000,测试效果相关功能键F5 结算 F9挂单 F11商品查询 F8退货 Insert单品取消 Del整单取消 F12开钱箱F2 会员 Ctrl+Z退出系统 Home 锁屏 相关源码待公开

C++ STL 竞赛常用容器详解

本文详细介绍了C++ STL中5种竞赛常用容器的核心用法和应用场景:1) queue用于BFS和FIFO操作;2) priority_queue实现堆结构用于贪心算法;3) stack处理LIFO问题和单调栈;4) set维护有序唯一元素;5) multiset处理可重复有序数据。每种容器均配有典型应用示例(如Dijkstra算法、单调栈求下一个更大元素)和3-5道经典题目(含LeetCode和洛谷链接),涵盖时间复杂度分析和使用注意事项。这些容器是算法竞赛中解决图论、贪心、单调性等问题的利器。

2401_88089822的博客 1318

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

unordered_map的介绍与用法

介绍示例代码std::unordered_map 是 C++ STL 标准库中的一个关联容器,提供了一种将键映射到值的方法。它是使用哈希表实现的,可以在 O(1)O(1)(平均情况下)的时间复杂度内完成插入、查找和删除操作。使用 std::unordered_map 需要包含头文件 。insert(key, value):将 (key, value) 键值对插入到 unordered_map 中。at(key):返回键为 key 的值的引用。

lzw0107的博客 2188

常用STL容器

关联容器,按照元素的键值自动排序,并且可以根据键快速查找和访问值,不允许重复元素。单向链表,与双向链表相比,空间占用更少,性能更好,但只支持单向遍历。哈希表,支持快速查找元素,不进行元素排序,不允许重复元素。哈希表,支持快速查找键值对,不进行元素排序,不允许重复键。关联容器,按照元素的键值自动排序,不允许重复元素。允许重复元素的关联容器,按照元素的键值自动排序。允许重复键值的关联容器,按照元素的键值自动排序。允许重复键值对的哈希表,不进行元素排序。允许重复元素的哈希表,不进行元素排序。

永远相信,美好的事情即将发生 581

《C++进阶之STL》【unordered_set/unordered_map 使用介绍】

本文介绍了C++ STL中的unordered_set和unordered_map容器。文章详细讲解了其模板参数、构造函数、常用成员函数(如:insert、find、erase等)以及非成员函数重载。通过示例代码展示了默认构造、初始化列表构造、拷贝构造和移动构造等用法,并演示了如何合并两个unordered_set容器。

序属秋秋秋的博客 2794

STL容器之unordered_map类

STL容器之unordered_map类

Xpccccc的博客 3204

【STL】unordered_map

C++11 引入了 unordered_map 容器,其功能和 map 完全类似,但其底层结构为哈希表,因此是无序的,并且增删查的效率为 O(1)。

jmlangel_的博客 1584

12 STL【unordered_map介绍】【unordered_map获取/添加/删除元素 成员函数】【unordered_multimap】【unordered_set】

文章目录0 - 前言1 - unordered_map成员函数2 - unordered_map迭代器3 - unordered_map获取元素4 - unordered_map insert()5 - unordered_map emplace() emplace_hint()6 - unordered_map删除元素7 - unordered_multimapunordered_multimap成员函数8 - unordered_setunordered_set成员函数 0 - 前言 C++ ST

日月既往,不可复追 7113

C++ STL unordered_map容器用法详解

C++ STL 标准库中提供有 4 种无序关联式容器,本节先讲解 unordered_map 容器。unordered_map 容器,直译过来就是"无序 map 容器"的意思。所谓“无序”,指的是 unordered_map 容器不会像 map 容器那样对存储的数据进行排序。换句话说,unordered_map 容器和 map 容器仅有一点不同,即 map 容器中存储的数据是有序的,而 unordered_map 容器中是无序的。

weixin_51710308的博客 3453

C++中unordered_map常用操作

unordered_map的常用操作,初始化,插入,删除,查找

我只钓小鱼的博客 1万+

STL map与Boost unordered_map

今天看到 boost::unordered_map, 它与 stl::map的区别就是,stl::map是按照operator<比较判断元素是否相同,以及比较元素的大小,然后选择合适的位置插入到树中。所以,如果对map进行遍历(中序遍历)的话,输出的结果是有序的。顺序就是按照operator< 定义的大小排序。 而boost::unordered_map是计算元素的Hash值,根据Hash值

orzlzro的专栏 4万+

C++ STL map合集(包括map、multimap、unordered_map、unordered_multimap)

map和set有很多相似的操作,比如其函数部分几乎是一样的,下文还会将一些部分进行比较,文章的排版也和set部分几乎一样,可自行食用~ —>C++ STL set合集(包括set、multiset、unordered_set、unordered_multiset)C++ STL中标准关联容器map, multimap,包括set, multiset,内部采用的就是一种非常高效的平衡检索二叉树:红黑树,也称为RB树(Red-Black Tree)。

非著名程序员博客 1442

STL之unordered_map使用方法

C++标准模板库之无序哈希表,STL之unordered_map使用方法

江天飞鸟的博客 1460
上一篇: STL常用操作:multimap
下一篇: STL常用操作:unordered_multimap
zhuikefeng
博客等级 码龄10年 87粉丝 95原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值
⌂ 换网址