Skip to content

Commit 714a413

Browse files
committed
rebuild
1 parent 4550459 commit 714a413

17 files changed

+69
-67
lines changed

01_data_structures.html

+5-5
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ <h2>Hello, World</h2>
120120
a room of programmers know it&rsquo;s going to be an empty set.
121121
That doesn&rsquo;t mean that you as an individual person doesn&rsquo;t know things, but intersection is going to be relatively small.</p>
122122

123-
<p>Unfortunatly we&rsquo;ve got to a point where nobody teaches programming.
123+
<p>Unfortunately we&rsquo;ve got to a point where nobody teaches programming.
124124
Because there&rsquo;s no professor of computer science who has any idea how to program<sup id="fnref:6"><a href="#fn:6" rel="footnote">6</a></sup>.
125125
Part of what I am trying to do here is to start discussing
126126
little things like, how do we name variables?
@@ -145,7 +145,7 @@ <h2>Hello, World</h2>
145145
through the last brace, zero is returned.
146146
Because the standard UNIX convention, which became Universal
147147
convention, that on success you return zero.
148-
The language actually allows you to do things things like that.</p>
148+
The language actually allows you to do things like that.</p>
149149

150150
<p>One warning, <a href="https://en.cppreference.com/w/cpp/io/cout"><code>cout</code></a> stuff works pretty much like how you think it works.
151151
However a friend of mine wrote something like:</p>
@@ -171,7 +171,7 @@ <h2>Number of unique elements</h2>
171171
pertaining to incorrect use of STL<sup id="fnref:9"><a href="#fn:9" rel="footnote">9</a></sup>.
172172
It&rsquo;s usually a one liner and the most egregious.</p>
173173

174-
<p>The most most amazing thing is the following one liner which I will start in the
174+
<p>The most amazing thing is the following one liner which I will start in the
175175
beginning of the course, because it was just so important.
176176
We could weave the whole fabric of the course around this one little example.
177177
There was a range of integers. For example:</p>
@@ -216,7 +216,7 @@ <h3>Equality vs ordering</h3>
216216
One of the amazing things which we will discover is that ordering is very important.
217217
Things which we could do with ordering cannot be effectively done just with equality<sup id="fnref:13"><a href="#fn:13" rel="footnote">13</a></sup>.</p>
218218

219-
<p>If we are going by the book we we will say sorting is good as long it does approximately <code>O(n log(n))</code> operations.
219+
<p>If we are going by the book we will say sorting is good as long it does approximately <code>O(n log(n))</code> operations.
220220
This is good for the books.
221221
It&rsquo;s actually not good for our code, because Big O
222222
could have an arbitrary coefficient.
@@ -381,7 +381,7 @@ <h2>Two fundamental performance metrics</h2>
381381
This is very good, we have to have that.
382382
But then we also need to have times for specific commonly used types.
383383
So these are two things which we need to do.
384-
Our goal is to to be able to measure this problem with <code>set</code> and with sort.
384+
Our goal is to be able to measure this problem with <code>set</code> and with sort.
385385
But, first we need to learn more about C++.</p>
386386

387387
<a name="Code"></a>

02_regular_types.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ <h2>We don&rsquo;t know how to program yet</h2>
4949
I did interview at Facebook and let me tell you what I saw of that place&hellip;
5050
That was five years ago.
5151
Maybe they improved but I don&rsquo;t think so.
52-
Places tend to to decline.</p>
52+
Places tend to decline.</p>
5353

5454
<p>You might say: &ldquo;Who are you to tell us?&rdquo;
5555
I am as guilty as any of you.

03_singleton.html

+2-2
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ <h3>Virtual functions, virtual destructors, and OOP</h3>
258258
He tells you always declare destructor as virtual<sup id="fnref:7"><a href="#fn:7" rel="footnote">7</a></sup>.
259259
OK, he&rsquo;s wrong. Simple as that.</p>
260260

261-
<p>What we do we want to create? Take type <code>T</code>, put it in a struct. Will the size of the thing increase?
261+
<p>What do we want to create? Take type <code>T</code>, put it in a struct. Will the size of the thing increase?
262262
No. It has no overhead.
263263
Singleton is the same size as <code>T</code>.
264264
It&rsquo;s the wonderful thing about singleton, and lets you pack them in arrays.
@@ -349,7 +349,7 @@ <h3>Why can&rsquo;t the compiler generate == and !=?</h3>
349349
Then they fixed it.
350350
They said, &ldquo;we&rsquo;ll just copy the bits&rdquo; and things would work.</p>
351351

