zoukankan      html  css  js  c++  java
  • kbmmemtable sorton 报错 : List index out of bounds

    同一数据集,不同的排序条件,有的可以,但某一条件,却能100%重现报错。

    procedure TkbmIndex.InternalFastQuickSort(const L,R:Integer);
    var
       I,J:integer;
       P:PkbmRecord;
    begin
         if ((R-L)>4) then
    //     if ((R-L)>0) then
         begin
              I:=(R+L) div 2;
              if CompareRecords(FIndexFieldList,PkbmRecord(FReferences[L]),PkbmRecord(FReferences[I]),true,false)>0 then
               InternalSwap(L,I);
              if CompareRecords(FIndexFieldList,PkbmRecord(FReferences[L]),PkbmRecord(FReferences[R]),true,false)>0 then
               InternalSwap(L,R);
              if CompareRecords(FIndexFieldList,PkbmRecord(FReferences[I]),PkbmRecord(FReferences[R]),true,false)>0 then
               InternalSwap(I,R);
    
              J:=R-1;
              InternalSwap(I,J);
              I:=L;
              P:=PkbmRecord(FReferences[J]);
              while true do
              begin
                   Inc(I);
                   Dec(J);
                   while CompareRecords(FIndexFieldList,PkbmRecord(FReferences[I]),P,true,false) < 0 do Inc(I);
                   while CompareRecords(FIndexFieldList,PkbmRecord(FReferences[J]),P,true,false) > 0 do Dec(J);
                   if (J<I) then break;
                   InternalSwap(I,J);
              end;
              InternalSwap(I,R-1);
              InternalFastQuickSort(L,J);
              InternalFastQuickSort(I+1,R);
         end;
    end;

     反复跟代码,发现在  kbmMemTable.PAS中,当J减至0时,FReferences[J] 下标越界

    试改为FIndexFieldList.Count>0前判断条件却未解决,说明并非是递减原因,改为大于J,未报错,是否有问题,待应用中再关注。

    procedure TkbmIndex.InternalFastQuickSort(const L,R:Integer);
    var
       I,J:integer;
       P:PkbmRecord;
    begin
         if ((R-L)>4) then
    //     if ((R-L)>0) then
         begin
              I:=(R+L) div 2;
              if CompareRecords(FIndexFieldList,PkbmRecord(FReferences[L]),PkbmRecord(FReferences[I]),true,false)>0 then
               InternalSwap(L,I);
              if CompareRecords(FIndexFieldList,PkbmRecord(FReferences[L]),PkbmRecord(FReferences[R]),true,false)>0 then
               InternalSwap(L,R);
              if CompareRecords(FIndexFieldList,PkbmRecord(FReferences[I]),PkbmRecord(FReferences[R]),true,false)>0 then
               InternalSwap(I,R);
    
              J:=R-1;
              InternalSwap(I,J);
              I:=L;
              P:=PkbmRecord(FReferences[J]);
              while true do
              begin
                   Inc(I);
                   Dec(J);
                   while CompareRecords(FIndexFieldList,PkbmRecord(FReferences[I]),P,true,false) < 0 do Inc(I);
                   while  (FIndexFieldList.Count>J )and (CompareRecords(FIndexFieldList,PkbmRecord(FReferences[J]),P,true,false) > 0) do Dec(J);
                   if (J<I) then break;
                   InternalSwap(I,J);
              end;
              InternalSwap(I,R-1);
              InternalFastQuickSort(L,J);
              InternalFastQuickSort(I+1,R);
         end;
    end;
  • 相关阅读:
    css的一些属性及其属性值
    HTML基本标签
    JQuery
    js中的Dom事件模型以及表格方面等内容
    Alpha的过程总结
    数独+GUI界面
    数独
    调研《构建之法》指导下的全国高校的历届软工实践作品、全国互联网+竞赛、物联网竞赛、华为杯研究生作品赛、全国大学生服务外包赛等各类全国性大学生信息化相关的竞赛平台的历届作品
    本学期高级软件工程课程的实践项目的自我目标
    高级软件工程第八次作业:“两只小熊队”团队作业-5
  • 原文地址:https://www.cnblogs.com/zhqian/p/10495329.html
Copyright © 2011-2022 走看看