So You Think You Can Hashmy_type); return static_cast(hasher); } OK, but how do I stick this into a std::unordered_set/map ?2024 Victor Ciura | @ciura_victor - Unleashing 🦀 The Ferris Within 47 GenericHash hasher; hash_append(hasher, t); return static_cast (hasher); } }; std::unordered_set > my_set;2024 Victor Ciura | @ciura_victor - Unleashing 🦀 The etc. std::unordered_set > my_set; std::unordered_set > my_set; std::unordered_set > my_set; std::unordered_set > 0 码力 | 119 页 | 6.54 MB | 6 月前3
Back to Basics Conceptscoll, const T& val) { coll.push_back(val); } std::vectorcoll1; std::set coll2;std::unordered_set uset; add(coll1, 42); // OK add(coll2, 42); // ERROR: no push_back() C++98 Nico T> void add(CollT& coll, const T& val) { coll.push_back(val); } std::vector coll; std::unordered_set add(coll, 42); // OK add(u 42); // uses 2nd add() calling insert() C++98 Nico Josuttis void add(auto& coll, const auto& val) { coll.push_back(val); } std::vector coll; std::unordered_set u; add(coll, 42); // OK add(us, 42); // uses 2nd add() calling insert() "Abbreviated 0 码力 | 23 页 | 2.14 MB | 6 月前3
Back to Basics: Classic 9STLset • multimap • multiset 21 • Unordered associative containers • unordered_map (C++11) • unordered_set (C++11) • unordered_multimap (C++11) • unordered_multiset (C++11) • Container adaptors • queue where an element's position is irrelevant • Implemented using hash tables • unordered_map, unordered_set, unordered_multimap, unordered_multiset 47CppCon 2021 – Back to Basics: Classic STL Copyright class Hash = hash, class Pred = equal_to , class Allocator = allocator > class unordered_set; • Features • Supports amortized constant time element lookup • Elements of type Key are stored 0 码力 | 75 页 | 603.36 KB | 6 月前3
Back to Basics: Lambdascriterion / hash function type (since C++20) ##includeJoratexit () ##include <unordered_set> int main() { ata: :atexit(T OUT Jambda to be called on regular 站 auto hashFunc = [] (const autog obj) { /lambdato be used as hashfunction return 有 std: :unordered_set coll GE 0 码力 | 17 页 | 935.72 KB | 6 月前3
Design Patterns: Facts and Misconceptionsclass KeyEqual = std::equal_to, class Allocator = std::allocator > class unordered_set; template< class T, class Deleter = std::default_delete > class unique_ptr;2. The 0 码力 | 88 页 | 17.31 MB | 6 月前3
Hello 算法 1.2.0 简体中文 C++ 版graphBFS(GraphAdjList &graph, Vertex *startVet) { // 顶点遍历序列 vectorres; // 哈希集合,用于记录已被访问过的顶点 unordered_set visited = {startVet}; // 队列用于实现 BFS queue que; que.push(startVet); // 来记录已被访问的顶点,以避免重复访问顶点。 // === File: graph_dfs.cpp === /* 深度优先遍历辅助函数 */ void dfs(GraphAdjList &graph, unordered_set &visited, vector &res, Vertex *vet) { res.push_back(vet); // 记录访问顶点 visited graphDFS(GraphAdjList &graph, Vertex *startVet) { // 顶点遍历序列 vector res; // 哈希集合,用于记录已被访问过的顶点 unordered_set visited; dfs(graph, visited, res, startVet); return res; } 深度优先遍历的算法流程如图 9‑12 所示。 0 码力 | 379 页 | 18.48 MB | 10 月前3
Hello 算法 1.2.0 繁体中文 C++ 版graphBFS(GraphAdjList &graph, Vertex *startVet) { // 頂點走訪序列 vectorres; // 雜湊集合,用於記錄已被訪問過的頂點 unordered_set visited = {startVet}; // 佇列用於實現 BFS queue que; que.push(startVet); // 來記錄已被訪問的頂點,以避免重複訪問頂點。 // === File: graph_dfs.cpp === /* 深度優先走訪輔助函式 */ void dfs(GraphAdjList &graph, unordered_set &visited, vector &res, Vertex *vet) { res.push_back(vet); // 記錄訪問頂點 visited graphDFS(GraphAdjList &graph, Vertex *startVet) { // 頂點走訪序列 vector res; // 雜湊集合,用於記錄已被訪問過的頂點 unordered_set visited; dfs(graph, visited, res, startVet); return res; } 深度優先走訪的演算法流程如圖 9‑12 所示。 0 码力 | 379 页 | 18.79 MB | 10 月前3
共 7 条
- 1













