1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134
|
/**************************************************************************
* *
* Regina - A Normal Surface Theory Calculator *
* Computational Engine *
* *
* Copyright (c) 1999-2011, Ben Burton *
* For further details contact Ben Burton (bab@debian.org). *
* *
* This program 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. *
* *
* This program 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 this program; if not, write to the Free *
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, *
* MA 02110-1301, USA. *
* *
**************************************************************************/
/* end stub */
/*! \file utilities/hashutils.h
* \brief Provides a variety of hash functions for use with the
* Standard Template Library.
*
* \deprecated Everything related to the \e hash_set and \e hash_map classes
* is deprecated, since these classes are not part of the C++ standard.
* This material is scheduled to be removed from Regina in version 5.0.
*/
#ifndef __HASHUTILS_H
#ifndef __DOXYGEN
#define __HASHUTILS_H
#endif
#include "regina-core.h"
#include "regina-config.h"
#include "utilities/hashset.h"
#include <string>
/*! \namespace stdhash
* \brief The namespace containing <tt>hash_set</tt>, <tt>hash_map</tt>
* and other associated Standard Template Library extension classes.
*
* This alias is provided because different compilers place these classes
* in different namespaces.
*
* \deprecated Everything related to the \e hash_set and \e hash_map classes
* is deprecated, since these classes are not part of the C++ standard.
* This material is scheduled to be removed from Regina in version 5.0.
*/
#ifdef __NO_NAMESPACE_ALIASES
#define stdhash __HASH_NAMESPACE
#else
namespace stdhash = __HASH_NAMESPACE;
#endif
namespace regina {
/**
* \weakgroup utilities
* @{
*/
/**
* A hash function used to calculate hash values for arbitrary pointers.
* This class is for use with the Standard Template Library.
*
* The only guarantee provided by this hash function is that two
* pointers representing the same memory location will return the same
* hash value. Two pointers pointing to identical data in two different
* memory locations might very well return two different hash values.
*
* \ifacespython Not present.
*
* \deprecated Everything related to the \e hash_set and \e hash_map classes
* is deprecated, since these classes are not part of the C++ standard.
* This material is scheduled to be removed from Regina in version 5.0.
*/
struct REGINA_API HashPointer {
/**
* Returns a hash value for the given pointer. See the general
* class notes for further details.
*
* @param p the pointer whose hash value should be calculated.
* @return the corresponding hash value.
*/
size_t operator() (const void* p) const {
// Cast the pointer directly to a size_t.
return reinterpret_cast<size_t>(p);
}
};
/**
* A hash function used to calculate hash values for C++ strings.
* This class is for use with the Standard Template Library.
*
* \ifacespython Not present.
*
* \deprecated Everything related to the \e hash_set and \e hash_map classes
* is deprecated, since these classes are not part of the C++ standard.
* This material is scheduled to be removed from Regina in version 5.0.
*/
struct REGINA_API HashString {
private:
static stdhash::hash<const char*> hashFcn;
/**< The real hash function used to perform calculations. */
public:
/**
* Returns a hash value for the given string.
*
* @param str the string whose hash value should be calculated.
* @return the corresponding hash value.
*/
size_t operator() (const std::string& str) const {
return hashFcn(str.c_str());
}
};
/*@}*/
} // namespace regina
#endif
|