%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % File: matelem.tu % Author: Gunnar Gotshalks % Date: 1997 January 21 % % This file implements the element class for sparse matrices. % % In a sparse matrix each element not only has a data value but also records % its row and column position, and pointers to the next row and column % elements. unit class MatrixElement export Initialize, Finalize, GetData, GetCol, GetRow, GetNextInRow, GetNextInCol, SetData, SetCol, SetRow, SetNextInRow, SetNextInCol type DataType : int var data : DataType % The data for the matrix element. var row : int % The row for the matrix element. var col : int % The col for the matrix element. var nextInRow : ^MatrixElement % Point to the next element in the row. var nextInCol : ^MatrixElement % Point to the next element in the column. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % Constructor and destructor operations. % % Initialize must be the first procedure called when using a matrix element. % % Precondition: True % Postcondition: The matrix element has row, column and data set. Pointers % are nil. procedure Initialize(theRow, theCol : int, theData : DataType) row := theRow col := theCol data := theData nextInRow := nil nextInCol := nil end Initialize %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % Finalize must be the last procedure called when using a matrix element. % % Precondition: Matrix element has been initialized. % Postcondition: All heap objects pointed to by the matrix element % are finalized and freed. procedure Finalize() % Nothing to do for this implementation. end Finalize %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % Accessor operations % Return data from a matrix element with no side effects. % % Precondition all: The corresponding matrix element fields have been % initialized by either using Initialize or the corresonding set % operation. % Postcondition all: Trivially implied by routine name. function GetData() : DataType result data end GetData function GetRow() : int result row end GetRow function GetCol() : int result col end GetCol function GetNextInRow() : ^MatrixElement result nextInRow end GetNextInRow function GetNextInCol(): ^MatrixElement result nextInCol end GetNextInCol %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % Set operations % Write data to fields in a matrix element with no other side effects. % % Precondition all: True. % Postcondition all: Trivially implied by routine name. procedure SetData(theData : DataType) data := theData end SetData procedure SetRow(theRow : int) row := theRow end SetRow procedure SetCol(theCol : int) col := theCol end SetCol procedure SetNextInRow(theElem : ^MatrixElement) nextInRow := theElem end SetNextInRow procedure SetNextInCol(theElem : ^MatrixElement) nextInCol := theElem end SetNextInCol end MatrixElement