Develop a fast ExistsInList(List, String) function

Here is a simple function:


Function ExistsInList(List : TStringList; Data: String) : Boolean;


i : Integer;


For i := 0 to List.Count-1 do


If Pos(List[i], Data) > 0 then


Result := True;






Your job is to design and implement in Delphi a speed optimized version of the function. The optimization can take into account the following information that we know about the input data:

1. The List of search words is sorted and usually small (usually 0..10 items)

2. The List of search words usually contains one or more strings which have identical beginning, e.g.:

Foobar 123

Foobar 443 gfd ds

Windows hhgff

Windows Foo

3. The Data input is usually very similar to the Data input of the previous function call. For example, the function is usually called like this:

ExistsInList(List, "foo-foobar-")

ExistsInList(List, "foo-foobar-foo")

ExistsInList(List, "foo-foobar-foobar 123") //Returns true, if the List contains "Foobar 123".

ExistsInList(List, "foo-foobar-foobar 123-fdsfads")

You can implement this as a class or with global variables, if you want to do some pre-processing or if you want to store some data. The function is called almost a million times in a real world application and these calls sum up to almost 800 seconds of runtime.

The code must compile and work under Delphi 2010. You must not use any assemply or any hacky (non-documented) solutions. Unlike the sample code above, the actual function should be case insensitive.

Evner: Algoritme, Delphi

Se mere: delphi fast list, up string, to string, sum of the solutions, string the, string search in c, string search algorithm c, string search algorithm, string processing in c, string processing algorithm, string i, string algorithm, some search string, simple search algorithm, simple algorithm example, search string in c, search string c, search string, search c string, search algorithm example, pos world, pos algorithm, fast string search algorithm, example of a algorithm, example algorithm

Om arbejdsgiveren:
( 591 bedømmelser ) Turku, Thailand

Projekt ID: #4062161

Tildelt til:


Hi sire, i can do this job for you if you offer me this chance.

$50 USD in 4 dage
(1 bedømmelse)

2 freelancere byder i gennemsnit $100 på dette job


Hi,sir. Please check your PMB.

$150 USD in 4 dage
(1 bedømmelse)