Skip to content

Commit ecaf749

Browse files
authoredSep 5, 2017
Fixed readme to match code.
1 parent 95d8df5 commit ecaf749

File tree

1 file changed

+3
-9
lines changed

1 file changed

+3
-9
lines changed
 

‎Multiset/README.markdown

+3-9
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,9 @@ Here's the essence of it:
3232

3333
``` swift
3434
public struct Multiset<Element: Hashable> {
35-
fileprivate var storage: [Element: UInt]
35+
public private(set) var storage: [Element: UInt] = [:]
Has a comment. Original line has a comment.
3636

37-
public init() {
38-
storage = [:]
39-
}
37+
public init() {}
4038
```
4139

4240
And here's how you'd use this class to create a multiset of strings:
@@ -49,11 +47,7 @@ Adding an element is a case of incrementing the counter for that element, or set
4947

5048
``` swift
5149
public mutating func add (_ elem: Element) {
52-
if let currentCount = storage[elem] {
53-
storage[elem] = currentCount + 1;
54-
} else {
55-
storage[elem] = 1
56-
}
50+
storage[elem, default: 0] += 1
5751
}
5852
```
5953

0 commit comments

Comments
 (0)
Please sign in to comment.