| Register | FAQ | Calendar | Search | Today's Posts | Mark Forums Read |
|
#1
| |||
| |||
| I'm scanning a directory for files and add all files into a TListview with two columns. Column1 holds the file name, Column2 the date on which the file was created. The Listview is sorted by file creation date. Now, there is of course a good chance that several files have the same creation date. How can I most efficiently add the number of occurances of the same file date within the Listview and get the values into a stringlist? Something like '12/24/2007 (3 files)'. The number of files in this folder might be huge, so I probably need to do various additions simultaniously to speed things up. Thanks Uwe |
|
#2
| |||
| |||
| Uwe wrote: > I'm scanning a directory for files and add all files into a TListview > with two columns. Column1 holds the file name, Column2 the date on which > the file was created. The Listview is sorted by file creation date. Now, > there is of course a good chance that several files have the same > creation date. How can I most efficiently add the number of occurances > of the same file date within the Listview and get the values into a > stringlist? Something like '12/24/2007 (3 files)'. The number of files > in this folder might be huge, so I probably need to do various additions > simultaniously to speed things up. > > Thanks > Uwe > My first thought would be to use an inverted list with the date as the term and the filename as the address converter key. A simple implementation could use a tHashedStringList for terms and each term entry would in turn use another tHashedStringList in its associated object entry for its key occurrences. So the Inverted list might look something like this termslist.strings[i] : '12/24/2007' : termslist.objects[i] => 'file1', 'file2', 'file3' termslist.strings[j] : '12/25/2007' : termslist.objects[j] => 'file4', 'file5' Then the keys tHashedStringList tells you exactly how many files you have in each term. quick sketch of method might look something like this (a lot is left out (destruction, duplicate handling, sorting, etc); this is just to get the idea) => ------------- type tInvertedList = class(tHashedStringList) public procedure invertTerm(term,key:string); end; procedure invertterm(term,key:string) var idx : integer; keys : tHashedStringList; begin idx := indexof(term); if (idx < 0) then begin keys := tHashedStringList.create; idx := self.addobject(term,keys); end; keys := self.objects[idx]; keys.add(key); end; ------------- Then do something like: var invertedlist : tInvertedList; var filename : string; var datestring : string; var idx : integer; var occurances : tHashedStringList; invertedlist := tInvertedList.create; .... // populate inverted list PositionAtFirstFile; while morefiles do begin datestring := FileDateAsString(CurrentFile); filename := FileNameOf(CurrentFile); invertedlist.InvertTerm(datestring,filename); end; // populate list view for idx := 0 to invertedlist.count - 1 do begin occurances := invertedlist.objects[idx]; datestring := invertedlist[idx] + ' (' + inttostr(occurances.count) + ' files)'; BuildListViewRows(datestring,occurances); end; Using a technique more efficient than a tHashedStringList is left to you as an exercise (dynamic arrays perhaps?). I usually don't bother as I find hashed lists quite good enough. I use inverted lists like this for in memory indexes quite a bit. Often the key in the occurances list essentially a bookmark to a data record. |
|
#3
| |||
| |||
| Hi Keith Thanks a lot. That gives me something to think about. Uwe |
|
#4
| |||
| |||
| > The number of files > in this folder might be huge, so I probably need to do various additions > simultaniously to speed things up. Make use of BeginUpdate and EndUpdate to speed things up. If it's still too slow consider using Mike Lischke's TVirtualTreeView. -- Jens Gruschel http://www.pegtop.net |
|
#5
| |||
| |||
| Jens Gruschel wrote: >> The number of files in this folder might be huge, so I probably need >> to do various additions simultaniously to speed things up. > > Make use of BeginUpdate and EndUpdate to speed things up. If it's still > too slow consider using Mike Lischke's TVirtualTreeView. Or use TListView.OwnerData, which makes TListView virtual. See the help for more info. BR, Jouni |
|
#6
| |||
| |||
| Hi Jens I'm using both already... ;-) The reason why I was asking is that the folder can contain thousands of files, and I'm not only retrieving file dates but also some metadata. The latter can be painstakingly slow, so I really need to find a way to do simultanious sorts on a larger number of attributes/metadata first, before I can add up the number of occurances. I might go with Keith's proposal, but I will also check out if an in-memory-table is faster. Thx Uwe "Jens Gruschel" <nospam@thisurldoesnotexist.com> wrote in message news:489aa051@newsgroups.borland.com... >> The number of files in this folder might be huge, so I probably need to >> do various additions simultaniously to speed things up. > > Make use of BeginUpdate and EndUpdate to speed things up. If it's still > too slow consider using Mike Lischke's TVirtualTreeView. > > -- > Jens Gruschel > http://www.pegtop.net |
![]() |
| Thread Tools | |
| Display Modes | |
In an effort to better serve ads to our visitors, cookies are used on objectmix.com. For more information, check out our Privacy Policy.