整理15确定性跳跃表Java实现.docx

上传人:b****7 文档编号:9645139 上传时间:2023-02-05 格式:DOCX 页数:33 大小:20.96KB
下载 相关 举报
整理15确定性跳跃表Java实现.docx_第1页
第1页 / 共33页
整理15确定性跳跃表Java实现.docx_第2页
第2页 / 共33页
整理15确定性跳跃表Java实现.docx_第3页
第3页 / 共33页
整理15确定性跳跃表Java实现.docx_第4页
第4页 / 共33页
整理15确定性跳跃表Java实现.docx_第5页
第5页 / 共33页
点击查看更多>>
下载资源
资源描述

整理15确定性跳跃表Java实现.docx

《整理15确定性跳跃表Java实现.docx》由会员分享,可在线阅读,更多相关《整理15确定性跳跃表Java实现.docx(33页珍藏版)》请在冰豆网上搜索。

整理15确定性跳跃表Java实现.docx

整理15确定性跳跃表Java实现

1-5确定性跳跃表Java实现

作者:

云南大学软件学院09数字媒体技术雒森

/*

*Tochangethistemplate,chooseTools|Templates

*andopenthetemplateintheeditor.

*/

packageLuoSen.DS.DS;

importjava.io.Serializable;

/**

*

*@authorLENOVO

*/

/**确定性跳跃表链的结点*/

publicclassDSLLinkNodeimplementsSerializable{

/**跳跃表链结点的层数*/

publicintlevelNum=1;

/**跳跃表链结点的数据*/

publicSdata;

/**顶部的链*/

publicDSLNodetop;

/**构造函数*/

publicDSLLinkNode(){

data=null;

top=null;

}

/**构造函数*/

publicDSLLinkNode(Sdata,DSLNodetop){

this.data=data;

this.top=top;

}

/**构造函数*/

publicDSLLinkNode(Sdata,DSLNodetop,inti){

this.data=data;

this.top=top;

this.levelNum=i;

}

/**判断节点是否相等*/

@Override

publicbooleanequals(Objecto)

{

if(this==o)

returntrue;

if(o==null||!

(oinstanceofDSLLinkNode))

returnfalse;

DSLLinkNodea=(DSLLinkNode)o;

if(data.equals(a.data))

returntrue;

returnfalse;

}

@Override

publicinthashCode(){

inthash=7;

hash=41*hash+this.levelNum;

hash+=41*hash+(this.data!

=null?

this.data.hashCode():

0);

returnhash;

}

@Override

publicStringtoString(){

return""+data;

}

}

 

/*

*Tochangethistemplate,chooseTools|Templates

*andopenthetemplateintheeditor.

*/

packageLuoSen.DS.DS;

importjava.io.Serializable;

/**

*

*@authorLENOVO

*/

/**确定性跳跃表结点*/

publicclassDSLNodeimplementsSerializable{

/**向右的链*/

publicDSLNoderight;

/**向下的链*/

publicDSLNodedown;

/**确定性跳跃表链的结点*/

publicDSLLinkNodelink;

/**默认构造函数*/

publicDSLNode(){

right=down=null;

link=null;

}

/**构造函数*/

publicDSLNode(DSLNoderight){

this.right=right;

this.down=null;

link=null;

}

/**构造函数*/

publicDSLNode(DSLNoderight,DSLNodedown){

this.right=right;

this.down=down;

link=null;

}

/**构造函数*/

publicDSLNode(DSLNoderight,DSLNodedown,DSLNodetop,inti){

this.right=right;

this.down=down;

link=newDSLLinkNode((S)newObject(),top,i);

}

/**构造函数*/

publicDSLNode(DSLNoderight,DSLNodedown,DSLLinkNodelink){

this.right=right;

this.down=down;

this.link=link;

}

/**判断节点是否相等*/

@Override

publicbooleanequals(Objecto)

{

if(this==o)

returntrue;

if(o==null||!

(oinstanceofDSLNode))

returnfalse;

DSLNodea=(DSLNode)o;

if(link==a.link||(link!

=null&&link.equals(a.link)))

returntrue;

returnfalse;

}

@Override

publicinthashCode(){

inthash=7;

hash=47*hash+(this.link!

=null?

this.link.hashCode():

0);

returnhash;

}

@Override

publicStringtoString(){

if(link!

=null)

returnlink.toString();

else

return"";

}

}

 

/*

*Tochangethistemplate,chooseTools|Templates

*andopenthetemplateintheeditor.

*/

packageLuoSen.DS.DS;

