zoukankan      html  css  js  c++  java
  • 自定义类型hash

     1 struct LogEventKey
     2 {
     3     LogEventId nId = 0;   // 事件Id
     4     LogEventTag nTag = 0; // 事件Tag
     5 
     6     bool operator==(const LogEventKey& rhs) const {
     7         return nId == rhs.nId && nTag == rhs.nTag;
     8     }
     9     bool operator<(const LogEventKey& rhs) const {
    10         return nId < rhs.nId || (nId == rhs.nId && nTag < rhs.nTag);
    11     }
    12     bool operator<=(const LogEventKey& rhs) const {
    13         return (*this == rhs) || (*this < rhs);
    14     }
    15     bool operator>(const LogEventKey& rhs) const {
    16         return !(*this <= rhs);
    17     }
    18     bool operator>=(const LogEventKey& rhs) const {
    19         return !(*this < rhs);
    20     }
    21     bool operator!=(const LogEventKey& rhs) const {
    22         return !(*this == rhs);
    23     }
    24     
    25 };//struct LogEventKey
    26 
    27 
    28 namespace std {
    29 
    30     template<>
    31     struct hash<LogEventKey>
    32     {
    33         std::size_t operator()(const LogEventKey& key) const {
    34             using std::size_t;
    35             using std::hash;
    36             using std::string;
    37 
    38             // Compute individual hash values for first,
    39             // second and third and combine them using XOR
    40             // and bit shifting:
    41 
    42             return ((hash<LogEventId>()(key.nId)
    43                    ^ (hash<LogEventTag>()(key.nTag) << 1)) >> 1);
    44         }
    45     };
    46 
    47 }
    === [Author: jacc.kim] & [e-mail: 175246359@qq.com] ===
  • 相关阅读:
    [转]IDEA 新建 JSP 项目时
    [转] AForge.NET 图像处理类
    [转] 端口被占用的处理
    [极客大挑战 2019]PHP
    今天鸽了
    [ZJCTF 2019]NiZhuanSiWei
    [极客大挑战 2019]Secret File
    [SUCTF 2019]Pythonginx
    [CISCN2019 华北赛区 Day1 Web2]ikun
    [极客大挑战 2019]EasySQL
  • 原文地址:https://www.cnblogs.com/tongy0/p/15046143.html
Copyright © 2011-2022 走看看