1
0
Fork 0
cl-sites/novaspec.org/cl/f_array-row-major-index.html
2025-02-05 18:52:26 +01:00

228 lines
No EOL
5.1 KiB
HTML

<!DOCTYPE HTML>
<HTML LANG="en-us"
><HEAD
><TITLE
>array-row-major-index | Common Lisp Nova Spec</TITLE
><META CHARSET="US-ASCII"
><LINK REL="canonical" HREF="f_array-row-major-index.html"
><LINK REL="next" HREF="f_array-total-size.html" TYPE="text/html" TITLE="array-total-size"
><LINK REL="prev" HREF="f_array-rank.html" TYPE="text/html" TITLE="array-rank"
><LINK REL="up" HREF="15_2_Arrays_Dictionary.html" TYPE="text/html" TITLE="15.2 Arrays Dictionary"
><LINK REL="start" HREF="index.html" TYPE="text/html" TITLE="Common Lisp Nova Spec"
><META NAME="VIEWPORT" CONTENT="width=device-width, initial-scale=1.0"
><LINK REL="STYLESHEET" HREF="dpans.css%3F3909942064.css"
><SCRIPT SRC="dpans.js%3F3909942064"
></SCRIPT
><SCRIPT SRC="apropos.js%3F3909942064"
></SCRIPT
></HEAD
><BODY
><DIV
><DIV CLASS="topnav"
><DIV CLASS="breadcrumb"
><SPAN CLASS="breadcrumb-item"
><A HREF="index.html"
>Common Lisp Nova Spec</A
></SPAN
> <SPAN CLASS="breadcrumb-item"
>&#8594; <A HREF="15_Arrays.html"
>15. Arrays</A
></SPAN
> <SPAN CLASS="breadcrumb-item"
>&#8594; <A HREF="15_2_Arrays_Dictionary.html"
>15.2 Arrays Dictionary</A
></SPAN
> <SPAN CLASS="breadcrumb-item"
>&#8594; <A HREF="f_array-row-major-index.html"
>array-row-major-index</A
></SPAN
></DIV
><DIV CLASS="apropos"
><DIV CLASS="apropos-io"
><A HREF="f_array-rank.html" CLASS="prev"
>&#8592;</A
><SPAN ID="apropos-label"
>Apropos </SPAN
><INPUT ID="apropos" AUTOFOCUS="AUTOFOCUS" PLACEHOLDER="Type here to search" ONINPUT="aproposInput(this);" ONKEYUP="aproposKeyup(event);" ONCHANGE="aproposChange(this);" ONFOCUS="aproposFocus(this);" ONFOCUSOUT="aproposFocusout(this);"
><A HREF="f_array-total-size.html" CLASS="next"
>&#8594;</A
></DIV
><DIV ID="apropos-res"
></DIV
></DIV
></DIV
><DIV CLASS="matter"
><DIV CLASS="com"
><DIV CLASS="begincom"
><HR
><TABLE WIDTH="100%" CELLSPACING="0" CELLPADDING="0"
><TR
><TD ALIGN="LEFT" VALIGN="BASELINE" WIDTH="100%" CLASS="name"
><SPAN CLASS="idx" DATA-KIND="idxref" DATA-TERM="array-row-major-index"
></SPAN
><B
>array-row-major-index</B
></TD
><TD ALIGN="RIGHT" VALIGN="BASELINE" WIDTH="0" NOWRAP="NOWRAP" CLASS="ftype"
><I
>Function</I
></TD
></TR
></TABLE
><HR
></DIV
><UL CLASS="subtoc"
></UL
><DL
><DT
><B
>Syntax</B
></DT
><DD
><P CLASS="j"
><B
>array-row-major-index</B
> <SPAN CLASS="cmssi"
>array</SPAN
> <SPAN CLASS="cmtt"
>&amp;rest</SPAN
> <SPAN CLASS="cmssi"
>subscripts</SPAN
> <SPAN CLASS="arrow"
>&#8594;</SPAN
> <SPAN CLASS="cmssi"
>index</SPAN
></P
></DD
><DT
><B
>Arguments and Values</B
></DT
><DD
><P CLASS="j"
><VAR CLASS="param"
>array</VAR
> &#8212; an <A HREF="26_1_Glossary.html#array"
><EM CLASS="term"
>array</EM
></A
>. </P
><P CLASS="j"
><VAR CLASS="param"
>subscripts</VAR
> &#8212; a <A HREF="26_1_Glossary.html#list"
><EM CLASS="term"
>list</EM
></A
> of <A HREF="26_1_Glossary.html#valid_array_index"
><EM CLASS="term"
>valid array indices</EM
></A
> for the <VAR CLASS="param"
>array</VAR
>. </P
><P CLASS="j"
><VAR CLASS="param"
>index</VAR
> &#8212; a <A HREF="26_1_Glossary.html#valid_array_row-major_index"
><EM CLASS="term"
>valid array row-major index</EM
></A
> for the <VAR CLASS="param"
>array</VAR
>.</P
></DD
><DT
><B
>Description</B
></DT
><DD
><P CLASS="j"
>Computes the position according to the row-major ordering of <VAR CLASS="param"
>array</VAR
> for the element that is specified by <VAR CLASS="param"
>subscripts</VAR
>, and returns the offset of the element in the computed position from the beginning of <VAR CLASS="param"
>array</VAR
>. </P
><P CLASS="j"
>For a one-dimensional <VAR CLASS="param"
>array</VAR
>, the result of <A HREF="f_array-row-major-index.html" CLASS="funref"
><B
>array-row-major-index</B
></A
> equals <VAR CLASS="param"
>subscript</VAR
>. </P
><P CLASS="j"
><A HREF="f_array-row-major-index.html" CLASS="funref"
><B
>array-row-major-index</B
></A
> ignores <A HREF="26_1_Glossary.html#fill_pointer"
><EM CLASS="term"
>fill pointers</EM
></A
>.</P
></DD
><DT
><B
>Examples</B
></DT
><DD
><PRE CLASS="screen"
>(setq a (make-array '(4 7) :element-type '(unsigned-byte 8)))
(array-row-major-index a 1 2) <SPAN CLASS="cmsy"
><SPAN CLASS="arrow"
>&#8594;</SPAN
></SPAN
> 9
(array-row-major-index
(make-array '(2 3 4)
:element-type '(unsigned-byte 8)
:displaced-to a
:displaced-index-offset 4)
0 2 1) <SPAN CLASS="cmsy"
><SPAN CLASS="arrow"
>&#8594;</SPAN
></SPAN
> 9</PRE
></DD
><DT
><B
>Notes</B
></DT
><DD
><P CLASS="j"
>A possible definition of <A HREF="f_array-row-major-index.html" CLASS="funref"
><B
>array-row-major-index</B
></A
>, with no error-checking, is</P
><PRE CLASS="screen"
>(defun array-row-major-index (a &amp;rest subscripts)
(apply #'+ (maplist #'(lambda (x y)
(* (car x) (apply #'* (cdr y))))
subscripts
(array-dimensions a))))</PRE
></DD
></DL
></DIV
></DIV
><DIV CLASS="footer"
><DIV CLASS="btmnav"
><A HREF="f_array-rank.html" CLASS="prev"
>&#8592;</A
><A HREF="f_array-total-size.html" CLASS="next"
>&#8594;</A
></DIV
><DIV CLASS="trail"
>Conversion to HTML copyright 2023 by Gilbert Baumann</DIV
></DIV
></DIV
><SCRIPT
>domReady();</SCRIPT
></BODY
></HTML
>