Saturday 10 April 2021

Array Types Part 5 | PPL | Sebesta | Elementary Data Types in Programming Language

                  In this post, we will see Array Types Part 5 | PPL | Sebesta | Elementary Data Types in Programming Language | array types, data types in ppl, data types ppl, elementary data types in programming language, ppl, sebesta  


VII. Slices

 

Consider the following Python declarations:

vector = [2, 4, 6, 8, 10, 12, 14, 16]

mat = [[1, 2, 3],[4, 5, 6],[7, 8, 9]]

 

Slices:

vector[3:6] returns [8, 10, 12]

vector[0:7:2] returns [2, 6, 10, 14]

mat[0:2] returns [[1, 2, 3], [4, 5, 6]]

 

 

VIII. Implementation of Array Types:

              Address of list[k] is calculated as follows:

address( list[k] ) = address( list[0] ) + k * element_size

 

Generalization:

 

address( list[k] ) = address( list [lower_bound]) +

(( k - lower_bound) * element_size)

 

 

Row major order & Column major order

 

For example, if the matrix had the values

 

3     4     7

6     2     5

1     3     8

 

it would be stored in row major order as

3, 4, 7, 6, 2, 5, 1, 3, 8

 

If the example matrix were stored in column major order, it would have the following order in memory:

3, 6, 1, 4, 2, 3, 7, 5, 8

 

              Column major order is used in Fortran, but other languages that have true multidimensional arrays use row major order.

 

 

Compile-time descriptor for single-dimensioned arrays:



 

A compile-time descriptor for a multidimensional array:




Watch following video:

Watch on YouTube: https://www.youtube.com/watch?v=ohzkc9W_xFE


No comments:

Post a Comment