Re: Fast appending and sorting of alot of short strings
- Posted by Pete Lomax <petelomax at blueyonder.co.uk> Oct 10, 2004
- 494 views
On Sun, 10 Oct 2004 02:02:33 -0700, Tommy Carlier <guest at RapidEuphoria.com> wrote: >I can't do this. The Collection-routines are for general use, not only >for one specific library. There are at least 10 different kinds of >collections in Win4Eu. >However, if anyone can optimize the routines, without changing the >functionality, I would really be grateful. Collections are used a lot >in Win4Eu, especially on the lowest level. How about giving external programs an integer index, rather than letting/making them store the table as a sequence. Using a table of tables internally, you can do this:
sequence AllMyTables global function newCollectionIdx() AllMyTables=append(AllMyTables,BUFFER) return length(AllMyTables) end function global procedure addToTable(integer tableid, object element) integer count, growSize sequence OneOfMyTables OneOfMyTables=AllMyTables[tableid] AllMyTables[tableid]=0 --<<-- Ensure Ref Count of 1!! count = OneOfMyTables[length(OneOfMyTables)] + 1 growSize = count - length(OneOfMyTables) if growSize > 0 then if growSize > GROWSIZE then OneOfMyTables &= repeat(0, growSize + GROWSIZE) else OneOfMyTables &= BUFFER end if end if OneOfMyTables[count] = element OneOfMyTables[length(OneOfMyTables)] = count AllMyTables[tableid]=OneOfMyTables end procedure ... integer MyTbleIdx MyTbleIdx=newCollectionIdx() addToTable(MyTbleIdx,c1)
Despite the fact that it looks like you are copying huge chunks of data about, it only copies the top level ref, which is nearly as fast as assigning an integer. By temporarily removing the table to be updated from your table of tables, you avoid reference counts of >1, which trigger the creation of new sequences. Done this way, however, it is only 57 times faster ) Regards, Pete PS I couldn't see the purpose of: if growSize > GROWSIZE then collection &= repeat(0, growSize + GROWSIZE)