#ifndef StringHash_h
#define StringHash_h
#include "wtf/text/AtomicString.h"
#include "wtf/HashTraits.h"
#include "wtf/StringHasher.h"
namespace WTF {
inline bool HashTraits<String>::isEmptyValue(const String& value)
{
return value.isNull();
}
struct StringHash {
static unsigned hash(StringImpl* key) { return key->hash(); }
static inline bool equal(const StringImpl* a, const StringImpl* b)
{
return equalNonNull(a, b);
}
static unsigned hash(const RefPtr<StringImpl>& key) { return key->hash(); }
static bool equal(const RefPtr<StringImpl>& a, const RefPtr<StringImpl>& b)
{
return equal(a.get(), b.get());
}
static unsigned hash(const String& key) { return key.impl()->hash(); }
static bool equal(const String& a, const String& b)
{
return equal(a.impl(), b.impl());
}
static const bool safeToCompareToEmptyOrDeleted = false;
};
class CaseFoldingHash {
public:
template<typename T> static inline UChar foldCase(T ch)
{
return WTF::Unicode::foldCase(ch);
}
static unsigned hash(const UChar* data, unsigned length)
{
return StringHasher::computeHashAndMaskTop8Bits<UChar, foldCase<UChar> >(data, length);
}
static unsigned hash(StringImpl* str)
{
if (str->is8Bit())
return hash(str->characters8(), str->length());
return hash(str->characters16(), str->length());
}
static unsigned hash(const LChar* data, unsigned length)
{
return StringHasher::computeHashAndMaskTop8Bits<LChar, foldCase<LChar> >(data, length);
}
static inline unsigned hash(const char* data, unsigned length)
{
return CaseFoldingHash::hash(reinterpret_cast<const LChar*>(data), length);
}
static inline bool equal(const StringImpl* a, const StringImpl* b)
{
return equalIgnoringCaseNonNull(a, b);
}
static unsigned hash(const RefPtr<StringImpl>& key)
{
return hash(key.get());
}
static bool equal(const RefPtr<StringImpl>& a, const RefPtr<StringImpl>& b)
{
return equal(a.get(), b.get());
}
static unsigned hash(const String& key)
{
return hash(key.impl());
}
static unsigned hash(const AtomicString& key)
{
return hash(key.impl());
}
static bool equal(const String& a, const String& b)
{
return equal(a.impl(), b.impl());
}
static bool equal(const AtomicString& a, const AtomicString& b)
{
return (a == b) || equal(a.impl(), b.impl());
}
static const bool safeToCompareToEmptyOrDeleted = false;
};
struct AlreadyHashed : IntHash<unsigned> {
static unsigned hash(unsigned key) { return key; }
static unsigned avoidDeletedValue(unsigned hash)
{
ASSERT(hash);
unsigned newHash = hash | (!(hash + 1) << 31);
ASSERT(newHash);
ASSERT(newHash != 0xFFFFFFFF);
return newHash;
}
};
}
using WTF::AlreadyHashed;
using WTF::CaseFoldingHash;
using WTF::StringHash;
#endif