缓存中有10万条数据,如何提高效率?
来源:百度知道 编辑:UC知道 时间:2024/06/01 17:18:51
1楼说的是hashmap还是hashset还是其他什么?能具体一点吗?我对数据结构不了解
比如一个根据手机号码查找归属地的程序,号码段是个文本文件,数据量在10万条-20万,怎么弄才能使这个查询的效率最高?
这个例子给你看下!希望对你有帮助!是关于hash_table的!
struct hashFun
{
size_t operator()(int nVal) const
{
char szVal[64] = {0};
_itoa(nVal, szVal, 10);
const char* psz = szVal;
unsigned long _hash = 0;
for (; *psz != 0; ++psz)
{
_hash *= 16777619;
_hash ^= (unsigned long) (unsigned short&)*psz;
}
return _hash;
}
};
struct tableNode
{
int nValue;
DWORD nKey;
int nCount; //这个元素的个数
tableNode* pNext;
};
struct BoxVec
{
int nCount; //这个桶下的元素的类型的个数,可能不同的数在同一个桶下
int nMaxNum; //这个桶下这个元素出现的次数
int nVal;
tableNode* pHead;
};
class CMyHasTable
{
public:
CMyHasTable(const int* pBoxSize, int nBoxCount, int nLevel);
~CMyHasTable();
private:
int m_nBoxCount; //桶增长级数个数
const int* m_pBoxSize; /