Front page | perl.perl6.internals |
Postings from July 2002
Initial Matrix class
Thread Next
From:
Josef Höök
Date:
July 15, 2002 01:30
Subject:
Initial Matrix class
Message ID:
Pine.GSO.4.21.0207150957180.6959-100000@chicken.stacken.kth.se
I have successfully written and read an 8x8 matrix.
I will start writing some documentation.
Current code lacks a proper representation of a matrix ( it doesnt have a
matrix structure ) , it works directly in a Buffer structure. I really
need some people to discuss ideas with before deciding the Matrix
structure. This code also lacks a dynamic allocation. I think i will
implement a similar pool as perlhash bucket->pool.
I also have the code in a "old key styled parrot" version so i would
apreciate if someone told me how the new vtable structure will look like.
I also added a init_keyed function in my version of vtable something that
cvs of parrot lacks. Is this something that we may add later i do need it.
The implementation represent a point or a CELL with a pointer to data and
a virtual_addr.
Y
|
| ------------
| [ 7 ][ 8 ][ 9 ]
| [ 4 ][ 5 ][ 6 ]
| [ 1 ][ 2 ][ 3 ] <-------- a CELL
|------------------ X
|-----------|
X0
CELL:
struct _cell {
INTVAL *data;
INTVAL *virtual_addr; // this one is used to handle offsets
INTVAL submatrix; // Answers the question are we a submatrix
};
The virtual_addr is the answer from a calculation of a CELL's position:
the equation looks like this (y-1)X0+x
lets say we want a number representation on cell
[2,2] accordingly to our equation it would be 5
[2,2] = 5.
The return (5) value is then used as an offset value from Buffer
base address. The offset value (5) is stored in virtual_addr.
and is later on read when reading a CELL in a certain location.
Current code hase complexity:
O(1) writing.
O(1) reading and in worst case O(N).
This kind of implementation has a major drawback and thatis when doing
dynamic growth of the matrix the offset value would then be corrupted.
But i have a couple of ideas on howto solve this. One way could be glueing
several submatrices toghether or another way would be a polymorphic
equation.
The good thing is that it would be possible to represent a
multidimensional array fairly the same way, though the equation would grow
linearly as dimensions grow.
/Josef
Thread Next
-
Initial Matrix class
by Josef Höök