mirror of
https://github.com/ETLCPP/etl.git
synced 2026-06-29 13:58:44 +08:00
Added hash functions for strings.
This commit is contained in:
parent
1171d7e555
commit
ae2e4609b2
17
src/string.h
17
src/string.h
@ -33,6 +33,7 @@ SOFTWARE.
|
||||
|
||||
#include "platform.h"
|
||||
#include "basic_string.h"
|
||||
#include "hash.h"
|
||||
|
||||
#if defined(ETL_COMPILER_MICROSOFT)
|
||||
#undef min
|
||||
@ -180,6 +181,22 @@ namespace etl
|
||||
|
||||
value_type buffer[MAX_SIZE + 1];
|
||||
};
|
||||
|
||||
//***************************************************************************
|
||||
/// Specialisation for string.
|
||||
///\ingroup hash
|
||||
//***************************************************************************
|
||||
template <>
|
||||
struct hash <string>
|
||||
{
|
||||
size_t operator ()(const string& s) const
|
||||
{
|
||||
uint8_t* p_begin = &s[0];
|
||||
uint8_t* p_end = &s[s.size()];
|
||||
|
||||
return etl::__private_hash__::generic_hash(p_begin, p_end);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
#if defined(ETL_COMPILER_MICROSOFT)
|
||||
|
||||
@ -33,6 +33,7 @@ SOFTWARE.
|
||||
|
||||
#include "platform.h"
|
||||
#include "basic_string.h"
|
||||
#include "hash.h"
|
||||
|
||||
#if defined(ETL_COMPILER_MICROSOFT)
|
||||
#undef min
|
||||
@ -180,6 +181,22 @@ namespace etl
|
||||
|
||||
value_type buffer[MAX_SIZE + 1];
|
||||
};
|
||||
|
||||
//***************************************************************************
|
||||
/// Specialisation for u16string.
|
||||
///\ingroup hash
|
||||
//***************************************************************************
|
||||
template <>
|
||||
struct hash <u16string>
|
||||
{
|
||||
size_t operator ()(const u16string& s) const
|
||||
{
|
||||
uint8_t* p_begin = &s[0];
|
||||
uint8_t* p_end = &s[s.size()];
|
||||
|
||||
return etl::__private_hash__::generic_hash(p_begin, p_end);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
#if defined(ETL_COMPILER_MICROSOFT)
|
||||
|
||||
@ -33,6 +33,7 @@ SOFTWARE.
|
||||
|
||||
#include "platform.h"
|
||||
#include "basic_string.h"
|
||||
#include "hash.h"
|
||||
|
||||
#if defined(ETL_COMPILER_MICROSOFT)
|
||||
#undef min
|
||||
@ -180,6 +181,22 @@ namespace etl
|
||||
|
||||
value_type buffer[MAX_SIZE + 1];
|
||||
};
|
||||
|
||||
//***************************************************************************
|
||||
/// Specialisation for u32string.
|
||||
///\ingroup hash
|
||||
//***************************************************************************
|
||||
template <>
|
||||
struct hash <u32string>
|
||||
{
|
||||
size_t operator ()(const u32string& s) const
|
||||
{
|
||||
uint8_t* p_begin = &s[0];
|
||||
uint8_t* p_end = &s[s.size()];
|
||||
|
||||
return etl::__private_hash__::generic_hash(p_begin, p_end);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
#if defined(ETL_COMPILER_MICROSOFT)
|
||||
|
||||
@ -33,6 +33,7 @@ SOFTWARE.
|
||||
|
||||
#include "platform.h"
|
||||
#include "basic_string.h"
|
||||
#include "hash.h"
|
||||
|
||||
#if defined(ETL_COMPILER_MICROSOFT)
|
||||
#undef min
|
||||
@ -181,6 +182,22 @@ namespace etl
|
||||
|
||||
value_type buffer[MAX_SIZE + 1];
|
||||
};
|
||||
|
||||
//***************************************************************************
|
||||
/// Specialisation for wstring.
|
||||
///\ingroup hash
|
||||
//***************************************************************************
|
||||
template <>
|
||||
struct hash <wstring>
|
||||
{
|
||||
size_t operator ()(const wstring& s) const
|
||||
{
|
||||
uint8_t* p_begin = &s[0];
|
||||
uint8_t* p_end = &s[s.size()];
|
||||
|
||||
return etl::__private_hash__::generic_hash(p_begin, p_end);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
#if defined(ETL_COMPILER_MICROSOFT)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user