352-
<p>Equality is defined for all built-in types; <code>int</code>, <code>double</code>, <code>short</code>, <code>char</code>, pointers, etc.
352+
<p>Equality is defined for all built-in types: <code>int</code>, <code>double</code>, <code>short</code>, <code>char</code>, pointers, etc.
353353
So, if you have a struct, why can&rsquo;t you generate an equality that uses those?
354354
Two things are equal if all their members are equal.
355355
It&rsquo;s a sensible rule a compiler could do.</p>

04_instrumented.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -593,7 +593,7 @@ <h2>Code</h2>
593593
and the cover of that edition is labeled as such.<a href="#fnref:1" rev="footnote">&#8617;</a></li>
594594
<li id="fn:2">
595595
<p>Goto used to be the primary way to do control flow in programs,
596-
because it closely resembles how how machines and their languages work.</p>
596+
because it closely resembles how machines and their languages work.</p>
597597

598598
<p>For example, to implement a <code>while</code> loop, you might write:</p>
599599

05_swap.html

+2-2
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ <h3>Three tests of a language&rsquo;s ability to write components</h3>
143143
<p>So you say, &ldquo;Alex, why don&rsquo;t we use a new language?&rdquo;
144144
Go try implementing these three program in your favorite language.
145145
Do them in a general way.
146-
If they&rsquo;re at least relatively efficient, that is, they are not slower than specific things written in the language, then let us talk.
146+
If they&rsquo;re at least relatively efficient, that is, they are not slower than specific things written in the language, then let us talk.
147147
If you cannot do it, let us stick with C++.
148148
I&rsquo;m just explaining the reasoning behind my choice of C++.</p>
149149

@@ -396,7 +396,7 @@ <h2>Code</h2>
396396

397397
<ol>
398398
<li><code>G</code> contains an identity element <code>e</code> in <code>G</code> such that <code>e * x = x * e = x</code> for all <code>x</code> in <code>G</code>.</li>
399-
<li>The operation <code>*</code> is associative. So <code>((x * y) * z) = (x * (y * z))</code> for all <code>x, y, z</code> in <code>G</code>.</li>
399+
<li>The operation <code>*</code> is associative. So <code>((x * y) * z) = (x * (y * z))</code> for all <code>x, y, z</code> in <code>G</code>.</li>
400400
<li>Every element <code>x</code> in <code>G</code> has an inverse element <code>y</code> such that x * y = y * x = e.</li>
401401
</ol>
402402

06_min_max.html

+2-2
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ <h2>Weak orderings</h2>
121121

122122
<p>The <code>==</code> is equality, not another equivalence relation.
123123
We can&rsquo;t conclude that with a weak ordering.
124-
We must overloaded symbols for what they commonly mean.</p>
124+
We must overload symbols for what they commonly mean.</p>
125125

126126
<a name="Min"></a>
127127
<h2>Min</h2>
@@ -355,7 +355,7 @@ <h3>Implementation</h3>
355355
committee he always says, &ldquo;Alex you are too theoretical&rdquo;.
356356
I guess I am because I pay attention to
357357
these little details.
358-
But I claim to be able to to show you that
358+
But I claim to be able to show you that
359359
things like that will matter.</p>
360360

361361
<p>Later we will generalize it on a bunch of things.

07_min_range.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ <h3>Forward iterator</h3>
159159
<a name="Finding-min-and-max-together"></a>
160160
<h2>Finding min and max together</h2>
161161

162-
<p>How many comparisons do we need to to find the min of five elements?
162+
<p>How many comparisons do we need to find the min of five elements?
163163
Four.
164164
In general why do we need <code>n - 1</code> comparisons.
165165
Why no more? We don&rsquo;t need to compare an element with itself.

10_binary_counter.html

+11-11
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ <h2>Binary counting and reduction</h2>
228228
But, they want to publish papers themselves and not tell you the general mechanism.</p>
229229

230230
<p>Let us assume we have elements of type <code>T</code> that need to be paired or combined in some way,
231-
whether with <code>min</code>, <code>+</code>, <code>merge</code>, or any other assocative operation on <code>T</code>.
231+
whether with <code>min</code>, <code>+</code>, <code>merge</code>, or any other associative operation on <code>T</code>.
232232
What we can do is create an array called a &ldquo;counter&rdquo;.</p>
233233

