2017-09-27 00:35:59 +00:00
|
|
|
#ifndef __TRACY__CHARUTIL_HPP__
|
|
|
|
#define __TRACY__CHARUTIL_HPP__
|
|
|
|
|
|
|
|
#include <stddef.h>
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
2019-11-07 22:52:52 +00:00
|
|
|
#define XXH_STATIC_LINKING_ONLY
|
|
|
|
#include "tracy_xxh3.h"
|
2018-03-23 20:12:29 +00:00
|
|
|
|
2017-09-27 00:35:59 +00:00
|
|
|
namespace tracy
|
|
|
|
{
|
|
|
|
namespace charutil
|
|
|
|
{
|
|
|
|
|
2019-11-07 22:52:52 +00:00
|
|
|
static inline size_t hash( const char* str )
|
2017-09-27 00:35:59 +00:00
|
|
|
{
|
2019-11-07 22:52:52 +00:00
|
|
|
const auto sz = strlen( str );
|
|
|
|
return XXH3_64bits( str, sz );
|
2017-09-27 00:35:59 +00:00
|
|
|
}
|
|
|
|
|
2019-11-07 22:52:52 +00:00
|
|
|
static inline size_t hash( const char* str, size_t sz )
|
2017-11-11 01:31:51 +00:00
|
|
|
{
|
2019-11-07 22:52:52 +00:00
|
|
|
return XXH3_64bits( str, sz );
|
2017-11-11 01:31:51 +00:00
|
|
|
}
|
|
|
|
|
2017-09-27 00:35:59 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2019-02-12 19:23:01 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2017-09-27 00:35:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|