skip to content
Ivan's wiki
Site Tools
Search
Tools
Show pagesource
Backlinks
Recent Changes
Media Manager
Sitemap
>
Recent Changes
Media Manager
Sitemap
hpp-unordered-map
This page is read only. You can view the source, but not change it.
# <unordered_map> **[<unordered_map>](https://en.cppreference.com/w/cpp/header/unordered_map)** is a hash table of key-value pairs with O(1) average insertion, deletion, and lookup. Keys are unordered, but you can iterate and access by key quickly. Use `unordered_map` when you need fast lookup by key; use `std::map` if you need sorted order. This example uses an unordered_map to count word frequencies, demonstrating fast insertion and lookup without order guarantees. ```cpp // compile: g++ -std=c++11 -o unorderedmapexample unorderedmapexample.cpp // run: ./unorderedmapexample // description: hash table map operations #include <unordered_map> #include <iostream> #include <string> int main() { std::unordered_map<std::string, int> count; count["apple"]++; count["banana"]++; count["apple"]++; for (const auto& [fruit, num] : count) { std::cout << fruit << ": " << num << "\n"; } std::cout << "apple count: " << count["apple"] << "\n"; return 0; } ```
Page Tools
Show pagesource
Backlinks
Back to top