234234
<pre><code> index: 0 1 ... 31
@@ -275,12 +275,12 @@ <h2>Binary counting and reduction</h2>
275275

276276
<p>What if the index <code>1</code> slot was non-zero, after comparing <code>x</code> and <code>y</code>?
277277
Then the guy there already won one game.
278-
So, we must <strong>carry propogate</strong><sup id="fnref:10"><a href="#fn:10" rel="footnote">10</a></sup>.
278+
So, we must <strong>carry propagate</strong><sup id="fnref:10"><a href="#fn:10" rel="footnote">10</a></sup>.
279279
Repeat the same process all the way up the counter, until we find a slot which is zero.
280280
What if the counter is full, and has no zero slots?
281281
That&rsquo;s called an <strong>overflow</strong>.</p>
282282

283-
<p>We borrow terminology from binary integer arithemtic because
283+
<p>We borrow terminology from binary integer arithmetic because
284284
our counter works just like a binary integer counting up:</p>
285285

286286
<pre><code>0 0 0
@@ -293,7 +293,7 @@ <h2>Binary counting and reduction</h2>
293293
1 1 1
294294
</code></pre>
295295

296-
<p>But instead of 0 and 1 in each slot or &ldquo;bit&rdquo; we have arbitary elements that are combined with an associative operation.</p>
296+
<p>But instead of 0 and 1 in each slot or &ldquo;bit&rdquo; we have arbitrary elements that are combined with an associative operation.</p>
297297

298298
<a name="Handling-overflow"></a>
299299
<h3>Handling overflow</h3>
@@ -469,8 +469,8 @@ <h3>Counter storage</h3>
469469

470470
<p><strong>Exercise:</strong> Rewrite <code>min_element</code> using this code (just <code>min_element</code>, don&rsquo;t worry about second best).</p>
471471

472-
<p><strong>Exercise:</strong> If you want to implement <a href="https://en.wikipedia.org/wiki/Merge_sort">merge sort</a> you can use exactly the same device, since merge is associative. The idea with merge sort, is you only want to merge lists if they are roughly the same length and this helps you do it (see Chapter 12).
473-
Write the associtative binary operation <code>merge</code> which can combine two sorted arrays into a sorted array.</p>
472+
<p><strong>Exercise:</strong> If you want to implement <a href="https://en.wikipedia.org/wiki/Merge_sort">merge sort</a> you can use exactly the same device, since merge is associative. The idea with merge sort, is you only want to merge lists if they are roughly the same length and this helps you do it (see Chapter 12).
473+
Write the associative binary operation <code>merge</code> which can combine two sorted arrays into a sorted array.</p>
474474

475475
<p><strong>Exercise:</strong> When we become grownups we learn about advanced data structures, such as <a href="https://en.wikipedia.org/wiki/Binomial_heap">binomial forest</a>. They use the same idea. Learn about this data structure and try to figure out where
476476
the counter could be used.</p>
@@ -535,7 +535,7 @@ <h2>Code</h2>
535535
See the definition of &ldquo;in-place memory usage&rdquo; at the end of the chapter.<a href="#fnref:6" rev="footnote">&#8617;</a></li>
536536
<li id="fn:7">
537537
<p>A binary function <code>f</code> is <a href="https://en.wikipedia.org/wiki/Associative_property">associative</a>
538-
if the the following holds for all <code>a, b, c</code> in its domain:</p>
538+
if the following holds for all <code>a, b, c</code> in its domain:</p>
539539

540540
<pre><code>f(f(a, b), c)) = f(a, f(b, c))
541541
</code></pre>
@@ -576,7 +576,7 @@ <h2>Code</h2>
576576
* * *
577577
</code></pre>
578578

579-
<p>Or as <a href="https://en.wikipedia.org/wiki/Peter_Gustav_Lejeune_Dirichlet)">Dirchlet</a> put it: &ldquo;Whether you arrange soldiers in rows or columns, you still have the same number of soldiers&rdquo;.</p>
579+
<p>Or as <a href="https://en.wikipedia.org/wiki/Peter_Gustav_Lejeune_Dirichlet)">Dirichlet</a> put it: &ldquo;Whether you arrange soldiers in rows or columns, you still have the same number of soldiers&rdquo;.</p>
580580

581581
<p>An example of an operation which is not commutative is string concatenation.</p>
582582

