Develop a fast ExistsInList(List, String) function

Completado Publicado Dec 21, 2012 Pagado a la entrega
Completado Pagado a la entrega

Here is a simple function:

==

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

Var

i : Integer;

Begin

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

begin

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

begin

Result := True;

Break;

End;

End;

End;

==

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.

Algoritmos Delphi

Nº del proyecto: #4062161

Sobre el proyecto

2 propuestas Proyecto remoto Activo Dec 21, 2012

Adjudicado a:

benny34

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

$50 USD en 4 días
(1 comentario)
1.7

2 freelancers están ofertando un promedio de $100 por este trabajo

crazyboy327

Hi,sir. Please check your PMB.

$150 USD en 4 días
(1 comentario)
1.6