Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

column major or row major.

by robo_kevs_009 (Initiate)
on Aug 09, 2009 at 10:16 UTC ( [id://787151]=perlquestion: print w/replies, xml ) Need Help??

robo_kevs_009 has asked for the wisdom of the Perl Monks concerning the following question:

Hello monks, I'm new to Perl and I just wanted to ask everybody if the array in perl implements column major or row major.

Replies are listed 'Best First'.
Re: column major or row major.
by moritz (Cardinal) on Aug 09, 2009 at 10:23 UTC
    Neither. Arrays are just arrays (and hopefully sequential in memory).

    If you implement a matrix as an array of arrays, it can be either row or column major, depending on whether you define the first index to be a row or a column index.

      Arrays are just arrays (and hopefully sequential in memory).
      There's some part of the array that is sequential in memory, and that's the "C" array containing pointers to the SVs holding the structures holding the values of the elements. The SVs themselves could be anywhere.
Re: column major or row major.
by betterworld (Curate) on Aug 09, 2009 at 11:00 UTC

    Two-dimensional arrays in Perl are implemented either as arrays of array references (where the references may reference arrays that are stored at any arbitrary memory location), or using hashes where there are special separators in the hash keys.

    Neither of these methods guarantees the order in which the elements are stored in memory, and there is no straightforward way to iterate over the elements in sequence. Therefore the concept of row major cannot be applied imho.

    If one needs a two-dimensional structure on a one-dimensional array, it's usually done by hand as in $array[$row * $columncount + $column]. Maybe one could use operator overloading to access these kinds of arrays with the usual $array[$row][$column] syntax.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://787151]
Approved by moritz
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (4)
As of 2024-04-25 02:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found