This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
/// A simple binary heap | |
final class Heap<T: Comparable> { | |
private let isMinHeap: Bool | |
private let comparator: (T, T) -> Bool | |
private var heap: [T] = [] | |
var isEmpty: Bool { return heap.isEmpty } | |
var count: Int { return heap.count } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension KeyedDecodingContainer { | |
/// The sole purpose of this `EmptyDecodable` is allowing decoder to skip an element that cannot be decoded. | |
private struct EmptyDecodable: Decodable {} | |
/// Return successfully decoded elements even if some of the element fails to decode. | |
func safelyDecodeArray<T: Decodable>(of type: T.Type, forKey key: KeyedDecodingContainer.Key) -> [T] { | |
guard var container = try? nestedUnkeyedContainer(forKey: key) else { | |
return [] | |
} |