unordered_map
注:
- *标记的为c++11新特性,构造函数默认为c++11
- 函数原型省略了一些细节,只展示实际需要填写的情况(分配器已经隐藏了,需要可以去c++reference查看)
- 参数栏表示传入的两个参数的意义而不是类型
- 返回值栏表示类型而不是意义
- 粉红色表示为c++11新特性
- 参数若标黄,则可以不填
- unordered_map 以下简称um
构造方法
方法(method) | 原型(prototype) | 参数(param) | 返回值(return) | 功能(function) |
---|---|---|---|---|
构造函数 | explicit unordered_map ( size_type n = /* see below */,const hasher& hf = hasher(),const key_equal& eql = key_equal(),const allocator_type& alloc = allocator_type() ); | 空间数量n,哈希函数对象hf,比较函数对象eql,分配器alloc | default | 构建一个空间大小为n,哈希方法为hf,比较方法为eql的unordered_map |
构造函数 | explicit unordered_map ( const allocator_type& alloc ); | 分配器alloc | default | 构建一个unordered_map |
构造函数 | unordered_map ( InputIterator first, InputIterator last,size_type n = /* see below */,const hasher& hf = hasher(),const key_equal& eql = key_equal(), const allocator_type& alloc = allocator_type() ); | 指向开始的迭代器first,指向结束的迭代器last,空间大小n,哈希函数对象hf,比较器函数对象eql,分配器alloc | default | 构建一个空间大小为n,哈希方法为hf,比较方法为eql,内容为从first开始到last结束的元素的拷贝的unordered_map |
构造函数 | unordered_map ( const unordered_map& ump ); | 需要拷贝的um的引用ump | default | 构建一个unordered_map,内容与ump相同 |
构造函数 | unordered_map ( const unordered_map& ump, const allocator_type& alloc ); | 需要拷贝的um的引用ump,分配器alloc | default | 构建一个unordered_map,内容与ump相同 |
构造函数 | unordered_map ( unordered_map&& ump ); | 需要拷贝的um的引用的引用ump | default | 构建一个unordered_map,内容与ump相同 |
构造函数 | unordered_map ( unordered_map&& ump, const allocator_type& alloc ); | 需要拷贝的um的引用的引用ump,分配器alloc | default | 构建一个unordered_map,内容与ump相同 |
构造函数 | unordered_map ( initializer_list<value_type> il,size_type n = /* see below */,const hasher& hf = hasher(),const key_equal& eql = key_equal(), const allocator_type& alloc = allocator_type() ); | 已经初始化的列表il,空间数量n,哈希函数对象hf,比较函数对象eql,分配器alloc | default | 构建一个空间大小为n,哈希方法为hf,比较方法为eql,内容为与il内容相同的unordered_map |
析构函数 | ~unordered_map(); | N/A | default | 销毁unordered_map |
重载= | unordered_map& operator= ( const unordered_map& ump ); | 需要赋值的um的引用ump | um的引用 | 执行复制赋值,将ump的所有元素复制到容器对象中 |
重载= | unordered_map& operator= ( unordered_map&& ump ); | 需要赋值的um的引用的引用ump | um的引用 | 执行移动分配,将ump内容的所有权转移给对象。 |
重载= | unordered_map& operator= ( intitializer_list<value_type> il ); | 需要赋值的已经初始化的列表 | um的引用 | 将初始值设定项列表il的内容指定为容器对象的元素。 |
容量方法
方法(method) | 原型(prototype) | 参数(param) | 返回值(return) | 功能(function) |
---|---|---|---|---|
empty | bool empty() const noexcept; | N/A | 布尔值 | 返回是否为空 |
size | size_type size() const noexcept; | N/A | 非负整数 | 返回元素的数量 |
max_size | size_type max_size() const noexcept; | N/A | 非负整数 | 返回能容纳的最大元素数量 |
迭代器方法
方法(method) | 原型(prototype) | 参数(param) | 返回值(return) | 功能(function) |
---|---|---|---|---|
begin | iterator begin() noexcept; | N/A | 迭代器 | 返回指向第一个元素的迭代器 |
begin | const_iterator begin() const noexcept; | N/A | 迭代器 | 返回指向第一个元素的迭代器 |
begin | local_iterator begin ( size_type n ); | 位置n | 迭代器 | 返回指向第一个元素的桶迭代器 |
begin | const_local_iterator begin ( size_type n ) const; | 位置n | 迭代器 | 返回指向第一个元素的桶迭代器 |
end | iterator end() noexcept; | N/A | 迭代器 | 返回指向最后一个元素的下一个位置的迭代器 |
end | const_iterator end() const noexcept; | N/A | 迭代器 | 返回指向最后一个元素的下一个位置的迭代器 |
end | local_iterator end (size_type n); | 位置n | 迭代器 | 返回指向最后一个元素的下一个位置的桶迭代器 |
end | const_local_iterator end (size_type n) const; | 位置n | 迭代器 | 返回指向最后一个元素的下一个位置的桶迭代器 |
cbegin | const_iterator cbegin() const noexcept; | N/A | 迭代器 | 返回指向最后一个元素的的迭代器 |
cbegin | const_local_iterator cbegin ( size_type n ) const; | 位置n | 迭代器 | 返回指向最后一个元素的的桶迭代器 |
cend | const_iterator cend() const noexcept; | N/A | 迭代器 | 返回指向第一个元素的前一个的迭代器 |
cend | const_local_iterator cend ( size_type n ) const; | 位置n | 迭代器 | 返回指向第一个元素的前一个的桶迭代器 |
元素访问方法
方法(method) | 原型(prototype) | 参数(param) | 返回值(return) | 功能(function) |
---|---|---|---|---|
重载[] | mapped_type& operator[] ( const key_type& k ); | key索引的引用k | 映射元素类型 | 返回key对应的值 |
重载[] | mapped_type& operator[] ( key_type&& k ); | key索引的引用的引用k | 映射元素类型 | 返回key对应的值 |
at | mapped_type& at ( const key_type& k ); | key索引的引用k | 映射元素类型 | 返回key对应的值 |
at | const mapped_type& at ( const key_type& k ) const; | key索引的引用的引用k | 映射元素类型 | 返回key对应的值 |
元素查找方法
方法(method) | 原型(prototype) | 参数(param) | 返回值(return) | 功能(function) |
---|---|---|---|---|
find | iterator find ( const key_type& k ); | 索引的引用k | 迭代器 | 返回k对应的位置的迭代器 |
find | const_iterator find ( const key_type& k ) const; | 索引的引用k | 迭代器 | 返回k对应的位置的迭代器 |
count | size_type count ( const key_type& k ) const; | 索引的引用k | 非负整数 | 返回索引为k的值数量 |
equal_range | pair<iterator,iterator> equal_range ( const key_type& k ); | 索引的引用k | 一个包含两个迭代器pair | 返回包含索引为key的所有值的迭代器对 |
equal_range | pair<const_iterator,const_iterator> equal_range ( const key_type& k ) const; | 索引的引用k | 一个包含两个迭代器pair | 返回包含索引为key的所有值的迭代器对 |
编辑方法
方法(method) | 原型(prototype) | 参数(param) | 返回值(return) | 功能(function) |
---|---|---|---|---|
emplace | pair<iterator, bool> emplace ( Args&&... args ); | 参数args…… | 一个包含iterator与bool的pair | (构造性的)插入(n个)参数 |
emplace_hint | iterator emplace_hint ( const_iterator position, Args&&... args ); | 表示位置的迭代器position,参数args…… | 迭代器 | (构造性的)在position位置插入(n个)参数 |
insert | pair<iterator,bool> insert ( const value_type& val ); | 插入值val | 一个包含iterator与bool的pair | 插入一个值val |
insert | pair<iterator,bool> insert ( P&& val ); | 插入值val | 一个包含iterator与bool的pair | 插入一个值val |
insert | iterator insert ( const_iterator hint, P&& val ); | 插入位置hint,值val | 迭代器 | 插入一个值val |
insert | void insert ( InputIterator first, InputIterator last ); | 指向开头的迭代器first,指向结尾的迭代器last | 无 | 将first到last中间的元素插入um容器 |
insert | void insert ( initializer_list<value_type> il ); | 已经初始化的列表il | 无 | 将一个已经初始化的列表的元素插入um |
erase | iterator erase ( const_iterator position ); | 表示擦除位置的迭代器position | 迭代器 | 将position位置的元素擦除 |
erase | size_type erase ( const key_type& k ); | 值val | 非负整数 | 将键为k的位置擦除 |
erase | iterator erase ( const_iterator first, const_iterator last ); | 指向开头的迭代器first,指向结尾的迭代器last | 迭代器 | 将first与last之间的内容擦除 |
clear | void clear() noexcept; | N/A | 无 | 清空容器 |
swap | void swap ( unordered_map& ump ); | 交换的um的引用 ump | 无 | 将容器的内容与ump中的内容交换 |
桶方法
方法(method) | 原型(prototype) | 参数(param) | 返回值(return) | 功能(function) |
---|---|---|---|---|
bucket_count | size_type bucket_count() const noexcept; | N/A | 非负整数 | 返回um中的桶数 |
max_bucket_count | size_type max_bucket_count() const noexcept; | N/A | 非负整数 | 返回容器中可以保存的最大桶数 |
bucket_size | size_type bucket_size ( size_type n ) const; | 值的类型n | 非负整数 | 在桶n中的数量 |
bucket | size_type bucket ( const key_type& k ) const; | 键的类型k | 非负整数 | 返回k所在的桶的编号 |
哈希策略方法
方法(method) | 原型(prototype) | 参数(param) | 返回值(return) | 功能(function) |
---|---|---|---|---|
load_factor | float load_factor() const noexcept; | N/A | 浮点数 | 返回容器的负载系数(负载系数 = 大小/ 桶数) |
max_load_factor | float max_load_factor() const noexcept; | N/A | 浮点数 | 返回容器的当前最大负载系数 |
max_load_factor | void max_load_factor ( float z ); | 新的最大负载系数z | 无 | 将z设置为无序_映射容器的新最大负载因子 |
rehash | void rehash( size_type n ); | 哈希表的最小存储桶数n | 无 | 将容器中的桶数设置为n或更多 |
reserve | void reserve ( size_type n ); | 容器请求的最小数量 | 无 | 将容器中的存储桶数设置为最适合包含至少n个元素的存储桶数 |
观测方法
方法(method) | 原型(prototype) | 参数(param) | 返回值(return) | 功能(function) |
---|---|---|---|---|
hash_function | hasher hash_function() const; | N/A | 哈希函数对象 | 返回容器使用的哈希函数对象 |
key_eq | key_equal key_eq() const; | N/A | 比较函数对象 | 返回容器使用的键比较函数对象 |
get_allocator | allocator_type get_allocator() const noexcept; | N/A | 构造器 | 返回分配器 |