2016-03-27 11:49:47 +02:00
|
|
|
/*
|
|
|
|
===========================================================================
|
|
|
|
Copyright (C) 2015 the OpenMoHAA team
|
|
|
|
|
|
|
|
This file is part of OpenMoHAA source code.
|
|
|
|
|
|
|
|
OpenMoHAA source code is free software; you can redistribute it
|
|
|
|
and/or modify it under the terms of the GNU General Public License as
|
|
|
|
published by the Free Software Foundation; either version 2 of the License,
|
|
|
|
or (at your option) any later version.
|
|
|
|
|
|
|
|
OpenMoHAA source code is distributed in the hope that it will be
|
|
|
|
useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with OpenMoHAA source code; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
===========================================================================
|
|
|
|
*/
|
|
|
|
|
|
|
|
// con_set.cpp: C++ map/set classes
|
|
|
|
|
2023-01-29 20:59:31 +01:00
|
|
|
#include "con_set.h"
|
|
|
|
#include "short3.h"
|
|
|
|
#include "str.h"
|
|
|
|
#include "vector.h"
|
2016-03-27 11:49:47 +02:00
|
|
|
|
|
|
|
// Basic Hash functions
|
|
|
|
|
|
|
|
template<>
|
2023-08-19 03:02:30 +02:00
|
|
|
int HashCode<const char *>(const char *const& key)
|
2016-03-27 11:49:47 +02:00
|
|
|
{
|
2023-08-19 03:02:30 +02:00
|
|
|
const char *p;
|
|
|
|
int hash = 0;
|
2016-03-27 11:49:47 +02:00
|
|
|
|
2023-08-19 03:02:30 +02:00
|
|
|
for (p = key; *p; p++) {
|
|
|
|
hash = *p + 31 * hash;
|
|
|
|
}
|
2016-03-27 11:49:47 +02:00
|
|
|
|
2023-08-19 03:02:30 +02:00
|
|
|
return hash;
|
2016-03-27 11:49:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
template<>
|
2023-08-19 03:02:30 +02:00
|
|
|
int HashCode<void *>(void *const& key)
|
2016-03-27 11:49:47 +02:00
|
|
|
{
|
2023-08-19 03:02:30 +02:00
|
|
|
return 0;
|
2016-03-27 11:49:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
template<>
|
2023-08-19 03:02:30 +02:00
|
|
|
int HashCode<const void *>(const void *const& key)
|
2016-03-27 11:49:47 +02:00
|
|
|
{
|
2023-08-19 03:02:30 +02:00
|
|
|
return 0;
|
2016-03-27 11:49:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
template<>
|
2023-08-19 03:02:30 +02:00
|
|
|
int HashCode<char>(const char& key)
|
2016-03-27 11:49:47 +02:00
|
|
|
{
|
2023-08-19 03:02:30 +02:00
|
|
|
return key;
|
2016-03-27 11:49:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
template<>
|
2023-08-19 03:02:30 +02:00
|
|
|
int HashCode<unsigned char>(const unsigned char& key)
|
2016-03-27 11:49:47 +02:00
|
|
|
{
|
2023-08-19 03:02:30 +02:00
|
|
|
return key;
|
2016-03-27 11:49:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
template<>
|
2023-08-19 03:02:30 +02:00
|
|
|
int HashCode<unsigned char *>(unsigned char *const& key)
|
2016-03-27 11:49:47 +02:00
|
|
|
{
|
2023-08-19 03:02:30 +02:00
|
|
|
return (int)(size_t)key;
|
2016-03-27 11:49:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
template<>
|
2023-08-19 03:02:30 +02:00
|
|
|
int HashCode<short>(const short& key)
|
2016-03-27 11:49:47 +02:00
|
|
|
{
|
2023-08-19 03:02:30 +02:00
|
|
|
return key;
|
2016-03-27 11:49:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
template<>
|
2023-08-19 03:02:30 +02:00
|
|
|
int HashCode<unsigned short>(const unsigned short& key)
|
2016-03-27 11:49:47 +02:00
|
|
|
{
|
2023-08-19 03:02:30 +02:00
|
|
|
return key;
|
2016-03-27 11:49:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
template<>
|
2023-08-19 03:02:30 +02:00
|
|
|
int HashCode<short3>(const short3& key)
|
2016-03-27 11:49:47 +02:00
|
|
|
{
|
2023-08-19 03:02:30 +02:00
|
|
|
return key;
|
2016-03-27 11:49:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
template<>
|
2023-08-19 03:02:30 +02:00
|
|
|
int HashCode<unsigned_short3>(const unsigned_short3& key)
|
2016-03-27 11:49:47 +02:00
|
|
|
{
|
2023-08-19 03:02:30 +02:00
|
|
|
return key;
|
2016-03-27 11:49:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
template<>
|
2023-08-19 03:02:30 +02:00
|
|
|
int HashCode<int>(const int& key)
|
2016-03-27 11:49:47 +02:00
|
|
|
{
|
2023-08-19 03:02:30 +02:00
|
|
|
return key;
|
2016-03-27 11:49:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
template<>
|
2023-08-19 03:02:30 +02:00
|
|
|
int HashCode<unsigned int>(const unsigned int& key)
|
2016-03-27 11:49:47 +02:00
|
|
|
{
|
2023-08-19 03:02:30 +02:00
|
|
|
return key;
|
2016-03-27 11:49:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
template<>
|
2023-08-19 03:02:30 +02:00
|
|
|
int HashCode<float>(const float& key)
|
2016-03-27 11:49:47 +02:00
|
|
|
{
|
2023-08-19 03:02:30 +02:00
|
|
|
return *(int *)&key;
|
2016-03-27 11:49:47 +02:00
|
|
|
}
|
|
|
|
|
2016-08-13 18:32:13 +02:00
|
|
|
template<>
|
2023-08-19 03:02:30 +02:00
|
|
|
int HashCode<double>(const double& key)
|
2016-08-13 18:32:13 +02:00
|
|
|
{
|
2023-08-19 03:02:30 +02:00
|
|
|
return *(int *)&key;
|
2016-08-13 18:32:13 +02:00
|
|
|
}
|
|
|
|
|
2016-03-27 11:49:47 +02:00
|
|
|
template<>
|
2023-08-19 03:02:30 +02:00
|
|
|
int HashCode<str>(const str& key)
|
2016-03-27 11:49:47 +02:00
|
|
|
{
|
2023-08-19 03:02:30 +02:00
|
|
|
return HashCode<const char *>(key.c_str());
|
2016-03-27 11:49:47 +02:00
|
|
|
}
|
2016-08-13 18:32:13 +02:00
|
|
|
|
|
|
|
template<>
|
2023-08-19 03:02:30 +02:00
|
|
|
int HashCode<Vector>(const Vector& key)
|
2016-08-13 18:32:13 +02:00
|
|
|
{
|
2023-08-19 03:02:30 +02:00
|
|
|
return (int)((key[0] + key[1] + key[2]) / 3);
|
2016-08-13 18:32:13 +02:00
|
|
|
}
|