选择显示字体大小

“中值排序基数法实现树状结构”的补充

     由于一时疏忽,造成了此法“对于int类型的基数字段,对原始贴的回复只能有31个;numeric类型的基数字段,对原始贴的回复也不能超过120个”(实际上是对于int型字段,原始贴的回复第32个以上的树状结构显示开始紊乱,对于numeric型的基数字段,原始贴的回复从121个以上树状结构显示开始紊乱——回复并不会出问题),这是由于计算机存储精度引起的。
   我们可以将加贴的存储过程修改一下(加进前面加上**号的行)以限制到了一定深度(在特定数据类型下,基数无法分辨)的时候不再以树状结构显示(而采用平显——平行显示,这样做虽然有点象折衷的做法,但在实际上由于浏览器等的限制——即使在深度100的时候能以树状结构显示,但从你的浏览器看来的树状结构的结果仍然不是清晰的——屏幕宽度不够,会折行呗)。
  
  加贴存储过程
  
  create procedure [add] @keyid int,@message varchar(50) output ———keyid为回复的贴子id号,如果是新贴则为0,@message为出错信息
  as
   if (@keyid=0)
   insert into forum (rootid,deep,ordernum,……) values(0,0,0,……)
   else
   begin
   declare @rootid int,@id int,@deep int,@begnum float,@endnum float,@ordernum float
   select @rootid=0,@id=0,@deep=0,@begnum=0,@endnum=0,@ordernum=0
   select @rootid=rootid,@id=id,@begnum=ordernum,@deep=deep from forum where id=@keyid
   if (@id=0)
   begin
   select @message=''要回复的贴子已经被删除!''
   return
   end
   else
   begin
   if (@rootid=0) select @rootid=@id ——回复的是根贴,取其id为新加贴的rootid
   select @endnum=ordernum where rootid=@rootid and ordernum>@begnum order by ordernum
   if (@endnum=0)
   select @ordernum=@begnum+65536 ——回复的是最后一贴,可以在此限制@ordernum的范围以防溢出
   else
  ** begin
  ** if @endnum-@begnum>1 ——精度仍能分辨。此处的1为精度标记,适合于基数字段为int,如果基数字段为numeric字段,请酌情选娶(呸呸呸,错别字来了),目的是使基数精度过小时限制深度增加,避免显示时的紊乱
  ** select @ordernum=(@begnum+@endnum)/2,@deep=@deep+1 ——关键,取排序基数中值
  ** else
  ** select @ordernum=@begnum ——限制深度不能再增加,此贴与回复贴平行显示,如果存在parentid字段,则要取parentid和回复贴的parentid一样
  ** end
  ** insert into forum (rootid,deep,ordernum,……) values(@rootid,@deep,@ordernum,……)
   end
   end
   select @message=''成功''
   return
  
  剪枝存储过程改为:
  
  create procedure [del] @keyid int,@message varchar(50) output ———keyid为要删除的贴子id号,如果是新贴则为0,@message为出错信息
  as
  declare @rootid int,@id int,@deep int,@begnum float,@endnum float
  select @rootid=0,@deep=0,@begnum=0,@endnum=0,@id=0
  select @id=id,@begnum=ordernum,@rootid=rootid,@deep=deep from forum where id=@keyid
  if (@id=0)
   begin
   select @message=''该贴子不存在!"
   return
   end
  else
   begin
   select @endnum=ordernum from forum where rootid=@rootid and deep<=@deep and ordernum>@begnum order by ordernum
   if (@endnum=0) ——要删除的是最后一个子枝或是根贴
   delete from forum where ordernum>=@begnum and (rootid=@rootid or id=@rootid)
   else
  ** begin
  ** if @begnum=@endnum
  ** delete from forum where id=@id and (rootid=@rootid or id=@rootid) ——已经受精度限制的枝,只删当前贴
  ** else
  ** delete from forum where ordernum>=@begnum and ordernum<@endnum and (rootid=@rootid or id=@rootid)
  ** end
   end
  
  
   虽然是限制,但此限制应该是必须的,因为实际上的回复深是不能太大的(就象我在这里灌到八九层的时候,讨饭猫就大叫“打住打住”了,呵呵)
  
   欢迎访问我的个人主页http://swuse.yeah.net(原来bigeagle是说我这一句话“目的明显啊”)
  
    


 


关键字 本文所属关键字

相关 与本文相关文章

分类 所有文章关键字导航

源码编程相关

Java   Asp   PHP   .Net   XML   C/C++   CGI   VB   Jsp   J2ee   J2se   J2me   EJB   Servlet   Tomcat   Resin   Struts   Weblogic   Eclipse   ANT   GUI   JMS   Web servise   IDEA   Webphere   Hibernate   Spring   Jboss   Applet   Swing   Socket   Javamail   Perl   Ajax   P2P   安全   模式   框架   测试   开源   游戏

SQL数据库相关

My-SQL   Ms-SQL   Access   DB2   Oracle   Sybase   SQLserver   索引   存储过程   加密   数据库   分页   视图  

手机无线相关

3G   Wap   CDMA   GRPS   GSM   IVR   彩信   短信   无线   增值业务

网页设计制作相关

HTML   CSS   网页配色   网页特效   Javascript   VBscript   Dreamweaver   Frontpage   JS   Web   网站设计

网站建设推广相关

建站经验   网站优化   网站排名   推广   Alexa

操作系统/服务器相关

Windows XP   Windows 2000   Windows 2003   Windows Me   Windows 9.x   Linux   UNIX   注册表   操作系统   服务器   应用服务器

图形图像多媒体相关

Photoshop   Fireworks   Flash   Coreldraw   Illustrator   Freehand   Photoimpact   多媒体   图形图像

标准 网站致力的规范

Valid CSS!

无不良内容,无不良广告,无恶意代码

Valid XHTML 1.0 Transitional

creativecommons