天天看点

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

      // modify by mofen

      cmp := CompareForSortModeString(k, h.Name);

    end;

........

function TSuperAvlTree.Delete(const k: SOString): ISuperObject;

  depth, rm_depth: longint;

  branch: TSuperAvlBitArray;

  h, parent, child, path, rm, parent_rm: TSuperAvlEntry;

  cmp, cmp_shortened_sub_with_path, reduced_depth, bf: integer;

  cmp_shortened_sub_with_path := 0;

  branch := [];

  depth := 0;

  parent := nil;

  while true do

    if (h = nil) then

      exit;

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

    //      if h.FHash > ha then cmp := 1 else

    //        cmp := 0;

.........

再经过修改Search和Delete后

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

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

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

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