Loading docs/lang/csl/unordered-container.md +9 −1 Original line number Diff line number Diff line Loading @@ -54,7 +54,15 @@ struct my_hash { chrono::steady_clock::now().time_since_epoch().count(); return splitmix64(x + FIXED_RANDOM); } // 针对 std::pair<int, int> 作为主键类型的哈希函数 size_t operator()(pair<uint64_t, uint64_t> x) const { static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count(); return splitmix64(x.first + FIXED_RANDOM) ^ (splitmix64(x.second + FIXED_RANDOM) >> 1); } }; ``` 写完自定义的哈希函数后,就可以通过 `unordered_map<int, int, my_hash> my_map;` 的定义方式将自定义的哈希函数传入容器了。 写完自定义的哈希函数后,就可以通过 `unordered_map<int, int, my_hash> my_map;` 或者 `unordered_map<pair<int, int>, int, my_hash> my_pair_map;` 的定义方式将自定义的哈希函数传入容器了。 Loading
docs/lang/csl/unordered-container.md +9 −1 Original line number Diff line number Diff line Loading @@ -54,7 +54,15 @@ struct my_hash { chrono::steady_clock::now().time_since_epoch().count(); return splitmix64(x + FIXED_RANDOM); } // 针对 std::pair<int, int> 作为主键类型的哈希函数 size_t operator()(pair<uint64_t, uint64_t> x) const { static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count(); return splitmix64(x.first + FIXED_RANDOM) ^ (splitmix64(x.second + FIXED_RANDOM) >> 1); } }; ``` 写完自定义的哈希函数后,就可以通过 `unordered_map<int, int, my_hash> my_map;` 的定义方式将自定义的哈希函数传入容器了。 写完自定义的哈希函数后,就可以通过 `unordered_map<int, int, my_hash> my_map;` 或者 `unordered_map<pair<int, int>, int, my_hash> my_pair_map;` 的定义方式将自定义的哈希函数传入容器了。