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

📄 nhashtable.h

📁 奇迹世界公用文件源代码,研究网络游戏的朋友可以研究下
💻 H
字号:
#ifndef N_HASHTABLE_H
#define N_HASHTABLE_H
//------------------------------------------------------------------------------
/**
    @brief Implements a simple string hash table.

    @author
    - RadonLabs GmbH 

    @since
    - 2005.6.30
    @remarks
    - 瘤肯 眠啊 
*/

#include "../ProgramCommon/Define.h"
#include "nstrlist.h"

//------------------------------------------------------------------------------
class nHashTable 
{
public:
    /// constructor
    nHashTable(int size);
    /// destructor
    ~nHashTable();
    /// add an entry to the hashtable
    void Add(nStrNode* n);
    /// search hash table for entry
    nStrNode* Find(const char* str) const;

private:
    int htable_size;
    nStrList *htable;
};

//------------------------------------------------------------------------------
/**
*/
inline 
nHashTable::nHashTable(int size)
{
    this->htable_size = size;
    this->htable = new nStrList[size];
}

//------------------------------------------------------------------------------
/**
*/
inline nHashTable::~nHashTable()
{
    delete[] this->htable;
}

//------------------------------------------------------------------------------
/**
*/
static 
inline 
int hash(const char *str, int htable_size)
{
    int i = 0;
    int j = 1;
    char c;
    while ((c = *str++)) i += ((uchar)c) * j++; 
    return (i % htable_size);
}

//------------------------------------------------------------------------------
/**
*/
inline 
void 
nHashTable::Add(nStrNode* n)
{
    int h_index = hash(n->GetName(), this->htable_size);
    this->htable[h_index].AddHead(n);
}

//------------------------------------------------------------------------------
/**
*/
inline 
nStrNode*
nHashTable::Find(const char* str) const
{
    int h_index = hash(str, this->htable_size);
    return this->htable[h_index].Find(str);
}

//------------------------------------------------------------------------------
#endif

⌨️ 快捷键说明

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