importLuoSen.DS.Alg.Util.CreateComparator;

importLuoSen.DS.Exceptions.IllegalParameterException;

importjava.io.Serializable;

importjava.util.Collection;

importjava.util.Comparator;

importjava.util.HashSet;

importjava.util.Iterator;

importjava.util.List;

importjava.util.Set;

importjava.util.logging.Level;

importjava.util.logging.Logger;

/**

*

*@author云大09数媒雒森

*/

/**1-5确定性跳跃表*/

publicclassDSkipListimplementsSerializable,Iterable{

/**头结点*/

protectedDSLNodeheader;

/**尾结点*/

protectedDSLNodetailer=null;

/**底结点*/

protectedDSLNodebottom=null;

/**表中元素的个数*/

protectedintsize=0;

/**比较器*/

protectedComparatorcp=null;

/**构造函数*/

publicDSkipList(){

bottom=null;

tailer=null;

header=newDSLNode(tailer,bottom,null,(byte)0);

}

/**构造函数*/

publicDSkipList(Comparatorcp){

bottom=null;

tailer=null;

header=newDSLNode(tailer,bottom,null,(byte)0);

this.cp=cp;

}

/**使用一个DSkipList跳表初始化,目的是将目标复制到当前表中*/

publicbooleaninitial(DSkipListdsl){

if(dsl==null)

returnfalse;

this.cp=dsl.cp;

this.header=dsl.header;

this.size=dsl.size;

returntrue;

}

/**返回跳跃表的头*/

publicDSLNodegetHeader()

{

returnheader;

}

/**设置比较器*/

publicvoidsetComparator(Comparatorcp){

this.cp=cp;

}

/**返回比较器*/

publicComparatorgetComparator(){

returncp;

}

/**判断表中是否有关键字对应值*/

publicbooleancontain(Sdata){

returnthis.search(data)!

=null;

}

/**查找数据为data的数据比较关键字封装在data中*/

publicSsearch(Sdata){

if(data==null||size==0)

returnnull;

DSLNodecur=header;

while(cur!

=bottom){

while(cur.right!

=tailer&&pare(cur.right.link.data,data)<0){

cur=cur.right;

}

if(cur.right!

=tailer&&pare(cur.right.link.data,data)==0){

returncur.right.link.data;

}

cur=cur.down;

}

returnnull;

}

/**查找数据为data的数据比较关键字封装在data中,若查不到则返回位于它之后的第一个(最底部)结点*/

publicDSLNodesearchStart(Sdata){

if(data==null||size==0)

returnnull;

DSLNodecur=header;

while(cur!

=bottom){

while(cur.right!

=tailer&&pare(cur.right.link.data,data)<0){

cur=cur.right;

}

if(cur.down==bottom||(cur.right!

=tailer&&

pare(cur.right.link.data,data)==0)){

cur=cur.right;

if(cur!

=tailer){

while(cur.down!

=bottom)

cur=cur.down;

}

returncur;

}

cur=cur.down;

}

returnnull;

}

/**查找数据为data的数据比较关键字封装在data中,若查不到则返回位于它之前的第一个(最底部)结点*/

publicDSLNodesearchEnd(Sdata){

if(data==null||size==0)

returnnull;

DSLNodecur=header;

while(cur!

=bottom){

while(cur.right!

=tailer&&pare(cur.right.link.data,data)<0){

cur=cur.right;

}

if(cur.down==bottom||(cur.right!

=tailer&&

pare(cur.right.link.data,data)==0)){

cur=cur.right;

if(cur!

=tailer){

while(cur.down!

=bottom)

cur=cur.down;

if(cur.right!

=tailer&&pare(cur.right.link.data,data)==0)

cur=cur.right;

}

returncur;

}

cur=cur.down;

}

returnnull;

}

/**插入数据data,若已存在返回数据链结点,并不插入数据,你可以在外面修改*/

publicDSLLinkNodeinsert(Sdata)throwsIllegalParameterException{

if(data==null)

returnnull;

if(cp==null){

if(Comparable.class.isAssignableFrom(data.getClass())){

CreateComparatorcc=newCreateComparator();

cp=cc.getComparator();

}

else{

thrownewIllegalParameterException("数据不可以比较,请先设置比较器!

");

}

}

DSLNodecur=header;

DSLNodenewNode=null;

while(cur!

=bottom){

while(cur.right!

=tailer&&pare(cur.right.link.data,data)<0){

cur=cur.right;

}

if(cur.right!

=tailer&&pare(cur.right.link.data,data)==0){

newNode=cur.right;

break;

}

if(cur.down==bottom){

newNode=newDSLNode(cur.right,bottom);

newNode.link=newDSLLinkNode(data,newNode);

cur.right=newNode;

size++;

break;

}

elseif(cur.down.right!

=tailer&&cur.down.right.right!

=tailer

&&cur.down.right.right.right!

=tailer&&

cur.down.right.right.right.right!

=tailer&&

cur.down.right.right.right.right.right!

=tailer&&

(cur.right==tailer||pare(cur.down.right.right.right

.right.right.link.data,cur.right.link.data)<0)){

cur.right=newDSLNode(cur.right,cur.down.right.right.right,cur.down.right.right.right.link);

cur.right.link.top=cur.right;

cur.right.link.levelNum++;

}

cur=cur.down;

}

if(header.right!

=tailer){

header.link.levelNum++;

header.link.top=header;

header=newDSLNode(tailer,header,header.link);

}

returnnewNode.link;

}

/**删除数据data*/

publicbooleanremove(Sdata)throwsIllegalParameterException{

if(data==null||size==0)

returnfalse;

if(cp==null){

if(Comparable.class.isAssignableFrom(data.getClass())){

CreateComparatorcc=newCreateComparator();

cp=cc.getComparator();

}

else{

thrownewIllegalParameterException("数据不可以比较,请先设置比较器!

");

}

}

DSLNodecur=header;

DSLNodec=null,cc=null,top=null;

while(cur!

=bottom){

while(cur.right!

=tailer&&pare(cur.right.link.data,data)<0){

cur=cur.right;

}

if(cur.down==bottom&&cur.right!

=tailer&&pare(cur.right.link.data,data)==0){

if(size==1){

header=newDSLNode(tailer,bottom,null,(byte)0);

}

else{

if(cur.link.levelNum

c=cur.right.link.top;

top=cur.right.link.top;

cur.link.levelNum=cur.right.link.levelNum;

while(c.down!

=cur.link.top.right){

c.link=cur.link;

c=c.down;

}

c.link=cur.link;

c.down=cur.link.top;

c=cur.link.top.right;

cc=cur.link.top;

while(c!

=bottom&&cc!

=bottom){

cc.right=c.right;

cc=cc.down;

c=c.down;

}

cur.link.top=top;

}

else{

cc=cur.link.top;

while(cc.right!

=cur.right.link.top){

cc=cc.down;

}

c=cur.right.link.top;

while(c!

=bottom&&cc!

=bottom){

cc.right=c.right;

cc=cc.down;

c=c.down;

}

}

}

size--;

while(header.down!

=bottom&&header.down.right==tailer){

header=header.down;

header.link.levelNum--;

header.link.top=header.down;

}

returntrue;

}

cur=cur.down;

}

returnfalse;

}

/**获取条件一维区间odr之间的元素集合,,该函数主要服务于:

KDSkipList,用于检索一维区间*/

publicCollectionqueryRegion(ODRegionodr){

Sets=newHashSet();

if(odr.isNoHasCondition){

DSLNodecur=header;

while(cur.down!

=bottom)

cur=cur.down;

cur=cur.right;

while(cur!

=tailer){

if(cur.link.datainstanceofKDSLNode)

s.addAll(((KDSLNode)cur.link.data).set);

else

s.add(cur.link.data);

cur=cur.right;

}

}

else{

DSLNodecur=header;

DSLNodeend=null;

if(odr.start!

=null)

cur=this.searchStart(odr.start);

else{

while(cur.down!

=bottom)

cur=cur.down;

cur=cur.right;

}

end=this.searchEnd(odr.end);

if(cur==null||(cur!

=null&&end!

=null&&pare(cur.link.data,end.link.data)>0))

returns;

while(cur!

=end){

if(cur.link.datainstanceofKDSLNode)

s.addAll(((KDSLNode)cur.link.data).set);

else

s.add(cur.link.data);

cur=cur.right;

}

}

returns;

}

/**获取条件一维区间odr之间的元素满足多维条件的数据集合,index为odr在qc中的位置,

*该函数主要服务于:

MLDSkipList用于检索多位区间*/

publicCollectionqueryRegion(Collections,ODRegionodr,intindex

List>qc,List>cps){

if(s==null)

returns;

if(odr.isNoHasCondition){

DSLNodecur=header;

while(cur.down!

=b

展开阅读全文
相关搜索

当前位置:首页 > 党团工作 > 入党转正申请

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1