You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: _pages/2019/spring/psets/4/speller/hashtable/speller.adoc
+7-8
Original file line number
Diff line number
Diff line change
@@ -1,5 +1,5 @@
1
1
---
2
-
layout: 2018/fall
2
+
layout: 2019/spring
3
3
---
4
4
5
5
= Speller
@@ -39,9 +39,8 @@ TIME IN TOTAL:
39
39
40
40
=== Downloading
41
41
42
-
Log into link:https://cs50.io/[CS50 IDE] and then, in a terminal window, execute each of the below.
42
+
Log into link:https://ide.cs50.io/[CS50 IDE] and then, in a terminal window, execute each of the below.
43
43
44
-
1. Execute `update50` to ensure your IDE is up-to-date. That command might take a few minutes to finish.
45
44
1. Execute `cd` to ensure that you're in `~/workspace/` (i.e., a directory called `workspace` that's in your home directory, aka `~`).
46
45
1. Execute `mkdir pset4` to make (i.e., create) a directory called `pset4` in your home directory.
47
46
1. Execute `cd pset4` to change into (i.e., open) that directory.
@@ -66,7 +65,7 @@ In `speller.c`, we've put together a program that's designed to spell-check a fi
66
65
67
66
==== `dictionary.h`
68
67
69
-
Open up `dictionary.h`, and you'll see some new syntax, including a few lines that mention `DICTIONARY_H`. No need to worry about those, but, if curious, those lines just ensure that, even though `dictionary.c` and `speller.c` (which you'll see in a moment) `#include` this file, `clang` will only compile it once.
68
+
Open up `dictionary.h`, and you'll see some new syntax, including a few lines that mention `DICTIONARY_H`. No need to worry about those, but, if curious, those lines just ensure that, even though `dictionary.c` and `speller.c` (which you'll see in a moment) `#include` this file, `clang` will only compile it once.
70
69
71
70
Next notice how we `#include` a file called `stdbool.h`. That's the file in which `bool` itself is defined. You've not needed it before, since the CS50 Library used to `#include` that for you.
72
71
@@ -92,7 +91,7 @@ And `const`, meanwhile, just says that those strings, when passed in as argument
92
91
93
92
Now open up `dictionary.c`. Notice how, atop the file, we've defined a `struct` called `node` that represents a node in a hash table. And we've declared a global array, `hashtable`, with enough room for `N` pointers to nodes, where `N` is initialized above that array to `26`, one bucket for each letter in the (English) alphabet.
94
93
95
-
A bit below those lines have we implemented a function called `hash` that hashes a word, returning `0` for any word that starts with an `a` (or `A`), `1` for any word that starts with a `b` (or `B`), `25` for any word that starts with a `z` (or `Z`), and so on for every letter in between.
94
+
A bit below those lines have we implemented a function called `hash` that hashes a word, returning `0` for any word that starts with an `a` (or `A`), `1` for any word that starts with a `b` (or `B`), `25` for any word that starts with a `z` (or `Z`), and so on for every letter in between.
96
95
97
96
Below that have we written part of a function called `load` that will soon (thanks to you!) load a dictionary of words into the hash table. We've written some code that initializes all of the buckets (i.e., pointers) in `hashtable` to `NULL`. And we've written some code that opens `dictionary`, which is the file name of a dictionary to load. And we've also written some code that iterates over that dictionary and reads the words therein, one at a time, into a buffer (i.e., `string`) called `word`. But we stop short of inserting those words into `hashtable`. Thereafter, we do close the file, though, and then return `true` to indicate (we hope!) success.
98
97
@@ -306,7 +305,7 @@ To test your code less manually (though still not exhaustively), you may also ex
306
305
307
306
[source]
308
307
----
309
-
check50 cs50/2018/fall/speller
308
+
check50 cs50/2019/spring/speller
310
309
----
311
310
312
311
Note that `check50` will also check for memory leaks, so be sure you've run `valgrind` as well.
@@ -326,7 +325,7 @@ And if you'd like to put your code to the test against classmates' code (just fo
326
325
327
326
[source]
328
327
----
329
-
check50 cs50/2018/fall/challenges/speller
328
+
check50 cs50/2019/spring/challenges/speller
330
329
----
331
330
332
331
Then visit the URL that `check50` outputs to see where you rank!
@@ -336,5 +335,5 @@ Then visit the URL that `check50` outputs to see where you rank!
336
335
Execute the below, logging in with your GitHub username and password when prompted. For security, you'll see asterisks (`*`) instead of the actual characters in your password.
@@ -66,7 +66,7 @@ In `speller.c`, we've put together a program that's designed to spell-check a fi
66
66
67
67
==== `dictionary.h`
68
68
69
-
Open up `dictionary.h`, and you'll see some new syntax, including a few lines that mention `DICTIONARY_H`. No need to worry about those, but, if curious, those lines just ensure that, even though `dictionary.c` and `speller.c` (which you'll see in a moment) `#include` this file, `clang` will only compile it once.
69
+
Open up `dictionary.h`, and you'll see some new syntax, including a few lines that mention `DICTIONARY_H`. No need to worry about those, but, if curious, those lines just ensure that, even though `dictionary.c` and `speller.c` (which you'll see in a moment) `#include` this file, `clang` will only compile it once.
70
70
71
71
Next notice how we `#include` a file called `stdbool.h`. That's the file in which `bool` itself is defined. You've not needed it before, since the CS50 Library used to `#include` that for you.
72
72
@@ -304,7 +304,7 @@ To test your code less manually (though still not exhaustively), you may also ex
304
304
305
305
[source]
306
306
----
307
-
check50 cs50/2018/fall/speller
307
+
check50 cs50/2019/spring/speller
308
308
----
309
309
310
310
Note that `check50` will also check for memory leaks, so be sure you've run `valgrind` as well.
@@ -324,7 +324,7 @@ And if you'd like to put your code to the test against classmates' code (just fo
324
324
325
325
[source]
326
326
----
327
-
check50 cs50/2018/fall/challenges/speller
327
+
check50 cs50/2019/spring/challenges/speller
328
328
----
329
329
330
330
Then visit the URL that `check50` outputs to see where you rank!
@@ -334,5 +334,5 @@ Then visit the URL that `check50` outputs to see where you rank!
334
334
Execute the below, logging in with your GitHub username and password when prompted. For security, you'll see asterisks (`*`) instead of the actual characters in your password.
0 commit comments