SuperObject(Delphi最好的JSON简析类) 扩展功能----排序(3)

function  TSuperAvlTree.Search( const  k: SOString; st: TSuperAvlSearchTypes): TSuperAvlEntry;
var
  cmp, target_cmp: integer;
  match_h, h: TSuperAvlEntry;
  ha: Cardinal;
begin
  ha :
=  TSuperAvlEntry.Hash(k);

  match_h :
=   nil ;

  h :
=  FRoot;



  
if  (stLess  in  st)  then
    target_cmp :
=   1   else
    
if  (stGreater  in  st)  then
      target_cmp :
=   - 1   else
      target_cmp :
=   0 ;

  
while  (h  <>   nil do
  
begin

            
//  modify by mofen
    
if  nowSortMode  =  sosmDefault  then
    
begin
      
// original code
      
if  h.FHash  <  ha  then  cmp : =   - 1   else
        
if  h.FHash  >  ha  then  cmp : =   1   else
          cmp :
=   0 ;
    
end   else
    
begin
      
//  modify by mofen
      cmp :
=  CompareForSortModeString(k, h.Name);
    
end ;
........

function  TSuperAvlTree.Delete( const  k: SOString): ISuperObject;
var
  depth, rm_depth: longint;
  branch: TSuperAvlBitArray;
  h, parent, child, path, rm, parent_rm: TSuperAvlEntry;
  cmp, cmp_shortened_sub_
with _path, reduced_depth, bf: integer;
  ha: Cardinal;
begin
  ha :
=  TSuperAvlEntry.Hash(k);
  cmp_shortened_sub_
with _path : =   0 ;
  branch :
=  [];

  depth :
=   0 ;
  h :
=  FRoot;
  parent :
=   nil ;
  
while  true  do
  
begin
    
if  (h  =   nil then
      exit;

    
//      if  h.FHash  <  ha  then  cmp : =   - 1   else
    
//        if  h.FHash  >  ha  then  cmp : =   1   else
    
//         cmp : =   0 ;

            
//  modify by mofen
    
if  nowSortMode  =  sosmDefault  then
    
begin
      
// original code
      
if  h.FHash  <  ha  then  cmp : =   - 1   else
        
if  h.FHash  >  ha  then  cmp : =   1   else
          cmp :
=   0 ;
    
end   else
    
begin
      
//  modify by mofen
      cmp :
=  CompareForSortModeString(k, h.Name);
    
end ;
.........

再经过修改Search和Delete后

经过测试基本都可以达到了,

唯一还有一个sosmAdd模式时,进行取值时取不到,

原因是在比较compare是,如果是sosmAdd时返回的结果都是1,就是向后查找,因为按Add模式排序时,在查找时并不能进行比较查找,而是需要查询所有的节点。

这样可想而知查询的速度势必有所影响。还没有仔细研究代码。sosmAdd还不能正常使用. 其他模式没有问题。

 

转载于:https://www.cnblogs.com/DKSoft/articles/1964582.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值