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:

  THashValue = 0..MaxInt;
  ICollectible = interface
    // 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;

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:

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

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