@@ -590,7 +590,7 @@ <h2>Code</h2>
590590
We distinguish between the left and right argument.<a href="#fnref:9" rev="footnote">&#8617;</a></li>
591591
<li id="fn:10">
592592
<p>The terms <strong>carry</strong> and <strong>overflow</strong>
593-
are closely associated the implementation of binary counting
593+
are closely associated with the implementation of binary counting
594594
or addition as an electrical circuit, called an <a href="https://en.wikipedia.org/wiki/Adder_(electronics)">adder</a>.</p>
595595

596596
<p>A single bit adder has two inputs <code>a</code> and <code>b</code> for
@@ -611,7 +611,7 @@ <h2>Code</h2>
611611
</code></pre>
612612

613613
<p>This adds a single digit, but we want to add entire numbers.
614-
To, do so we add an additional input <code>l</code> for carried digits
614+
To do so we add an additional input <code>l</code> for carried digits
615615
from lower place values.</p>
616616

617617
<pre><code>a b l c s
@@ -640,7 +640,7 @@ <h2>Code</h2>
640640
<a href="https://signalvnoise.com/posts/2710-designed-by-apple-in-california">Designed in Cupertino</a>, assembled in China.
641641
So let&rsquo;s try to assemble our machine in Palo Alto.<a href="#fnref:11" rev="footnote">&#8617;</a></li>
642642
<li id="fn:12">
643-
<p>Floating point arithemetic can involve many tricky details,
643+
<p>Floating point arithmetic can involve many tricky details,
644644
but the basic issue Alex is referring to is straightforward.
645645
We often use scientific notation to write larger numbers as a decimal to a power,
646646
when they would otherwise be very long to write out.

11_min_1_2.html

+9-9
Original file line numberDiff line numberDiff line change
@@ -55,20 +55,20 @@ <h2>Overview</h2>
5555
I pick this algorithm because it allows us to learn how to do decomposition
5656
and learn these components like <code>list_pool</code> and <code>binary_counter</code> along the way.</p>
5757

58-
<p>Let me sketch the grand plan of the whole alogorithm.</p>
58+
<p>Let me sketch the grand plan of the whole algorithm.</p>
5959

6060
<ol>
61-
<li><p>We already showed that we want to arrange our comparisons like a tennis tournmant,
61+
<li><p>We already showed that we want to arrange our comparisons like a tennis tournament,
6262
and <code>binary_counter</code> helps us do this.
6363
Instead of comparing by left reduction, we compare by balanced reduction.</p></li>
6464
<li><p>We also want to keep a history for each element of all
6565
the other elements which they have beat.
6666
This history will be used to determine the second-place guy.</p>
6767

68-
<p> We will store this history in a list (using <code>list_pool</code>)
69-
along with each element in the binary counter.
70-
Note that the counter works on generic elements, so it doesn&rsquo;t
71-
need to be modified to know about this history tracking.</p></li>
68+
<p>We will store this history in a list (using <code>list_pool</code>)
69+
along with each element in the binary counter.
70+
Note that the counter works on generic elements, so it doesn&rsquo;t
71+
need to be modified to know about this history tracking.</p></li>
7272
</ol>
7373

7474

@@ -132,7 +132,7 @@ <h3>Inner loop</h3>
132132
<p>Notice that we use <code>std::min_element</code> on our list pool.
133133
Will that work?
134134
Yes, because we added iterators to our list pool.
135-
Define our <code>iterator</code> type;</p>
135+
Define our <code>iterator</code> type:</p>
136136

137137
<pre><code>typedef typename list_pool&lt;I, std::size_t&gt;::iterator iterator;
138138
</code></pre>
@@ -230,7 +230,7 @@ <h3>Finishing the scaffolding</h3>
230230

231231
typedef op_min1_2&lt;I, size_t, compare_type&gt; op_type;
232232
typedef binary_counter&lt;op_type&gt; counter_type;
233-
typedef typename op_type::argument_type result_type;
233+
typedef typename op_type::argument_type result_type;
234234

235235
// ...
236236
}
@@ -262,7 +262,7 @@ <h2>Why do we need the typename keyword?</h2>
262262

263263
<p>Obviously what you are trying to do is extract <code>T</code>&rsquo;s <code>value_type</code>
264264
and use it here.
265-
Let us try to to follow the committees logic.
265+
Let us try to follow the committees logic.
266266
The logic says maybe <code>T::value_type</code> refers to a static variable
267267
in <code>T</code>, which it could be of course.
268268
But, don&rsquo;t you know from the context that it&rsquo;s supposed to be a type?

0 commit comments

Comments
 (0)