Skip to content

Commit a3ed4ce

Browse files
authored
Merge pull request #61 from pedropark99/revision-12
Add a revision for Chapter 12
2 parents b739b71 + e8f9095 commit a3ed4ce

File tree

19 files changed

+349
-385
lines changed

19 files changed

+349
-385
lines changed

Chapters/01-base64.qmd

+2-2
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ These are the 64 characters that compose the base64 scale. The equal sign charac
6969
but it is a special character in the base64 encoding system. This character is used solely as a suffix, to mark the end of the character sequence,
7070
or, to mark the end of meaningful characters in the sequence.
7171

72-
The bulletpoints below summarises the base64 scale:
72+
The bullet points below summarises the base64 scale:
7373

7474
- range 0 to 25 is represented by: ASCII uppercase letters `-> [A-Z]`;
7575
- range 26 to 51 is represented by: ASCII lowercase letters `-> [a-z]`;
@@ -379,7 +379,7 @@ becoming:
379379
- `output[2]` and `output[3]` are the character `=`.
380380

381381

382-
If these bulletpoints were a bit confusing for you, you may find the @tbl-transf-6bit more intuitive.
382+
If these bullet points were a bit confusing for you, you may find the @tbl-transf-6bit more intuitive.
383383
This table unifies all this logic into a simple table. Notice that
384384
this table also provides the exact expression in Zig that creates the corresponding
385385
byte in the output.

Chapters/09-data-structures.qmd

