Skip to content

Commit 621a28d

Browse files
authored
Update README.markdown
1 parent c10b698 commit 621a28d

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

Hash Table/README.markdown

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ it first hashes the key `"lastName"` to calculate the array index, which is 3. S
103103

104104
Common ways to implement this chaining mechanism are to use a linked list or another array. Since the order of the items in the chain does not matter, you can think of it as a set instead of a list. (Now you can also imagine where the term "bucket" comes from; we just dump all the objects together into the bucket.)
105105

106-
Chains should not become long becasuse the slow process of looking up items in the hash table. Ideally, we would have no chains at all, but in practice it is impossible to avoid collisions. You can improve the odds by giving the hash table enough buckets using high-quality hash functions.
106+
Chains should not become long because the slow process of looking up items in the hash table. Ideally, we would have no chains at all, but in practice it is impossible to avoid collisions. You can improve the odds by giving the hash table enough buckets using high-quality hash functions.
107107

108108
> **Note:** An alternative to chaining is "open addressing". The idea is this: if an array index is already taken, we put the element in the next unused bucket. This approach has its own upsides and downsides.
109109
@@ -127,7 +127,7 @@ public struct HashTable<Key: Hashable, Value> {
127127
}
128128
```
129129

130-
The `HashTable` is a generic container, and the two generic types are named `Key` (which must be `Hashable`) and `Value`. We also define two other types: `Element` is a key/value pair for useing in a chain, and `Bucket` is an array of such `Elements`.
130+
The `HashTable` is a generic container, and the two generic types are named `Key` (which must be `Hashable`) and `Value`. We also define two other types: `Element` is a key/value pair for using in a chain, and `Bucket` is an array of such `Elements`.
131131

132132
The main array is named `buckets`. It has a fixed size, the so-called capacity, provided by the `init(capacity)` method. We are also keeping track of how many items have been added to the hash table using the `count` variable.
133133

0 commit comments

Comments
 (0)