Fastream Technologies wrote:
> So you are right in your saying that when Sorted = true, Add()'s are
> with binary search. But there is a HACK one needs to be very careful
> about: If you do not set Duplicates = dupAccept, then it calls
> IndexOf() before inserting to see if the same value exists!!
Both is not correct:
function TStringList.AddObject(const S: string; AObject: TObject): Integer;
begin
if not Sorted then
Result := FCount
else
if Find(S, Result) then <== binary search
case Duplicates of
dupIgnore: Exit;
dupError: Error(@SDuplicateString, 0);
end;
InsertItem(Result, S, AObject);
end;
And when Sorted = True IndexOf() uses binary search:
function TStringList.IndexOf(const S: string): Integer;
begin
if not Sorted then Result := inherited IndexOf(S) else
if not Find(S, Result) then Result := -1; <== binary search
end;
>
> That must have been the reason our code got that faster (not the to
> insert() change)!
See above.
--
Arno Garrels
--
To unsubscribe or change your settings for TWSocket mailing list
please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket
Visit our website at http://www.overbyte.be