Map in C++ Standard Template Library (STL)
详情请见:https://www.geeksforgeeks.org/map-associative-containers-the-c-standard-template-library-stl/
List of all functions of Map:
- map insert() in C++ STL– Insert elements with a particular key in the map container. .
- map count() function in C++ STL– Returns the number of matches to element with key value ‘g’ in the map.
- map equal_range() in C++ STL– Returns an iterator of pairs. The pair refers to the bounds of a range that includes all the elements in the container which have a key equivalent to k.
- map erase() function in C++ STL– Used to erase element from the container.
- map rend() function in C++ STL– Returns a reverse iterator pointing to the theoretical element right before the first key-value pair in the map(which is considered its reverse end).
- map rbegin() function in C++ STL– Returns a reverse iterator which points to the last element of the map.
- map find() function in C++ STL– Returns an iterator to the element with key value ‘g’ in the map if found, else returns the iterator to end.
- map crbegin() and crend() function in C++ STL– crbegin() returns a constant reverse iterator referring to the last element in the map container. crend() returns a constant reverse iterator pointing to the theoretical element before the first element in the map.
- map cbegin() and cend() function in C++ STL– cbegin() returns a constant iterator referring to the first element in the map container. cend() returns a constant iterator pointing to the theoretical element that follows last element in the multimap.
- map emplace() in C++ STL– Inserts the key and its element in the map container.
- map max_size() in C++ STL– Returns the maximum number of elements a map container can hold.
- map upper_bound() function in C++ STL– Returns an iterator to the first element that is equivalent to mapped value with key value ‘g’ or definitely will go after the element with key value ‘g’ in the map
- map operator= in C++ STL– Assigns contents of a container to a different container, replacing its current content.
- map lower_bound() function in C++ STL– Returns an iterator to the first element that is equivalent to mapped value with key value ‘g’ or definitely will not go before the element with key value ‘g’ in the map.
- map emplace_hint() function in C++ STL– Inserts the key and its element in the map container with a given hint.
- map value_comp() in C++ STL– Returns the object that determines how the elements in the map are ordered (‘<' by default).
- map key_comp() function in C++ STL– Returns the object that determines how the elements in the map are ordered (‘<' by default).
- map::size() in C++ STL– Returns the number of elements in the map.
- map::empty() in C++ STL– Returns whether the map is empty.
- map::begin() and end() in C++ STL– begin() returns an iterator to the first element in the map. end() returns an iterator to the theoretical element that follows last element in the map
- map::operator[] in C++ STL– This operator is used to reference the element present at position given inside the operator.
- map::clear() in C++ STL– Removes all the elements from the map.
- map::at() and map::swap() in C++ STL– at() function is used to return the reference to the element associated with the key k. swap() function is used to exchange the contents of two maps but the maps must be of same type, although sizes may differ.
P.S. map和set还有无序版本,分别对应头文件<unordered_map>、<unordered_set>
- 具有相同相同哈希值的元素被放在同一个桶(bucket)中。
- Unordered_map vs unordered_set:
在unordered_set中,我们只有键,没有值,这些主要用于查看集合中的存在/不存在。 例如,考虑计算单个单词频率的问题。 我们不能使用unordered_set(或set),因为我们不能存储计数。
- Unordered_map vs map:
Map(类似set)是一个唯一键的有序序列,而unordered_map中的键可以以任何顺序存储,所以unordered。
映射是作为平衡的树结构实现的,这就是为什么可以维护元素之间的顺序(通过特定的树遍历)。 map操作的时间复杂度为O(Log n),而unordered_map的平均时间复杂度为O(1)。
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· Manus的开源复刻OpenManus初探
· AI 智能体引爆开源社区「GitHub 热点速览」
· 从HTTP原因短语缺失研究HTTP/2和HTTP/3的设计差异
· 三行代码完成国际化适配,妙~啊~