比較する必要があるいくつかのファイル (3-5) があり
ます。ファイル 1.txt には 100 万の文字列があります。
ファイル 2.txt には 1000 万の文字列があります。
ファイル 3.txt には 500 万の文字列があります。
これらのファイルはすべてファイル keys.txt (10,000 文字列) と比較されます。現在開いているファイルの行が keys.txt の行の 1 つと同じ場合は、この行を output.txt に書き込みます (私の言いたいことを理解していただければ幸いです)。
今私が持っています:
function Thread.checkKeys(sLine: string): boolean;
var
SR: TStreamReader;
line: string;
begin
Result := false;
SR := TStreamReader.Create(sKeyFile); // sKeyFile - Path to file keys.txt
try
while (not(SR.EndOfStream)) and (not(Result))do
begin
line := SR.ReadLine;
if LowerCase(line) = LowerCase(sLine) then
begin
saveStr(sLine);
inc(iMatch);
Result := true;
end;
end;
finally
SR.Free;
end;
end;
procedure Thread.saveStr(sToSave: string);
var
fOut: TStreamWriter;
begin
fOut := TStreamWriter.Create('output.txt', true, TEncoding.UTF8);
try
fOut.WriteLine(sToSave);
finally
fOut.Free;
end;
end;
procedure Thread.updateFiles;
begin
fmMain.flDone.Caption := IntToStr(iFile);
fmMain.flMatch.Caption := IntToStr(iMatch);
end;
そしてループ
fInput := TStreamReader.Create(tsFiles[iCurFile]);
while not(fInput.EndOfStream) do
begin
sInput := fInput.ReadLine;
checkKeys(sInput);
end;
fInput.Free;
iFile := iCurFile + 1;
Synchronize(updateFiles);
したがって、これら 3 つのファイルをファイル key.txt と比較すると、約 4 時間かかります。比較時間を短縮するには?