Board index » delphi » TList and indexof..

TList and indexof..

Greetings Delphians,

   Quick question.. does the method "indexof" in Tlist object do a sequential
search?

  If it does, I'll better use something else...

Balance Trees anyone?

 

Re:TList and indexof..


In article <4ggfn4$...@isis.fiu.edu>, anola...@solix.fiu.edu says...

Quote
>Greetings Delphians,

hello

Quote
>   Quick question.. does the method "indexof" in Tlist object do a
sequential
>search?

Yes.  This is from the VCL source:

function TList.IndexOf(Item: Pointer): Integer;
begin
  Result := 0;
  while (Result < FCount) and (FList^[Result] <> Item) do Inc(Result);
  if Result = FCount then Result := -1;
end;

Quote
>  If it does, I'll better use something else...

>Balance Trees anyone?

:-O  

Re:TList and indexof..


In article <4ggfn4$...@isis.fiu.edu>,
alexander m nolasco <anola...@solix.fiu.edu> wrote:

Quote

>Greetings Delphians,

>   Quick question.. does the method "indexof" in Tlist object do a sequential
>search?

>  If it does, I'll better use something else...

>Balance Trees anyone?

Yes, it does do a sequential search. I think they very rationally decided that
most TList's would have a few hundred or thousand entries at most, and most
would have mere tens, and that simplicity of implementation was worth more
than optimizing a small percentage of the uses.
--

http://www.armory.com/~jon               Personal Pages
http://www.armory.com/~jon/pubs             Programming Publications
http://www.armory.com/~jon/hs         Home School Resource List

Other Threads