Skip to content

Commit

Permalink
Add removeAll method.
Browse files Browse the repository at this point in the history
  • Loading branch information
eonil committed Oct 4, 2019
1 parent b6a941d commit c5f4f78
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 0 deletions.
6 changes: 6 additions & 0 deletions HAMT/HAMT.swift
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,12 @@ extension HAMT: Sequence {
}
}

public extension HAMT {
mutating func removeAll() {
self = HAMT()
}
}

/// A zero-cost wrapper to route system hash value
/// to `PD5Hashable` protocol.
private struct PD5Key<K>: PD5Hashable where K: Hashable {
Expand Down
23 changes: 23 additions & 0 deletions HAMTTests/HAMTTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
//
// File.swift
//
//
// Created by Henry Hathaway on 10/4/19.
//

import Foundation
import XCTest
import GameKit
@testable import HAMT

final class HAMTTests: XCTestCase {
func testRemoveAll() {
var x = HAMT<Int,Int>()
x[111] = 222
x[222] = 444
x[333] = 666
XCTAssertEqual(x.count, 3)
x.removeAll()
XCTAssertEqual(x.count, 0)
}
}
1 change: 1 addition & 0 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ let package = Package(
],
targets: [
.target(name: "HAMT", dependencies: [], path: "HAMT"),
.testTarget(name: "HAMTTests", dependencies: ["HAMT"], path: "HAMTTests"),
.testTarget(name: "PD5UnitTests", dependencies: ["HAMT"], path: "PD5UnitTests"),
.target(name: "HAMTFuzz", dependencies: ["HAMT"], path: "HAMTFuzz"),
]
Expand Down

0 comments on commit c5f4f78

Please sign in to comment.