⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ahash.h

📁 A Set of Simple C++ Hash Templates
💻 H
字号:
#ifndef THE_HASH_THAT_WAS_DESIGNED_BY_ME_H__20061020#define THE_HASH_THAT_WAS_DESIGNED_BY_ME_H__20061020#include "ahashp.h"/**	\brief Hash table		A more complicated hash table that that simplifies the use of it's child class, but make T a little more complex.\n	To setup this class:\n	1. You derive your hash class from this class.\n	2. T must also have comparison operator.\n	3. Follow the requirements for _HashP\<T, KEY_TYPE\>.\n	4. You must create the definition for the static member m_NULL. Somewhere in your class's CPP file put \code template <> T _Hash<T>::m_NULL = T(); \endcode Replacing T with the actual name of your class. M_NULL will be returned by Get() to indicate a NULL value. One such way to do this is give a bool member to T, say m_bNULL, then assign \code m_NULL.m_bNULL = true; \endcode*/template <typename T, typename KEY_TYPE = const char *>class _Hash : public _HashP<T, KEY_TYPE> {protected:	_Hash(int nBucketSize = 0);public:	/**	 *  \brief A const version of Get(KEY_TYPE)	 */	const T &Get(KEY_TYPE ref) const {		const T *pElement = Find(ref);		return (pElement == NULL ? m_NULL : *pElement);	}	/**	 *  \brief Get an element from the table	 * @param ref The reference used to find the element	 * @return A reference to the element sought, or m_NULL if not found.	 */	T &Get(KEY_TYPE ref);public:	//!The null value indicating an empty set	/**It is necessary that this be defined in your program. Then the child class or the instance owner will be able to use his own criteria to identify a NULL value*/	static T m_NULL;};/** * \brief Basic constructor * @param nBucketSize The initial size of the bucket array */template <typename T, typename KEY_TYPE>_Hash<T, KEY_TYPE>::_Hash(int nBucketSize) : _HashP<T, KEY_TYPE>(nBucketSize) {}template <typename T, typename KEY_TYPE>T &_Hash<T, KEY_TYPE>::Get(KEY_TYPE ref) {	T *p = _HashP<T, KEY_TYPE>::Get(ref);	if (p == NULL) return m_NULL;	return *p;}#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -