Staircase Matrix

By Roger Dunn

Freeware 31 Mar 2005

In category

Code Samples > Samples > Science

Description

A Staircase Matrix is useful when you want a matrix of objects where the value of cell (A, B) is guaranteed to be the same as the value of cell (B, A), and where referencing cell (A, A) or cell (B, B) is meaningless.

Staircase Matrices are useful when implementing fully- or partially-connected uni-directed graphs (or networks). If A and B are indexes in your own single-dimension array of nodes, cell (A, B) in the staircase matrix represents the weight or cost of the edge between nodes A & B.

This implementation of the Staircase Matrix is guaranteed to save space over a traditional matrix of size N x N. The underlying single-dimension array is length N(N-1)/2 (e.g. normally a 10x10 matrix fitting the staircase matrix paradigm would be 100 cells big. Using TStaircaseMatrix, the underlying array is only 45 cells big.) Accessing cells is almost as quick as if you were accessing an N x N matrix.

StaircaseMatrix.pas includes implementations for TStaircaseMatrixOfObjects, TStaircaseMatrixOfIntegers, TStaircaseMatrixOfStrings, TStaircaseMatrixOfVariants, and TStaircaseMatrixOfDoubles. More instructions on using these objects is included in a comments section at the top of the unit.

Informations

  • Status: Fully functional
  • Source: FW
  • Size: 3 090kB

Platforms:

  • Delphi 7

Downloads