std::hash
|
|
このページは、Google 翻訳を使って英語版から機械翻訳されました。
翻訳には誤りや奇妙な言い回しがあるかもしれません。文章の上にポインタをおくと、元の文章が見れます。誤りを修正して翻訳を改善する手助けをしてください。翻訳についての説明は、ここをクリックしてください。 |
| Defined in header <functional>
|
||
| template< class Key > struct hash; // not defined |
(C++11およびそれ以降) | |
You can help to correct and verify the translation. Click here for instructions.
Keyの単一のパラメータを受け入れ.Key.You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
k1とk2等しいこと、std::hash<Key>()(k1) == std::hash<Key>()(k2).k1 and k2 that are equal, std::hash<Key>()(k1) == std::hash<Key>()(k2).You can help to correct and verify the translation. Click here for instructions.
k1とk2等しくないこと、std::hash<Key>()(k1) == std::hash<Key>()(k2)は1.0/std::numeric_limits<size_t>::max()に近づいて、非常に小さい値になるはずである確率.k1 and k2 that are not equal, the probability that std::hash<Key>()(k1) == std::hash<Key>()(k2) should be very small, approaching 1.0/std::numeric_limits<size_t>::max().You can help to correct and verify the translation. Click here for instructions.
CopyConstructibleとDestructibleです.CopyConstructible and Destructible.You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
目次 |
[編集] メンバータイプ
argument_type
|
Key
|
result_type
|
std::size_t |
[編集] メンバ関数
| ハッシュ関数オブジェクトを構築します Original: constructs a hash function object The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (パブリックメンバ関数) | |
| 引数のハッシュを計算します Original: calculate the hash of the argument The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (パブリックメンバ関数) |
[編集] 基本的なタイプの標準の専門分野
| Defined in header <functional>
|
||
| template<> struct hash<bool>; template<> struct hash<char>; |
||
[編集] ライブラリー·タイプのための標準的な特殊化
| (C++11) (C++11) (C++11) (C++11) |
文字列のハッシュをサポートしています Original: hash support for strings The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (クラステンプレートの特殊化の2つの値を比較します) |
| (C++11) |
std::error_codeハッシュをサポート Original: hash support for std::error_code The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (クラステンプレートの特殊化の2つの値を比較します) |
| (C++11) |
std::bitsetハッシュをサポート Original: hash support for std::bitset The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (クラステンプレートの特殊化の2つの値を比較します) |
| (C++11) |
std::unique_ptrハッシュをサポート Original: hash support for std::unique_ptr The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (クラステンプレートの特殊化の2つの値を比較します) |
| (C++11) |
std::shared_ptrハッシュをサポート Original: hash support for std::shared_ptr The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (クラステンプレートの特殊化の2つの値を比較します) |
| (C++11) |
std::type_indexハッシュをサポート Original: hash support for std::type_index The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (クラステンプレートの特殊化の2つの値を比較します) |
| (C++11) |
std::vector<bool>ハッシュをサポート Original: hash support for std::vector<bool> The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (クラステンプレートの特殊化の2つの値を比較します) |
| (C++11) |
std::thread::idハッシュをサポート Original: hash support for std::thread::id The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (クラステンプレートの特殊化の2つの値を比較します) |
[編集] 例
std::string、既にハッシュ専門性を持つ型のハッシュの計算を示しています.
Demonstrates the computation of a hash for std::string, a type that already has a hash specialization.
You can help to correct and verify the translation. Click here for instructions.
#include <iostream> #include <functional> #include <string> int main() { std::string str = "Meet the new boss..."; std::hash<std::string> hash_fn; size_t str_hash = hash_fn(str); std::cout << str_hash << '\n'; }
出力:
391070135
ユーザ定義型のハッシュ関数の作成方法を示します。 std::unordered_map用テンプレートパラメータとしてこれを使用して、std::unordered_setなどもstd::equal_toの専門性を必要とします.
Demonstrates creation of a hash function for a user defined type. Using this as a template parameter for std::unordered_map, std::unordered_set, etc. also requires specialization of std::equal_to.
You can help to correct and verify the translation. Click here for instructions.
#include <iostream> #include <functional> #include <string> struct S { std::string first_name; std::string last_name; }; template<class T> class MyHash; template<> class MyHash<S> { public: size_t operator()(const S &s) const { size_t h1 = std::hash<std::string>()(s.first_name); size_t h2 = std::hash<std::string>()(s.last_name); return h1 ^ (h2 << 1); } }; int main() { std::string s1 = "Hubert"; std::string s2 = "Farnsworth"; std::hash<std::string> h1; S n1; n1.first_name = s1; n1.last_name = s2; std::cout << "hash(s1) = " << h1(s1) << "\n" << "hash(s2) = " << std::hash<std::string>()(s2) << "\n" << "hash(n1) = " << MyHash<S>()(n1) << "\n"; }
出力:
hash(s1) = 6119893563398376542 hash(s2) = 14988020022735710972 hash(n1) = 17649170831080298918
ユーザー定義型のstd::hashを特化する方法を示しています.
Demonstrates how to specialize std::hash for a user defined type.
You can help to correct and verify the translation. Click here for instructions.
#include <iostream> #include <functional> #include <string> struct S { std::string first_name; std::string last_name; }; namespace std { template<> class hash<S> { public: size_t operator()(const S &s) const { size_t h1 = std::hash<std::string>()(s.first_name); size_t h2 = std::hash<std::string>()(s.last_name); return h1 ^ ( h2 << 1 ); } }; } int main() { S s; s.first_name = "Bender"; s.last_name = "Rodriguez"; std::hash<S> hash_fn; std::cout << "hash(s) = " << hash_fn(s) << "\n"; }
出力:
hash(s) = 32902390710

