关于快速格式化数据-超过10W条以上(100分)

  • 主题发起人 主题发起人 flfqnet
  • 开始时间 开始时间
F

flfqnet

Unregistered / Unconfirmed
GUEST, unregistred user!
有一给定的自定义数据库,数据结格已经知道
本人使用如下方法读取,但发现1-2W条的话是很快的,但大数量的就很慢

PSong_ZTData=^TSong_ZTData;
TSong_ZTData=record
Code:array[0..7] of char;
Name:array[0..39] of char;
Language:array[0..7] of char;
Num:array[0..1] of char;
Singer1:array[0..15] of char;
Singer1Code:array[0..3] of char;
Singer2:array[0..15] of char;
Singer3Code:array[0..3] of char;
Version:array[0..7] of char;
type1:array[0..7] of char;
type2:array[0..7] of char;
PinYin:array[0..7] of char;
ZhuYin:array[0..7] of char;
index:array[0..7] of char;
tutti:char;
bookman:array[0..9] of char;
charset:array[0..7] of char;
s_name:array[0..39] of char;
Source:array[0..5] of char;
quality:array[0..3] of char;
End;

Var
SongInfo_User_List:TList; //Usersong.dat

{************* 初始化 用户歌库 usersong.dat 歌曲信息**************}
Function TZTData.IniUserSongInfo(FilePath:string):Boolean;
Var
TS:TstringList;
iCount:integer;
SongInfoTemp:TSong_ZTData;
StrTemp:String;
_PSongInfo:PSong_ZTData;
Begin
Result:=False;
TS:=TstringList.Create ;
Try
if FileExists(FilePath) then
Begin
TS.LoadFromFile(FilePath);
TS.Sort ;//排序 (按歌曲编号排列)
for iCount:=0 to ts.Count -1 DO
Begin
StrTemp:= TS.Strings[icount];
SongInfoTemp:=PSong_ZTData(StrTemp)^;
Try
New(_PSongInfo);
_PSongInfo^:=SongInfoTemp;
SongInfo_User_List.Add(_PSongInfo);
Result:=True;
Except
End; //Try
End; //for iCount:=0 to ts.Count -1 DO
End;
EXCEPT
Result:=False;
End;
TS.Free ;
End;

//如果读取 15M 数据量的话,在P4 2.8G(超线程) 512M 情况下约要半分多钟
//如果是5M 数据量的话,一眨眼就好了
 
发现是排序的问题
 
10万以上数据最好用sql,建立全文索引
或者用哈希表,这个我正在研究
 
我自己是没用过,但建议尝试用一下DELPHI2006中的FOR IN DO语句来替换for to DO语句看看是否有效果,据说FOR IN语句的效率上是较有改观的语句了。
 
建立全文索引
 
因为数据库是别人的,是在LINUX下使用的
本人现在在WINDOWS进行读取整理对比纠错工作
 
即然知道TS.Sort的问题,你就将那行注掉
然后用SongInfo_User_List来排序

function SongDataCompare(S1, S2: PChar): Integer;
var
I: Integer;
begin
Result := 0;
Count := 8;
while Count > 0 do
begin
if S1^ > S2^ then
begin
Result := 1;
Exit;
end else
if S1^ < S2^ then
begin
Result := -1;
Exit;
end;
// else继续
Inc(S1);
Inc(S2);
Dec(Count);
end;
end;

// TS.Sort;

for iCount:=0 to ts.Count -1 DO
Begin
StrTemp:= TS.Strings[icount];
SongInfoTemp:=PSong_ZTData(StrTemp)^;
Try
New(_PSongInfo);
_PSongInfo^:=SongInfoTemp;
SongInfo_User_List.Add(_PSongInfo);
Result:=True;
Except
End; //Try
End; //for iCount:=0 to ts.Count -1 DO

SongInfo_User_List.Sort(@SongDataCompare);
...


BTW: 代码习惯请改好些,最起码缩进要整齐。
 
Count := 8; ==》 SizeOf(TSong_ZTData.Code)
 
谢谢,我去试试看.
代码是C+C C+V
所以都没有缩进了
 
不要使用tstringlist,直接用tlist看看.
 
不明白hityou什么意思
 

Similar threads

S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
I
回复
0
查看
743
import
I
I
回复
0
查看
693
import
I
后退
顶部