mirror of
https://github.com/krahets/hello-algo.git
synced 2026-07-26 13:06:07 +00:00
feat: add Swift codes for hash_collision article (#569)
* feat: add Swift codes for hash_collision article * refactor: extract common Pair * Update hash_map.md --------- Co-authored-by: Yudong Jin <krahets@163.com>
This commit is contained in:
@@ -515,7 +515,20 @@ index = hash(key) % capacity
|
||||
=== "Swift"
|
||||
|
||||
```swift title="array_hash_map.swift"
|
||||
[class]{Pair}-[func]{}
|
||||
/* 键值对 */
|
||||
public class Pair: Equatable {
|
||||
public var key: Int
|
||||
public var val: String
|
||||
|
||||
public init(key: Int, val: String) {
|
||||
self.key = key
|
||||
self.val = val
|
||||
}
|
||||
|
||||
public static func == (lhs: Pair, rhs: Pair) -> Bool {
|
||||
lhs.key == rhs.key && lhs.val == rhs.val
|
||||
}
|
||||
}
|
||||
|
||||
[class]{ArrayHashMap}-[func]{}
|
||||
```
|
||||
|
||||
Reference in New Issue
Block a user