Delphi in a Nutshell coverDelphi in a Nutshell

by Ray Lischner

Cltn50 package


[ Tempest Software | Delphi in a Nutshell | Examples | NutShl50 package ]

The Cltn50 runtime package is a suite of collection interfaces and classes. To store something in a collection, you must implement the ICollectible interface. The interface can then be stored in any collection. The framework is extensible: you can add new collection interfaces and new implementations. See Printable.pas for an example of using the collection classes.

The ICollectible interface declares only two methods:

type
  THashValue = 0..MaxInt;
  ICollectible = interface
  ['{618977E1-1ADA-11D3-B1A8-00105AA9C2AD}']
    // Return a value < 0 if Self<Obj
    //                = 0 if Self=Obj
    //                > 0 if Self>Obj
    function CompareTo(const Obj: ICollectible): Integer;
    // Return a unique hash value. If two objects are equal (CompareTo=0)
    // their hash values must also be equal, but the reverse is not
    // necessarily true.
    function HashValue: THashValue;
  end;

All collection inherit the same ICollection interface. Different collections define interfaces that are appropriate:

All collections have enumerators, which let you access all the elements of a collection. All enumerators inherit from IEnumerator.

The interfaces define the abstract collection behavior. Different classes provide concrete implementations of these interfaces using arrays, linked lists, hash tables, and red-black trees. The following units make up the package:

Cltn.pas
Declares the basic collection interfaces and a number of useful classes.
CltnArrays.pas
Implements collections using arrays.
CltnHash.pas
Implements hash tables using open hashing.
CltnList.pas
Implements doubly-linked lists.
CltnRbTree.pas
Implements red-black trees.

[ Tempest Software | Delphi in a Nutshell | Examples | NutShl50 package ]