Skip to content

Commit

Permalink
Recompile book
Browse files Browse the repository at this point in the history
  • Loading branch information
pedropark99 committed Aug 24, 2024
1 parent cb67577 commit f42758d
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 105 deletions.
7 changes: 6 additions & 1 deletion Chapters/09-data-structures.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -844,7 +844,9 @@ for each field of the struct that you provide as input.
Consider the following code example. We create a new custom struct called `Person`. This
struct contains three different data members, or, three different fields. As consequence,
when we provide this `Person` data type as input to `MultiArrayList()`, this
creates three different arrays. One array for each field in the struct.
creates a "struct of three different arrays" called `PersonArray`. In other words,
this `PersonArray` is a struct that contains three internal dynamic arrays in it.
One array for each field found in the `Person` struct definition.


```{zig}
Expand Down Expand Up @@ -878,6 +880,9 @@ pub fn main() !void {
In other words, instead of creating an array of "persons", the `MultiArrayList()` function
creates a "struct of arrays". Each data member of this struct is a different array that stores
the values of a specific field from the `Person` struct values that are added (or, appended) to the "struct of arrays".
One important detail is that each of these separate internal arrays stored inside `PersonArray`
are dynamic arrays. This means that these arrays can grow automatically as needed, to accomodate
more values.

The @fig-multi-array exposed below presents a diagram that describes the `PersonArray` struct
that we have created in the previous code example. Notice that the values of the data members
Expand Down
8 changes: 5 additions & 3 deletions _freeze/Chapters/09-data-structures/execute-results/html.json

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/Chapters/09-data-structures.html
Original file line number Diff line number Diff line change
Expand Up @@ -726,7 +726,7 @@ <h2 data-number="11.3" class="anchored" data-anchor-id="linked-lists"><span clas
<section id="multi-array-structure" class="level2" data-number="11.4">
<h2 data-number="11.4" class="anchored" data-anchor-id="multi-array-structure"><span class="header-section-number">11.4</span> Multi array structure</h2>
<p>Zig introduces a new data structure called <code>MultiArrayList()</code>. It is a different version of the dynamic array that we have introduced at <a href="#sec-dynamic-array" class="quarto-xref"><span>Section 11.1</span></a>. The difference between this structure and the <code>ArrayList()</code> that we know from <a href="#sec-dynamic-array" class="quarto-xref"><span>Section 11.1</span></a>, is that <code>MultiArrayList()</code> creates a separate dynamic array for each field of the struct that you provide as input.</p>
<p>Consider the following code example. We create a new custom struct called <code>Person</code>. This struct contains three different data members, or, three different fields. As consequence, when we provide this <code>Person</code> data type as input to <code>MultiArrayList()</code>, this creates three different arrays. One array for each field in the struct.</p>
<p>Consider the following code example. We create a new custom struct called <code>Person</code>. This struct contains three different data members, or, three different fields. As consequence, when we provide this <code>Person</code> data type as input to <code>MultiArrayList()</code>, this creates a “struct of three different arrays” called <code>PersonArray</code>. In other words, this <code>PersonArray</code> is a struct that contains three internal dynamic arrays in it. One array for each field found in the <code>Person</code> struct definition.</p>
<div class="cell">
<div class="sourceCode cell-code" id="cb21"><pre class="sourceCode zig code-with-copy"><code class="sourceCode zig"><span id="cb21-1"><a href="#cb21-1" aria-hidden="true" tabindex="-1"></a><span class="kw">const</span> std = <span class="bu">@import</span>(<span class="st">"std"</span>);</span>
<span id="cb21-2"><a href="#cb21-2" aria-hidden="true" tabindex="-1"></a><span class="kw">const</span> Person = <span class="kw">struct</span> <span class="op">{</span></span>
Expand All @@ -753,7 +753,7 @@ <h2 data-number="11.4" class="anchored" data-anchor-id="multi-array-structure"><
<span id="cb21-23"><a href="#cb21-23" aria-hidden="true" tabindex="-1"></a> <span class="op">}</span>);</span>
<span id="cb21-24"><a href="#cb21-24" aria-hidden="true" tabindex="-1"></a><span class="op">}</span></span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</div>
<p>In other words, instead of creating an array of “persons”, the <code>MultiArrayList()</code> function creates a “struct of arrays”. Each data member of this struct is a different array that stores the values of a specific field from the <code>Person</code> struct values that are added (or, appended) to the “struct of arrays”.</p>
<p>In other words, instead of creating an array of “persons”, the <code>MultiArrayList()</code> function creates a “struct of arrays”. Each data member of this struct is a different array that stores the values of a specific field from the <code>Person</code> struct values that are added (or, appended) to the “struct of arrays”. One important detail is that each of these separate internal arrays stored inside <code>PersonArray</code> are dynamic arrays. This means that these arrays can grow automatically as needed, to accomodate more values.</p>
<p>The <a href="#fig-multi-array" class="quarto-xref">Figure&nbsp;<span>11.5</span></a> exposed below presents a diagram that describes the <code>PersonArray</code> struct that we have created in the previous code example. Notice that the values of the data members present in each of the three <code>Person</code> values that we have appended into the <code>PersonArray</code> object that we have instantiated, are scattered across three different internal arrays of the <code>PersonArray</code> object.</p>
<div id="fig-multi-array" class="quarto-float quarto-figure quarto-figure-center anchored">
<figure class="quarto-float quarto-float-fig figure">
Expand Down
Binary file removed docs/Figures/buffered-io2.png
Binary file not shown.
4 changes: 2 additions & 2 deletions docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes">

<meta name="author" content="Pedro Duarte Faria">
<meta name="dcterms.date" content="2024-08-21">
<meta name="dcterms.date" content="2024-08-24">

<title>An Introduction to Zig</title>
<style>
Expand Down Expand Up @@ -246,7 +246,7 @@ <h1 class="title">An Introduction to Zig</h1>
<div>
<div class="quarto-title-meta-heading">Published</div>
<div class="quarto-title-meta-contents">
<p class="date">August 21, 2024</p>
<p class="date">August 24, 2024</p>
</div>
</div>

Expand Down
Loading

0 comments on commit f42758d

Please sign in to comment.