[fpc-devel] Questions on TStringList.Find change (Mantis 28744)
Denis Kozlov
dezlov at gmail.com
Tue Mar 22 15:41:01 CET 2016
Find method must find an item in the list. Whether the list is sorted or
not, whether the binary search optimization can be applied or not - are
implementation details.
Find method should either:
1) Raise exception if list is not sorted,
2) Use IndexOf method if the list is not sorted (preferable).
Adding optional parameters is hardly a good solution. Instead, add a
FindSorted method.
To summarise:
procedure Find(const S: string; out Index: Integer):Boolean;
begin
if Sorted then
Result := FindSorted(S, Index);
else
begin
Index := IndexOf(S);
Result := (Index >= 0);
end;
end;
procedure FindSorted(const S: string; out Index: Integer):Boolean;
begin
if not Sorted then
raise Exception.Create('List must be sorted');
// search logic here...
end;
Denis
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-devel/attachments/20160322/04a55444/attachment.html>
More information about the fpc-devel
mailing list