Skip to content

Commit

Permalink
Merge pull request jamesroutley#13 from medium-endian/master
Browse files Browse the repository at this point in the history
Minor nitpicks
  • Loading branch information
jamesroutley authored Aug 24, 2017
2 parents 2aa56da + d859418 commit b68b3ab
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 10 deletions.
2 changes: 1 addition & 1 deletion 03-hashing/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ function hash(string, a, num_buckets):
hash = 0
string_len = length(string)
for i = 0, 1, ..., string_len:
hash += (a ** string_len - (i+1)) * char_code(string[i])
hash += (a ** (string_len - (i+1))) * char_code(string[i])
hash = hash % num_buckets
return hash
```
Expand Down
2 changes: 1 addition & 1 deletion 04-collisions/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ and over. We can mitigate this by adding 1 to the result of the second hash,
making sure it's never 0.

```
index = hash_a(string) + i * (hash_b(string) + 1) % num_buckets
index = (hash_a(string) + i * (hash_b(string) + 1)) % num_buckets
```

## Implementation
Expand Down
4 changes: 2 additions & 2 deletions 05-methods/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,13 +91,13 @@ void ht_delete(ht_hash_table* ht, const char* key) {
ht->count--;
}
```
After deleting, we decrement the hash table's `count` attribute.

We also need to modify `ht_insert` and `ht_search` functions to take account of
deleted nodes.

When searching, we ignore and 'jump over' deleted nodes. When inserting, if we
hit a deleted node, we can insert the new node into the deleted slot. After
deleting, we decrement the hash table's `count` attribute.
hit a deleted node, we can insert the new node into the deleted slot.

```c
// hash_table.c
Expand Down
13 changes: 7 additions & 6 deletions 06-resizing/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,12 @@ We will resize:
To resize, we create a new hash table roughly half or twice as big as the
current, and insert all non-deleted items into it.

Our new array size should be a prime number roughly double the current size.
Finding the new array size isn't trivial. To do so, we store a base size, which
we want the array to be, and then define the actual size as the first prime
larger than the base size. To resize up, we double the base size, and find the
first larger prime.
Our new array size should be a prime number roughly double or half the current
size. Finding the new array size isn't trivial. To do so, we store a base
size, which we want the array to be, and then define the actual size as the
first prime larger than the base size. To resize up, we double the base size,
and find the first larger prime, and to resize down, we halve the size and
find the next larger prime.

Our base sizes start at 50. Instead of storing

Expand Down Expand Up @@ -114,7 +115,7 @@ with the desired size. All non `NULL` or deleted items are inserted into the new
hash table. We then swap the attributes of the new and old hash tables before
deleting the old.
```
```c
// hash_table.c
static void ht_resize(ht_hash_table* ht, const int base_size) {
if (base_size < HT_INITIAL_BASE_SIZE) {
Expand Down

0 comments on commit b68b3ab

Please sign in to comment.