Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ssl/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Delphi 比较2个列表框';锿_Delphi - Fatal编程技术网

Delphi 比较2个列表框';锿

Delphi 比较2个列表框';锿,delphi,Delphi,我在Win 64 sp2上运行D7 Enterprise 在我的程序中,我有两个列表框(lb1,Lb2) Lb1最多可包含35.000个项目。(字符串[4]) Lb2最多可包含35.000个项目。(字符串[4]) 两个列表框都已排序 Thera可能是列表框中的重复项(从0到30.000),我想找到这些重复项 我已经尝试了“自下而上”类型(例如:从listbox2的底部获取元素,从listbox1扫描到底部,标记相等的元素,(最终复制到第三个listbox2),再次获取下一个元素I listbox

我在Win 64 sp2上运行D7 Enterprise

在我的程序中,我有两个列表框(lb1,Lb2)

Lb1最多可包含35.000个项目。(字符串[4]) Lb2最多可包含35.000个项目。(字符串[4])

两个列表框都已排序

Thera可能是列表框中的重复项(从0到30.000),我想找到这些重复项

我已经尝试了“自下而上”类型(例如:从listbox2的底部获取元素,从listbox1扫描到底部,标记相等的元素,(最终复制到第三个listbox2),再次获取下一个元素I listbox2 do sacn I listbox1并继续到顶部af listbox2。)

此方法确实有效,但非常繁琐且非常缓慢(大约需要8分钟(+/-)/35000件LB1/25000件LB2)

我想知道是否可以修改TStringList组件:TStringList.NoDuplicates;到
TStringList.getDuplicates;或者类似的,如果是这样,我该怎么做

或者我没有在TStringList组件中找到“隐藏的”(至少对我来说)可能性/方法吗

还是有第三种方法可以找到复制品

请帮忙

谢谢


KRIS

要比较两个排序的列表,您可以比较第一个条目,然后根据该比较推进一个或两个列表:

  • 相等:重复,前进到两个列表中的下一个
  • 第一个>第二个,前进到第二个列表中的下一个
  • 第二个>第一个,前进到第一个列表中的下一个
  • 一个或两个列表结束:完成

正如其他人所提到的,比较列表控件内的数据要比比较字符串列表或数组慢得多。

要比较两个排序的列表,您可以比较第一个条目,然后根据该比较推进一个或两个列表:

  • 相等:重复,前进到两个列表中的下一个
  • 第一个>第二个,前进到第二个列表中的下一个
  • 第二个>第一个,前进到第一个列表中的下一个
  • 一个或两个列表结束:完成

正如其他人所提到的,比较列表控件中的数据比比较字符串列表或数组要慢得多。

最好像手动操作一样,用手指沿着每个列表向下移动

这里有一个这样做的程序

procedure TFormTest.CompareLists(const Lista, Listb, Listc: TStrings);
var
  a, b, amax, bmax : integer;
begin
  aMax := Lista.Count;
  bMax := Listb.Count;

  Listc.Clear;

  a:=0;
  b:=0;

  while (a< aMax) and (b<bMax) do
  begin
    // Once either index goes past end of list we are done;
    case Sign( CompareStr( Lista[a], Listb[b])) of  // oer CompareText if not case sensitive
      -1:
      begin
        // ista[a] < List0[ b ]b
        inc( a );
      end;
      0:
      begin
        // a = b
        Listc.add( Lista[a] );  // same so could be either
        inc(a);
        inc(b);
      end;
      1:
      begin
        inc( b );
      end;
    end;
  end;
end;
procedure-TFormTest.CompareLists(const-Lista、Listb、Listc:TStrings);
变量
a、 b,amax,bmax:整数;
开始
aMax:=Lista.Count;
bMax:=Listb.Count;
Listc.Clear;
a:=0;
b:=0;

而(a 这里有一个这样做的程序

procedure TFormTest.CompareLists(const Lista, Listb, Listc: TStrings);
var
  a, b, amax, bmax : integer;
begin
  aMax := Lista.Count;
  bMax := Listb.Count;

  Listc.Clear;

  a:=0;
  b:=0;

  while (a< aMax) and (b<bMax) do
  begin
    // Once either index goes past end of list we are done;
    case Sign( CompareStr( Lista[a], Listb[b])) of  // oer CompareText if not case sensitive
      -1:
      begin
        // ista[a] < List0[ b ]b
        inc( a );
      end;
      0:
      begin
        // a = b
        Listc.add( Lista[a] );  // same so could be either
        inc(a);
        inc(b);
      end;
      1:
      begin
        inc( b );
      end;
    end;
  end;
end;
procedure-TFormTest.CompareLists(const-Lista、Listb、Listc:TStrings);
变量
a、 b,amax,bmax:整数;
开始
aMax:=Lista.Count;
bMax:=Listb.Count;
Listc.Clear;
a:=0;
b:=0;

而(aTStringList
变量:
A:=TStringList.Create;A.Assign(ListBox1.Items);B:=TStringList.Create;B.Assign(ListBox2.Items)
(当然,使用正确的
try.
块)。然后对
A
B
执行所有工作。那么您想找到两个列表框的交点,即两个列表框中存在的字符串吗?@Andreas Rejbrand:Yes不在第二个列表框中执行线性搜索,而是执行A。这将复杂性从O(n)降低到O(log n)。或者你可以用字典得到O(1)。@Andreas Rejbrand-可能是个好主意。我觉得,这种(新的)方法可能是最好的方法。(顺便说一句,我对我问题中文本的所有打字错误感到遗憾,-我有一个戴尔lbtop,键盘非常灵敏。我的控制读取完全失败。)如果出现任何问题,我会再试一次。谢谢angain。@fpiette是对的。只需将它们复制到两个本地
TStringList
变量:
A:=TStringList.Create;A.Assign(ListBox1.Items);B:=TStringList.Create;B.Assign(ListBox2.Items)
(当然,使用正确的
try.
块)。然后完成
A
B
上的所有工作。感谢代码。我将深入研究它,并(如有必要)修改它以满足我的需要。感谢代码。我将深入研究它,并(如有必要)修改它以满足我的需要。