Added std::hash for String, made use of unordered_map

Former-commit-id: 20f3d12bc3222873706949f0a7d0a131e237a247
This commit is contained in:
Lynix
2013-06-23 16:53:37 +02:00
parent 3e82794b70
commit 3609f31708
9 changed files with 51 additions and 15 deletions

View File

@@ -323,4 +323,6 @@ namespace std
NAZARA_API void swap(NzString& lhs, NzString& rhs);
}
#include <Nazara/Core/String.inl>
#endif // NAZARA_STRING_HPP

View File

@@ -0,0 +1,33 @@
// Copyright (C) 2013 Jérôme Leclercq
// This file is part of the "Nazara Engine - Core module"
// For conditions of distribution and use, see copyright notice in Config.hpp
#include <Nazara/Core/Debug.hpp>
namespace std
{
template<>
struct hash<NzString>
{
public:
size_t operator()(const NzString& str) const
{
// Algorithme DJB2
// http://www.cse.yorku.ca/~oz/hash.html
size_t h = 5381;
if (!str.IsEmpty())
{
const char* ptr = str.GetConstBuffer();
do
h = ((h << 5) + h) + *ptr;
while (*++ptr);
}
return h;
}
};
}
#include <Nazara/Core/DebugOff.hpp>