*---------------------------------------------------------------- // Copyright (C) 2005 一缕阳光版权所有 // 版权所有。 // // 文件名:Hash.h // 文件功能描述:此类简单实现了一个hash表的功能 // // 作者:Sundy // 创建标识:2005-06-27 // //----------------------------------------------------------------*/ #ifndef _HASH_H_ #define _HASH_H_ #define KEYLENGTH 64 //宏定义 class CHashElem ...{ public: ~CHashElem()...{ } int Key; int Val; CHashElem *pNext; }; class CHash ...{ public: CHash(int iSlots =10); ~CHash(); public: /**//**//**//* *功能:根据键名称,获取键值 *@Key:键名称; *@Val:键值; *返回:If the function succeeds, the return value is true. */ bool QueryValue(constint Key,int& Val); /**//**//**//* *功能:根据键名称,获取键值 *@Key:键名称; *@Val:键值; *返回:If the function succeeds, the return value is true. */ bool Insert(int Key, int Val); /**//**//**//* *功能:根据键名称,删除键 *@Key:键名称; *返回:If the function succeeds, the return value is true. */ bool Remove(constint Key); /**//**//**//* *功能:获取哈希表长度 *返回:If the function succeeds, the return value is the hash lenghth. */ int GetLength(); /**//**//**//* *功能:根据键名称,获取键值 *返回:If the function succeeds, the return value is the hash lenghth. */ int GetSlotNum(); /**//**//**//* *功能:根据索引返回 *@iIndex:键的索引号; *返回:If the function succeeds, the return value is CHashElem. */ CHashElem* QueryElem(constint iIndex); protected: CHashElem **m_pHashSlots; int m_iNumSlots; int m_iLength; }; #endif