Jump to content

mapping function?

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
3 replies to this topic

#1
Apprentice123

Apprentice123

    Programming Expert

  • Members
  • PipPipPipPipPipPip
  • 430 posts
What is mapping function ?

It's about matrix


Knowing:
Eb => starting address of the memory area
t => size in bytes of each element

a) one-dimensional
Function:
fm(i) = Eb + t*(i-1)

b) two-dimensional
Function:
fm(i,j) = Eb + t*[(i-1)*n + j-1]


I have these formulas, but I do not understand

#2
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
Draw a picture of a 2D array and resequence the rows into a single row and number them.
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

#3
Apprentice123

Apprentice123

    Programming Expert

  • Members
  • PipPipPipPipPipPip
  • 430 posts
How can I do in C?

It's about mapping function matrix. The two-dimensional mapping function is:
fm(i,j) = Eb + t*[(i-1)*n +j-1]

Algorithm creates an array data type with the specified function, knowing that proc (procedure) to pass the parameter by reference.

Algorithm:

TAD matrix def

      rep = reg(  val:vet[1...max] of value;    "vector for the elements"

                  eb: int;                      "address (cursor) initial"

                  t: int;                       "size of the elements"

                  d: int;                       "number of dimensions"

                  L1,L2: int)                   "limits of rows and columns"

      op = proc create_twodim(M: matrix; L1, L2: int);

           proc attribution(M: matrix; i, j: int; v: value);

           func query(M: matrix; i, j: int) return value;

           func row_dim(M: matrix, k: int) return int;

end matrix;

TAD matrix implem;

      func fm(i, j: int) return int;

      "Dimensional mapping function"

      begin

         return M.eb +M.t*[(i-1)*M.L2 + j-1]

      end;

      func row_dim(M: matrix, k: int) return int;

            "Provides the limit of one dimension of the matrix M"

            begin

               if k = 1

                  then return M.L1

               else of k = 2

                  then return M.L2

               else error("Invalid size!")

            end;

      proc create_twodim(M: matrix; L1, L2: int);

           "Sets the contents of the two-dimensional descriptor"

           begin

              M.eb := 1;

              M.t := 1;

              M.d := 2;

              M.L1 := L1;

              M.L2 := L2;

           end;

      proc attribution(M: matrix; i, j: int; v: value);

           "Associates the value v to the indices i, j in M"

           begin

             if i <= M.L1 & j <= M.L2

                then M.val[ fm(i,j) ] := v;

                else error("Indexes invalid!");

           end;

      func query(M: matrix; i, j: int) return value;

           "Provides the value associated with indices i, j in M"

           begin

             if 0 < i <= M.L1 & 0 < j <= M.L2

                then return M.val[ fm(i,j) ]

                else error("Indexes invalid!");

           end;

end matrix



#4
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
You shouldn't need the -1's
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog