Donovan,
If the
range of ID's are not too sparse then an array would be a very direct way of
looking them up.
Another way would be a linked list of records or a 2 dimensional
array holding ID and Code, and pre-sort the list by ID. then look it up
with a binary search or B-Tree or similar.
For
replacing strings see StringReplace. There are faster alternatives - I recall
something by Peter Morris a while back called
FastStrings.pas.
For
what you are doing though, you probably want to parse the string first, then on
each ID do a lookup for PlayerCode then replace the string. Then because you
know the position of the ID in the string, you would use delete and insert (or
copy) to replace the string.
regards,
Steve
-----Original Message-----All,
From: Donovan J. Edye [mailto:[EMAIL PROTECTED]]
Sent: Friday, 13 July 2001 17:12
To: Multiple recipients of list delphi
Subject: [DUG]: How to approach this?
I have to do the following:
- Replace some numeric integers with string values in a string
- The position of the integers the string may vary
- It all has to be as fast as possible
What we have are some paradox tables with the following format: (TPlayerID : integer)
TableA
PlayerID : TPlayerID
FirstName : string;
SecondName : string;
TableB
BatsmanID : TPlayerID
BowlerID : TPlayerID
Field1
Field2
Field3
OtherBatsmanID : TPlayerID
Field4
etc.
Assume we have the following TPlayerID - TPlayerCode mappings. TPlayerCode : string[5]
1 - ABCDE
2 - FGHIJ
3 - MNOPQ
etc.
If we get strings as follows - say read from a text file:
PlayerID, FirstName, SecondName
3,John,Doe
BatsmanID, BowlerID, Field1, Field2, Field3, OtherBatsmanID, Field4
1,3,a,b,c,2,e
PlayerID, FirstName, SecondName
1,Paul,Smith
BatsmanID, BowlerID, Field1, Field2, Field3, OtherBatsmanID, Field4
2,1,a,b,c,3,e
Question 1:
- What is the most efficient way to store the TPlayerID, TPlayerCode as a memory structure mappings so that:
- Minimal memory footprint
- Fastest searching
The above mappings list does not generally change a lot. So "slow" creation of the mapping list is not a big concern. Typically the mapping list is created once and accessed many. It is nominally read only.
Question 2:
- What is the most efficient way to replace a specific string with another? So given:
BatsmanID, BowlerID, Field1, Field2, Field3, OtherBatsmanID, Field4
1,3,a,b,c,2,e
End up with
BatsmanID, BowlerID, Field1, Field2, Field3, OtherBatsmanID, Field4
ABCDE,MNOPQ,a,b,c,FGHIJ,e
Comments, suggestions welcome. TIA-- Donovan
----------------------------------------------------------------------
Donovan J. Edye [www.edye.wattle.id.au]
Namadgi Systems [www.namsys.com.au]
Voice: +61 2 6285-3460
Fax: +61 2 6285-3459
TVisualBasic = Class(None);
Heard just before the 'Big Bang': "...Uh Oh...."
----------------------------------------------------------------------
GXExplorer [http://www.gxexplorer.org] Freeware Windows Explorer
replacement. Also includes freeware delphi windows explorer components.
----------------------------------------------------------------------