File: hash_func.h

package info (click to toggle)
libcds 2.3.3-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye
  • size: 15,564 kB
  • sloc: cpp: 135,002; ansic: 7,218; perl: 243; sh: 237; makefile: 6
file content (114 lines) | stat: -rw-r--r-- 2,918 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
// Copyright (c) 2006-2018 Maxim Khizhinsky
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE or copy at http://www.boost.org/LICENSE_1_0.txt)

#ifndef CDSUNIT_HASH_FUNC_H
#define CDSUNIT_HASH_FUNC_H

#include <cds/details/defs.h>

#if CDS_BUILD_BITS == 64
#   include <cds_test/city.h>
#endif

namespace cds_test {

#if CDS_BUILD_BITS == 64
    class city32 {
    public:
        typedef uint32_t hash_type;
        typedef hash_type result_type;

        hash_type operator()( void const * pBuf, size_t len ) const
        {
            return CityHash32( reinterpret_cast<char const *>( pBuf ), len );
        }

        hash_type operator()( std::string const& s ) const
        {
            return CityHash32( s.c_str(), s.length());
        }

        template <typename T>
        hash_type operator()( T const& s ) const
        {
            return CityHash32( reinterpret_cast<char const *>( &s ), sizeof(s));
        }

        struct less
        {
            bool operator()( hash_type lhs, hash_type rhs ) const
            {
                return lhs < rhs;
            }
        };
    };

    class city64 {
    public:
        typedef uint64_t hash_type;
        typedef hash_type result_type;

        hash_type operator()( void const * pBuf, size_t len ) const
        {
            return CityHash64( reinterpret_cast<char const *>( pBuf ), len );
        }

        hash_type operator()( std::string const& s ) const
        {
            return CityHash64( s.c_str(), s.length());
        }

        template <typename T>
        hash_type operator()( T const& s ) const
        {
            return CityHash64( reinterpret_cast<char const *>( &s ), sizeof(s));
        }

        struct less
        {
            bool operator()( hash_type lhs, hash_type rhs ) const
            {
                return lhs < rhs;
            }
        };
    };

    class city128 {
    public:
        typedef uint128 hash_type;
        typedef hash_type result_type;

        hash_type operator()( void const * pBuf, size_t len ) const
        {
            return CityHash128( reinterpret_cast<char const *>( pBuf ), len );
        }

        hash_type operator()( std::string const& s ) const
        {
            return CityHash128( s.c_str(), s.length());
        }

        template <typename T>
        hash_type operator()( T const& s ) const
        {
            return CityHash128( reinterpret_cast<char const *>( &s ), sizeof(s));
        }

        struct less
        {
            bool operator()( hash_type const& lhs, hash_type const& rhs ) const
            {
                if ( lhs.first != rhs.first )
                    return lhs.second < rhs.second;
                return lhs.first < rhs.first;
            }
        };
    };
#endif // #if CDS_BUILD_BITS == 64


} // namespace cds_test

#endif // #ifndef CDSUNIT_HASH_FUNC_H