资源简介
B-树作为查找作为查找存储结构,中文单词进行哈希,本中文词典规模在十万级别以上,最长逆向匹配算法实现中文分词。

代码片段和文件信息
/************************************************************************/
/*作者;康维鹏 时间:2010年1月10日 */
/************************************************************************/
#include “Btree.h“
#include
#include
/*构造函数*/
Btree::Btree()
{
levels=1;
nodes=0;
counts=0;
root= mallocNode();
}
/*析构函数*/
Btree::~Btree()
{
if(root==NULL)
return ;
delAll();
}
/*分配新节点,并初始化*/
btree Btree::mallocNode()
{
btree newnode=(btree)malloc(sizeof(node));
for(int i=0;i<=2*M;i++)
{
newnode->key[i]=MIN;
newnode->child[i]=NULL;
newnode->val[i]=NULL;
}
newnode->child[2*M+1]=NULL;
newnode->p=NULL;
newnode->lev=1;
newnode->num=0;
nodes++;
return newnode;
}
/*返回插入的键值数目*/
int Btree::getCount()
{
return counts;
}
/*返回节点数目*/
int Btree::getNode()
{
return nodes;
}
/*返回高度,以1开始计算*/
int Btree::getHeight()
{
return levels;
}
/*返回根节点*/
btree Btree::getRoot()
{
return root;
}
/*设定高度*/
int Btree::setHeight(int hight)
{
return levels=hight;
}
/*设定键值数量*/
int Btree::setCount(int count)
{
return counts=count;
}
/*设定节点总数*/
int Btree::setNode(int num)
{
return nodes=num;
}
bool Btree::setRoot(btree bt)
{
delAll();
root=bt;
return true;
}
/*查找键值是否存在*/
bool Btree::search(typekey key)
{
btree bt=rootpt=root;
if(search(keybtpt)==-1)
return false;
return true;
}
/*查找键值为key的val是否存在*/
bool Btree::search(typekey keyconst char *val)
{
btree bt=rootpt=root;
int mid=search(keybtpt);
if(mid==-1)
return false;
if(strcmp(bt->val[mid]->valval)!=0)
return false;
return true;
}
/*查找键值是否存在,以及保存在有关信息*/
int Btree::search(typekey key btree &btbtree &pt)
{
if(root->num==0)
return -1;
if(bt==NULL)
return -1;
if(bt->num==0)
return -1;
/*直到叶节点为止*/
while(1)
{
/*折半查找,效率较佳*/
int low=0 high=bt->num-1 mid=(low+high)/2;
for(;high >=low;)
{
if(key==bt->key[mid])
{
/*找到则返回,保存信息*/
pt=bt->p;
return mid;
}
;
if(key > bt->key[mid])
{
low=mid+1;
mid=(high+low)/2;
}
else
{
high=mid-1;
mid=(high+low)/2;
}
}
pt=bt;
/*根据大小关系,选择子节点进行。这是因为在调整lowhighmid时可能漏判mid的情况*/
if(key > bt->key[mid])
bt=bt->child[mid+1];
else
bt=bt->child[mid];
if(bt==NULL)
return -1;
}
return -1;
}
//使节点pt的第pos的孩子指向bt
bool Btree::apend(btree &ptint posbtree &bt)
{
if(pt==NULL)
return false;
if(pos>pt->num)
return false;
pt->child[pos]=bt;
if(bt!=NULL)
bt->p=pt;
return true;
}
/*插入新结点*/
bool Btree::insert(typekey key)
{
return insert(keyNULL);
}
/*插入新结点*/
bool Btree::insert(typekey keypword val)
{
if(root->num==0)
{
root->key[0]=key;
root->val[0]=val;
root->num++;
counts++;
return true;
}
btree btpt;
pt=root;
bt=root;
if(search(keybtpt)==-1)
{
if(insert(keyvalptbt))
{
counts++
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 264 2009-01-14 14:24 readme.txt
文件 1863649 2010-01-12 13:52 dict.dat
文件 13115 2009-01-14 13:51 Btree.cpp
文件 2802 2009-01-14 13:21 Btree.h
文件 7446 2009-01-14 13:38 Dict.cpp
文件 1820 2009-01-14 13:51 Dict.h
文件 3490 2010-01-12 13:56 Hash.cpp
文件 1298 2010-01-12 13:56 Hash.h
文件 857 2010-01-12 13:39 Node.h
文件 814 2009-01-14 13:08 testDict.cpp
----------- --------- ---------- ----- ----
1895555 10
- 上一篇:网页视频地址获取工具
- 下一篇:servlet获取json的小
相关资源
- B-树 C 实现 基本功能
- 电子词典设计与开发 电子词典123
- 贝贝词典黑莓上最好用的电子词典
- 汉语大词典光盘版
- 含拼音的现代汉语词典
- EXCEL函数手册.chm格式
- 情感词极值表,台湾大学NTUSD简体中文
- 台湾大学NTUSD简体中文情感词典+知网
- NTUSD情感词典+知网HowNet+大连理工DUT
- 全情感词情感词典大全
- 台湾大学NTUSD,知网情感分析用词语集
- 带词性标注的中文分词词典
- 台湾大学NTUSD - 简体中文情感极性词典
- 情感分析-情感词典
- 最新提升版-台湾大学ANTUSD-简体中文情
- 台湾大学情感词典
- 中文基础情感词典(NTUSD/HowNet/Tsingh
- 最全中文情感和语义词库包含好几种
- 维软大词典2005
- 最全中文情感和语义词库
- perl语言:成语词典进行加工,生成一
- 情感和语义分析最全中文数据库
- 四个情感词典汇总.zip
- 词典变位词检索系统.rar
- NTUSD情感字典+清华情感字典+知网情感
- 三个主流情感词典Hownet、NTUSD、清华大
- 中文情感词典
- 台湾大学中文情感极性词典
- 安卓项目英汉词典
- 朗文当代英语词典ld2格式
评论
共有 条评论