Unverified Commit 11e1a5ef authored by Nano's avatar Nano Committed by GitHub
Browse files

Merge pull request #2644 from H-Shen/patch-4

Update unordered-container.md
parents 0fd28d33 26b8a73c
Loading
Loading
Loading
Loading
+9 −1
Original line number Diff line number Diff line
@@ -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;` 的定义方式将自定义的哈希函数传入容器了。