Skip to content

Commit

Permalink
Merge pull request kodecocodes#878 from Vladis92/abs-overflow
Browse files Browse the repository at this point in the history
Fix abs of hashValue causing overflow
  • Loading branch information
kelvinlauKL authored May 29, 2019
2 parents 47456c5 + 721af5d commit 67f00de
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Hash Table/HashTable.playground/Sources/HashTable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ public struct HashTable<Key: Hashable, Value> {
Returns the given key's array index.
*/
private func index(forKey key: Key) -> Int {
return abs(key.hashValue) % buckets.count
return abs(key.hashValue % buckets.count)
}
}

Expand Down
2 changes: 1 addition & 1 deletion Hash Table/README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ The hash table does not do anything yet, so let's add the remaining functionalit

```swift
private func index(forKey key: Key) -> Int {
return abs(key.hashValue) % buckets.count
return abs(key.hashValue % buckets.count)
}
```

Expand Down

0 comments on commit 67f00de

Please sign in to comment.