Kelas hash
Menghitung kode hash untuk nilai.
Sintaks
template <class Ty>
struct hash {
size_t operator()(Ty val) const;
};
Keterangan
Objek fungsi mendefinisikan fungsi hash, cocok untuk nilai pemetaan jenis Ty ke distribusi nilai indeks. Anggota operator()
mengembalikan kode hash untuk val, cocok untuk digunakan dengan templat unordered_map
kelas , , unordered_multimap
unordered_set
, dan unordered_multiset
. Pustaka standar menyediakan spesialisasi untuk jenis dasar: Ty mungkin jenis skalar apa pun, termasuk jenis penunjuk dan jenis enumerasi. Selain itu, ada spesialisasi untuk jenis string
pustaka , , , wstring
, u16string
, u16string_view
wstring_view
u32string
string_view
, u32string_view
, bitset
, optional
error_code
error_condition
, shared_ptr
, , thread
, , type_index
, , unique_ptr
, variant
dan .vector<bool>
Contoh
// std__functional__hash.cpp
// compile with: /EHsc
#include <functional>
#include <iostream>
#include <unordered_set>
int main()
{
std::unordered_set<int, std::hash<int> > c0;
c0.insert(3);
std::cout << *c0.find(3) << std::endl;
return (0);
}
3
Persyaratan
Header:<functional>
Namespace: std
Lihat juga
<unordered_map>
Kelas unordered_multimap
Kelas unordered_multiset
<unordered_set>