Files
darwin-apk/Sources/apk/Graph/ApkPackageGraphNode.swift

49 lines
1.1 KiB
Swift
Raw Normal View History

2024-11-11 21:06:37 +11:00
/*
2025-07-10 21:51:30 +10:00
* darwin-apk © 2024, 2025 Gay Pizza Specifications
2024-11-11 21:06:37 +11:00
* SPDX-License-Identifier: Apache-2.0
*/
import Foundation
public class ApkPackageGraphNode {
2025-07-10 21:51:30 +10:00
public let packageID: ApkIndex.Index
public var parentIDs = [ApkIndex.Index]()
public var children: [ChildRef]
2024-11-11 21:06:37 +11:00
2025-07-10 21:51:30 +10:00
@inlinable public var isShallow: Bool { self.parentIDs.isEmpty }
@inlinable public var isDeep: Bool { self.children.isEmpty }
2024-11-11 23:08:01 +11:00
2025-07-11 20:50:12 +10:00
internal init(id: Int, children: [ChildRef]) {
2024-11-11 23:08:01 +11:00
self.packageID = id
2024-11-11 21:06:37 +11:00
self.children = children
}
}
2024-11-11 23:08:01 +11:00
extension ApkPackageGraphNode: Equatable, Hashable {
public static func == (lhs: ApkPackageGraphNode, rhs: ApkPackageGraphNode) -> Bool {
lhs.packageID == rhs.packageID
}
public func hash(into hasher: inout Hasher) {
self.packageID.hash(into: &hasher)
}
}
2025-07-10 21:51:30 +10:00
extension ApkPackageGraphNode {
public struct ChildRef {
let constraint: Constraint
let packageID: Int
let versionSpec: ApkVersionSpecification
}
public enum Constraint {
case dependency, installIf
}
}
2025-07-11 20:40:23 +10:00
extension ApkIndex {
public func at(node: ApkPackageGraphNode) -> ApkIndexPackage {
self.packages[node.packageID]
2024-11-11 21:06:37 +11:00
}
}