mirror of
https://github.com/wolfpld/tracy.git
synced 2024-11-25 23:44:35 +00:00
Add character utilities.
This commit is contained in:
parent
d65d957272
commit
537542f682
53
server/TracyCharUtil.hpp
Executable file
53
server/TracyCharUtil.hpp
Executable file
@ -0,0 +1,53 @@
|
||||
#ifndef __TRACY__CHARUTIL_HPP__
|
||||
#define __TRACY__CHARUTIL_HPP__
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
|
||||
namespace tracy
|
||||
{
|
||||
namespace charutil
|
||||
{
|
||||
|
||||
static inline uint32_t hash( const char* str )
|
||||
{
|
||||
uint32_t hash = 5381;
|
||||
int c;
|
||||
|
||||
while( c = *str++ )
|
||||
{
|
||||
hash = ( ( hash << 5 ) + hash ) ^ c;
|
||||
}
|
||||
|
||||
return hash;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue
Block a user