htab.cpp
来自「《c++ 实践之路》光盘中的源代码」· C++ 代码 · 共 31 行
CPP
31 行
// (c) Bartosz Milewski 2000
#include "HTab.h"
#include <cassert>
// Find the list in the hash table that may contain
// the id of the string we are looking for
List const & HTable::Find (char const * str) const
{
int i = hash (str);
return _aList [i];
}
void HTable::Add (char const * str, int id)
{
int i = hash (str);
_aList [i].Add (id);
}
int HTable::hash (char const * str) const
{
// no empty strings, please
assert (str != 0 && str [0] != 0);
unsigned h = str [0];
for (int i = 1; str [i] != 0; ++i)
h = (h << 4) + str [i];
return h % _size; // remainder
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?