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 <> nildo
  
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 = nilthen
      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还不能正常使用. 其他模式没有问题。

 

posted @ 2011-02-25 10:59  D10.天地弦  阅读(972)  评论(0编辑  收藏  举报