+1-1
Original file line numberDiff line numberDiff line change
@@ -815,7 +815,7 @@ pub fn main() !void {
815815

816816
There are other methods available from the linked list object, depending if this object is
817817
a singly linked list or a doubly linked list, that might be very useful for you. You can find a
818-
summary of them in the bulletpoints below:
818+
summary of them in the bullet points below:
819819

820820
- `remove()` to remove a specific node from the linked list.
821821
- if singly linked list, `len()` to count how many nodes there is in the linked list.

Chapters/10-stack-project.qmd

+70-95
Large diffs are not rendered by default.

Chapters/12-file-op.qmd

+89-96
Large diffs are not rendered by default.

Chapters/14-threads.qmd

+2-2
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ the following steps:
7575
1. start cooking the food in the kitchen.
7676
1. when the food is fully cooked deliver this food to the client.
7777

78-
If you think about the bulletpoints above, you will notice that one big moment of waiting
78+
If you think about the bullet points above, you will notice that one big moment of waiting
7979
is present in this hole process, which is while the food is being prepared and cooked
8080
inside the kitchen. Because while the food is being prepped, both the waiter and the client
8181
itself are waiting for the food to be ready and delivered.
@@ -609,7 +609,7 @@ where undefined behaviour can be introduced into the program.
609609
When we use mutexes in our program, the critical section defines the area of the codebase that we want to lock.
610610
So we normally lock the mutex object at the beginning of the critical section,
611611
and then, we unlock it at the end of the critical section.
612-
The two bulletpoints exposed below comes from the "Critical Section" article from GeekFromGeeks,
612+
The two bullet points exposed below comes from the "Critical Section" article from GeekFromGeeks,
613613
and they summarise well the role that a critical section plays in the thread syncronization problem [@geeks_critical_section].
614614

615615

ZigExamples/data-structures/generic_stack.zig

+3-4
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ fn Stack(comptime T: type) type {
1111

1212
pub fn init(allocator: Allocator, capacity: usize) !Stack(T) {
1313
var buf = try allocator.alloc(T, capacity);
14-
@memset(buf[0..], 0);
1514
return .{
1615
.items = buf[0..],
1716
.capacity = capacity,
@@ -23,10 +22,10 @@ fn Stack(comptime T: type) type {
2322
pub fn push(self: *Self, val: T) !void {
2423
if ((self.length + 1) > self.capacity) {
2524
var new_buf = try self.allocator.alloc(T, self.capacity * 2);
26-
@memset(new_buf[0..], 0);
2725
@memcpy(new_buf[0..self.capacity], self.items);
2826
self.allocator.free(self.items);
2927
self.items = new_buf;
28+
self.capacity = self.capacity * 2;
3029
}
3130

3231
self.items[self.length] = val;
@@ -36,7 +35,7 @@ fn Stack(comptime T: type) type {
3635
pub fn pop(self: *Self) void {
3736
if (self.length == 0) return;
3837

39-
self.items[self.length - 1] = 0;
38+
self.items[self.length - 1] = undefined;
4039
self.length -= 1;
4140
}
4241

@@ -66,5 +65,5 @@ pub fn main() !void {
6665
std.debug.print("Stack len: {d}\n", .{stack.length});
6766
stack.pop();
6867
std.debug.print("Stack len: {d}\n", .{stack.length});
69-
std.debug.print("Stack state: {any}\n", .{stack.items});
68+
std.debug.print("Stack state: {any}\n", .{stack.items[0..stack.length]});
7069
}

ZigExamples/data-structures/stack.zig

+3-4
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ const Stack = struct {
99

1010
pub fn init(allocator: Allocator, capacity: usize) !Stack {
1111
var buf = try allocator.alloc(u32, capacity);
12-
@memset(buf[0..], 0);
1312
return .{
1413
.items = buf[0..],
1514
.capacity = capacity,
@@ -21,10 +20,10 @@ const Stack = struct {
2120
pub fn push(self: *Stack, val: u32) !void {
2221
if ((self.length + 1) > self.capacity) {
2322
var new_buf = try self.allocator.alloc(u32, self.capacity * 2);
24-
@memset(new_buf[0..], 0);
2523
@memcpy(new_buf[0..self.capacity], self.items);
2624
self.allocator.free(self.items);
2725
self.items = new_buf;
26+
self.capacity = self.capacity * 2;
2827
}
2928

3029
self.items[self.length] = val;
@@ -34,7 +33,7 @@ const Stack = struct {
3433
pub fn pop(self: *Stack) void {
3534
if (self.length == 0) return;
3635

37-
self.items[self.length - 1] = 0;
36+
self.items[self.length - 1] = undefined;
3837
self.length -= 1;
3938
}
4039

@@ -62,5 +61,5 @@ pub fn main() !void {
6261
std.debug.print("Stack len: {d}\n", .{stack.length});
6362
stack.pop();
6463
std.debug.print("Stack len: {d}\n", .{stack.length});
65-
std.debug.print("Stack state: {any}\n", .{stack.items});
64+
std.debug.print("Stack state: {any}\n", .{stack.items[0..stack.length]});
6665
}

_freeze/Chapters/01-base64/execute-results/html.json

+2-2
Large diffs are not rendered by default.

_freeze/Chapters/09-data-structures/execute-results/html.json

+2-2
Large diffs are not rendered by default.

_freeze/Chapters/10-stack-project/execute-results/html.json

+2-2
Large diffs are not rendered by default.

_freeze/Chapters/12-file-op/execute-results/html.json

+2-2
Large diffs are not rendered by default.

_freeze/Chapters/14-threads/execute-results/html.json

+2-2
Large diffs are not rendered by default.

docs/Chapters/01-base64.html

+2-2
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,7 @@ <h3 data-number="4.1.1" class="anchored" data-anchor-id="sec-base64-scale"><span
388388
<p>The base64 encoding system is based on a scale that goes from 0 to 63 (hence the name). Each index in this scale is represented by a character (it is a scale of 64 characters). So, in order to convert some binary data, to the base64 encoding, we need to convert each binary number to the corresponding character in this “scale of 64 characters”.</p>
389389
<p>The base64 scale starts with all ASCII uppercase letters (A to Z) which represents the first 25 indexes in this scale (0 to 25). After that, we have all ASCII lowercase letters (a to z), which represents the range 26 to 51 in the scale. After that, we have the one digit numbers (0 to 9), which represents the indexes from 52 to 61 in the scale. Finally, the last two indexes in the scale (62 and 63) are represented by the characters <code>+</code> and <code>/</code>, respectively.</p>
390390
<p>These are the 64 characters that compose the base64 scale. The equal sign character (<code>=</code>) is not part of the scale itself, but it is a special character in the base64 encoding system. This character is used solely as a suffix, to mark the end of the character sequence, or, to mark the end of meaningful characters in the sequence.</p>
391-
<p>The bulletpoints below summarises the base64 scale:</p>
391+
<p>The bullet points below summarises the base64 scale:</p>
392392
<ul>
393393
<li>range 0 to 25 is represented by: ASCII uppercase letters <code>-&gt; [A-Z]</code>;</li>
394394
<li>range 26 to 51 is represented by: ASCII lowercase letters <code>-&gt; [a-z]</code>;</li>
@@ -549,7 +549,7 @@ <h3 data-number="4.4.1" class="anchored" data-anchor-id="sec-6bit-transf"><span
549549
<li><code>output[1]</code> is produced by taking the last two bits from <code>input[0]</code>, then, move them four positions to the left.</li>
550550
<li><code>output[2]</code> and <code>output[3]</code> are the character <code>=</code>.</li>
551551
</ul>
552-
<p>If these bulletpoints were a bit confusing for you, you may find the <a href="#tbl-transf-6bit" class="quarto-xref">Table&nbsp;<span>4.1</span></a> more intuitive. This table unifies all this logic into a simple table. Notice that this table also provides the exact expression in Zig that creates the corresponding byte in the output.</p>
552+
<p>If these bullet points were a bit confusing for you, you may find the <a href="#tbl-transf-6bit" class="quarto-xref">Table&nbsp;<span>4.1</span></a> more intuitive. This table unifies all this logic into a simple table. Notice that this table also provides the exact expression in Zig that creates the corresponding byte in the output.</p>
553553
<div id="tbl-transf-6bit" class="quarto-float quarto-figure quarto-figure-center anchored">
554554
<figure class="quarto-float quarto-float-tbl figure">
555555
<figcaption class="quarto-float-caption-top quarto-float-caption quarto-float-tbl" id="tbl-transf-6bit-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">

docs/Chapters/09-data-structures.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -744,7 +744,7 @@ <h2 data-number="11.3" class="anchored" data-anchor-id="linked-lists"><span clas
744744
<span id="cb20-17"><a href="#cb20-17" aria-hidden="true" tabindex="-1"></a> three.insertAfter(&amp;four); <span class="co">// {1, 2, 3, 4, 5}</span></span>
745745
<span id="cb20-18"><a href="#cb20-18" 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>
746746
</div>
747-
<p>There are other methods available from the linked list object, depending if this object is a singly linked list or a doubly linked list, that might be very useful for you. You can find a summary of them in the bulletpoints below:</p>
747+
<p>There are other methods available from the linked list object, depending if this object is a singly linked list or a doubly linked list, that might be very useful for you. You can find a summary of them in the bullet points below:</p>
748748
<ul>
749749
<li><code>remove()</code> to remove a specific node from the linked list.</li>
750750
<li>if singly linked list, <code>len()</code> to count how many nodes there is in the linked list.</li>

0 commit comments

Comments
 (0)