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
|
|
|
|
|
2024-11-23 21:02:52 +11:00
|
|
|
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
|
|
|
private weak var _graph: ApkPackageGraph?
|
2024-11-11 21:06:37 +11:00
|
|
|
|
2025-07-10 21:51:30 +10:00
|
|
|
public var package: ApkIndexPackage {
|
2024-11-11 23:08:01 +11:00
|
|
|
self._graph!.pkgIndex.packages[self.packageID]
|
|
|
|
}
|
2025-07-10 21:51:30 +10:00
|
|
|
public var parents: [ApkIndexPackage] {
|
|
|
|
self.parentIDs.map { index in self._graph!.pkgIndex.packages[index] }
|
|
|
|
}
|
|
|
|
public var childPackages: [ApkIndexPackage] {
|
|
|
|
self.children.map { child in self._graph!.pkgIndex.packages[child.packageID] }
|
|
|
|
}
|
|
|
|
|
|
|
|
@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-10 21:51:30 +10:00
|
|
|
internal init(_ graph: ApkPackageGraph, id: Int, children: [ChildRef]) {
|
2024-11-11 23:08:01 +11:00
|
|
|
self._graph = graph
|
|
|
|
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
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-11-11 21:06:37 +11:00
|
|
|
extension ApkPackageGraphNode: CustomStringConvertible {
|
2024-11-23 21:02:52 +11:00
|
|
|
public var description: String {
|
2025-07-10 21:51:30 +10:00
|
|
|
let package = self.package
|
|
|
|
var result = " \(package.nameDescription):\n"
|
|
|
|
if !self.parentIDs.isEmpty {
|
|
|
|
result += " parents:\n"
|
|
|
|
for parent in self.parents {
|
|
|
|
result += " \(parent.nameDescription)\n"
|
|
|
|
}
|
2024-11-11 21:06:37 +11:00
|
|
|
}
|
|
|
|
if !self.children.isEmpty {
|
2025-07-10 21:51:30 +10:00
|
|
|
result += " children:\n"
|
|
|
|
for child in self.children {
|
|
|
|
let childPackage = self._graph!.pkgIndex.packages[child.packageID]
|
|
|
|
result += " "
|
|
|
|
switch child.constraint {
|
|
|
|
case .dependency: result += "dep="
|
|
|
|
case .installIf: result += "installIf="
|
|
|
|
}
|
|
|
|
result += childPackage.nameDescription
|
|
|
|
result += ", "
|
|
|
|
result += child.versionSpec.description
|
|
|
|
result += "\n"
|
|
|
|
}
|
2024-11-11 21:06:37 +11:00
|
|
|
}
|
|
|
|
return result
|
|
|
|
}
|
|
|
|
}
|