Welcome to mirror list, hosted at ThFree Co, Russian Federation.

TracyCharUtil.hpp « server - github.com/wolfpld/tracy.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: f96f9ec56ac3feb7eeb1f9080c7de56cdf1c0206 (plain)
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
#ifndef __TRACY__CHARUTIL_HPP__
#define __TRACY__CHARUTIL_HPP__

#include <stddef.h>
#include <stdint.h>
#include <string.h>

#define XXH_INLINE_ALL
#include "tracy_xxhash.h"

namespace tracy
{
namespace charutil
{

static inline size_t hash( const char* str )
{
    const auto sz = strlen( str );
    return XXH3_64bits( str, sz );
}

static inline size_t hash( const char* str, size_t sz )
{
    return XXH3_64bits( str, sz );
}

struct Hasher
{
    size_t operator()( const char* key ) const
    {
        return hash( key );
    }
};

struct Comparator
{
    bool operator()( const char* lhs, const char* rhs ) const
    {
        return strcmp( lhs, rhs ) == 0;
    }
};

struct LessComparator
{
    bool operator()( const char* lhs, const char* rhs ) const
    {
        return strcmp( lhs, rhs ) < 0;
    }
};

struct StringKey
{
    const char* ptr;
    size_t sz;

    struct Hasher
    {
        size_t operator()( const StringKey& key ) const
        {
            return hash( key.ptr, key.sz );
        }
    };

    struct Comparator
    {
        bool operator()( const StringKey& lhs, const StringKey& rhs ) const
        {
            return lhs.sz == rhs.sz && memcmp( lhs.ptr, rhs.ptr, lhs.sz ) == 0;
        }
    };
};

}
}

#endif