Performance for this function should be O(n)
antonio081014 opened this issue · 3 comments
antonio081014 commented
In this function, index(of:) costs O(n), then remove(at:) costs O(log n), it should be O(n + log n), which would be O(n)
antonio081014 commented
antonio081014 commented
/** Removes the first occurrence of a node from the heap. Performance: O(n log n). */
@discardableResult public mutating func remove(node: T) -> T? {
if let index = index(of: node) {
return remove(at: index)
}
return nil
}
kelvinlauKL commented
Fixed #905. Thanks!