[nem-pl] Komparatory w drzewach

"Paweł W. Olszta" Pawel.Olszta at adv.pl
Thu Jan 15 17:34:07 CET 2004


Lukasz Kaiser wrote:

> Hej.
> 
> 
>>  1) teraz jest tak, ze kazdy wierzcholek ma w sobie wskaznik na swoj
>>  komparator (jak sie mozna domyslec srednio efektywne i niepotrzebne bo i tak
>>  wszystkie maja ten sam)
>>  2) zrobic z drzew klase i przekazywac jej komparator w konstruktorze
>>   (lepiej i narazie taki jest pomysl)
> 
> 
> Moglbys mi to wytlumaczyc, bo ja nie rozumiem dokladnie o co ci chodzi.
> Masz typ RBtree 'a i przekazujesz w 'a funkcje porownujaca ?
> Nie masz interface'u czy tez interface'y sa nieefektywne ?
> Nie chcesz przekazywac funkcji porownujacej jako argumentu funkcji na
> drzewach ze wzgledu na elegancje czy jakichs innych ?
> Ja przepraszam ze gadam a nie poczytalem kodu, ale moze ktos mi szybko
> wytlumaczy i oszczedzi zabawy :).

Oj oj, Łukasz ma rację. Żyjemy w świecie obiektów, jak bardzo by nas to 
nie bolało. Interfejsy są bardzo efektywne -- metody wirtualne 
przechowywane są w końcu tylko w jednej kopii. Przekazywanie komparatora 
jako argumentu, to dodatkowy push i pop co jakiś czas -- zupełnie bez sensu.

Mamy interfejs System.IComparable. Implementuje go np. System.String i 
System.Int32. Wystawia on nam metodę:

   [C#]
   int CompareTo(
      object obj
   );

Parameters
   obj  --  An object to compare with this instance.

Return Value
   A 32-bit signed integer that indicates the relative order of the 
comparands. The return value has these meanings:

Value Meaning
   Less than zero This instance is less than obj.
   Zero This instance is equal to obj.
   Greater than zero This instance is greater than obj.

Exceptions
   ArgumentException obj is not the same type as this instance.

I chyba nic więcej nie potrzebujemy?

-- 
My opinions may have changed, but not the fact
that I am right. -- Ashley Brilliant





More information about the devel-pl mailing list