出处:http://blog.csdn.net/v_JULY_v
我做了一些详细的注释
//copyright@yansha &&July
//July、updated,2011.05.08
//题目描述:
//搜索引擎会通过日志文件把用户每次检索使用的所有检索串都记录下来,每个查询串的
//长度为1-255字节。假设目前有一千万个记录(这些查询串的重复度比较高,虽然总数是1千万,但如果
//除去重复后,不超过3百万个。一个查询串的重复度越高,说明查询它的用户越多,也就是越热门),
//请你统计最热门的10个查询串,要求使用的内存不能超过1G。
/*
#include <iostream>
#include <string>
#include <assert.h>
using namespace std;
#define HASHLEN 28000
#define WORDLEN 15
// 结点指针
typedef struct node_no_space *ptr_no_space;
typedef struct node_has_space *ptr_has_space;
ptr_no_space head[HASHLEN];
struct node_no_space
{
char *word;
int count;
ptr_no_space next;
};
struct node_has_space
{
char word[WORDLEN];
int count;
ptr_has_space next;
};
// 最简单hash函数
int hash_function( char *p) //在哈希统计中根据某个规则进行定位,并返回哈希值value
{
int value = 0;
while (*p != '\0') //对字符串中的每个字母都哈希运算下,结果v