Added std::hash for String, made use of unordered_map
Former-commit-id: 20f3d12bc3222873706949f0a7d0a131e237a247
This commit is contained in:
@@ -323,4 +323,6 @@ namespace std
|
||||
NAZARA_API void swap(NzString& lhs, NzString& rhs);
|
||||
}
|
||||
|
||||
#include <Nazara/Core/String.inl>
|
||||
|
||||
#endif // NAZARA_STRING_HPP
|
||||
|
||||
33
include/Nazara/Core/String.inl
Normal file
33
include/Nazara/Core/String.inl
Normal 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>
|
||||
Reference in New Issue
Block a user