Re: Finding maximum of an array
- From: "Anders Isaksson" <blockcad@xxxxxxxxxxxxxxx>
- Date: Mon, 28 Apr 2008 19:22:47 +0200
Richard Lavoie wrote:
The procedure below delete for a M x M matrix the value in a single
column L by shifting to the left every value to the right of this
column.
procedure SMatrix.ShiftAll(L, M : LongInt);
var
I, Ms: LongInt;
begin
Ms := (M-L)*4; // compute the size of the data to move
for I := 0 to M - 1 do begin // for every row in the matrix
PtRow := Matrix.Items[I]; // get the pointer of the
array of single values
Move(PtRow^[L+1],PtRow^[L],Ms); // move left all values
after L end;
end;
I do use the FastMove unit, so I wonder whether there is anything I
can do to speed ut the above procedure.
If you address your matrix indirectly through a Row vector and a Col vector
the 'deletion' will take almost no time at all. Just remove the row index
from the Row vector and the col index from the Col vector. No need to
actually move all the matrix data around.
The drawback (as I said in my previous post) is that all computational
references to the matrix gets a little extra time added, but as you've
gotten that part down to almost nothing, I think you can bear it :-)
The values in the Row vector is initialized to 0..3199, the Col vector the
same. Then when you want to delete a row R you just do
for i := R to CurrentMaxRow-1 do Row[i] := Row[i+1];
or use Move() and forget the loop!
Just remember: Every reference, Matrix[r, k], is replaced by Matrix[Row[r],
Col[k]] and that's it. As your Matrix is already a class, you don't even
have to change anything outside the class!
--
Anders Isaksson, Sweden
BlockCAD: http://web.telia.com/~u16122508/proglego.htm
Gallery: http://web.telia.com/~u16122508/gallery/index.htm
.
- Follow-Ups:
- Re: Finding maximum of an array
- From: Q Correll
- Re: Finding maximum of an array
- References:
- Finding maximum of an array
- From: Richard Lavoie
- Re: Finding maximum of an array
- From: John Herbster
- Re: Finding maximum of an array
- From: Richard Lavoie
- Re: Finding maximum of an array
- From: Dennis
- Re: Finding maximum of an array
- From: Richard Lavoie
- Re: Finding maximum of an array
- From: Dennis
- Re: Finding maximum of an array
- From: Richard Lavoie
- Finding maximum of an array
- Prev by Date: Designing high performance (SQlconnection) Pool
- Next by Date: Re: Finding maximum of an array
- Previous by thread: Re: Finding maximum of an array
- Next by thread: Re: Finding maximum of an array
- Index(es):
Relevant Pages
|