Develop a fast ExistsInList(List, String) function
$30-400 USD
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.
Nº del proyecto: #4062161