I have a string list with 10,000 entries. I have a regular procedure, but access to any of the elements takes a lot of time. Passing through all 10k elements takes a huge amount of time.
I want to save it to disk and then make shuffle in a file using another method.
Any suggestions?
How is your regular shuffle done? Especially the exchange rate? If you wrote your own, follow these steps:
vTempSrting := vStringList[I]; vStringList.Delete(I); vStringList.Insert(J,vTempString);
he will be very slow. Use the exchange method in the string list.
78 (3-) :
program Project1; {$APPTYPE CONSOLE} uses SysUtils,Classes,uIntegerList,Windows,Math; procedure Shuffle(aSL : TStringList); var I,J : integer; begin for I := 0 to aSL.Count-1 do begin J := randomrange(I,aSL.Count); aSL.Exchange(I,J); end; end; procedure CreateTestFile; var vSL : TStringList; I : integer; begin vSL := TStringList.Create; try for I := 1 to 100000 do vSL.Add('Sample text #'+inttostr(I)); vSL.SaveToFile('c:\test.txt'); finally vSL.Free; end; end; function TestShuffle : longword; var vSL : TStringList; vTick0 : longword; begin vSL := TStringList.Create; try vTick0 := gettickcount; vSL.LoadFromFile('c:\test.txt'); Shuffle(vSL); vSL.SaveToFile('c:\test.txt'); Result := gettickcount - vTick0; finally vSL.Free; end; end; begin CreateTestFile; writeln(TestShuffle,' ms'); readln; end.
, .
, . . 10 000 , , , , , .
, , .
- , , . o (n * log (n)), o (n), .
, , , , , .
, - , , , , O (n)
PRNG,
- , , , . - , ( 32 64- ) . , N- , N * 4 ( N * 8 64- ), , .
, , . , , , , ( ) ( , ), , , (, SSD).
10K . - 10 , , ( , ), , ( - ) 32- .
Source: https://habr.com/ru/post/1720664/More articles:Qwidget, how to select widget under cursor - c ++Adding a new datagridview row to use defaults - sqlHow can I migrate a Java enumeration and still iterate over it? - javaHow to update Settings.settings when changing the type of saved data? - c #XSLT 2.0 support in JDK 6? - javaVerify that the row in the Oracle database column table does not exceed 2000 bytes - javaHow should I protect copyright and license my free software? - ruby | fooobar.comWhen is a custom enumeration / collection useful? - c #https://translate.googleusercontent.com/translate_c?depth=1&pto=aue&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=https://fooobar.com/questions/1720668/how-to-copy-a-table-schema-and-constraints-to-a-table-of-different-database&usg=ALkJrhhfwpkKT4Qvw9Y4je2NpEt9Kw6iXwCalculation and iteration order for physical engines - c #All Articles