don't constantly check the heap property in debug mode (#1272)

Motivation:

So far we've been checking the heap property of our heaps _twice per
heap operation_. I think that's a bit much.

Modifications:

Remove the heap operation checks.

Result:

Runs much faster in debug mode.
This commit is contained in:
Johannes Weiss authored and George Barnett committed 2019-11-28 10:33:46 +00:00
1 parent 3c879ebbaf
commit cb72048eca
1 file changed
-7
-7
View File
@@ -20,30 +20,23 @@ internal struct PriorityQueue<Element: Comparable> {
}
public mutating func remove(_ key: Element) {
assert(self.heap.checkHeapProperty(), "broken heap: \(self.heap.debugDescription)")
self.heap.remove(value: key)
assert(self.heap.checkHeapProperty(), "broken heap: \(self.heap.debugDescription)")
}
public mutating func push(_ key: Element) {
assert(self.heap.checkHeapProperty(), "broken heap: \(self.heap.debugDescription)")
self.heap.append(key)
assert(self.heap.checkHeapProperty(), "broken heap: \(self.heap.debugDescription)")
}
public func peek() -> Element? {
assert(self.heap.checkHeapProperty(), "broken heap: \(self.heap.debugDescription)")
return self.heap.storage.first
}
public var isEmpty: Bool {
assert(self.heap.checkHeapProperty(), "broken heap: \(self.heap.debugDescription)")
return self.heap.storage.isEmpty
}
@discardableResult
public mutating func pop() -> Element? {
assert(self.heap.checkHeapProperty(), "broken heap: \(self.heap.debugDescription)")
return self.heap.removeRoot()
}