mirror of
https://github.com/GayPizzaSpecifications/darwin-apk.git
synced 2025-08-06 14:41:35 +00:00
Port index changes to parallel sort
This commit is contained in:
@ -1,24 +1,31 @@
|
||||
/*
|
||||
* darwin-apk © 2024 Gay Pizza Specifications
|
||||
* darwin-apk © 2024, 2025 Gay Pizza Specifications
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
import Foundation
|
||||
|
||||
public class ApkPackageGraphNode {
|
||||
public let packageID: ApkIndex.Index
|
||||
public var parentIDs = [ApkIndex.Index]()
|
||||
public var children: [ChildRef]
|
||||
|
||||
private weak var _graph: ApkPackageGraph?
|
||||
let packageID: Int
|
||||
|
||||
//private var _parents = NSHashTable<ApkPackageGraphNode>.weakObjects()
|
||||
//private var _children = NSHashTable<ApkPackageGraphNode>.weakObjects()
|
||||
var parents = [ApkIndexRequirementRef]()
|
||||
var children: [ApkIndexRequirementRef]
|
||||
|
||||
var package: ApkIndexPackage {
|
||||
public var package: ApkIndexPackage {
|
||||
self._graph!.pkgIndex.packages[self.packageID]
|
||||
}
|
||||
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] }
|
||||
}
|
||||
|
||||
internal init(_ graph: ApkPackageGraph, id: Int, children: [ApkIndexRequirementRef]) {
|
||||
@inlinable public var isShallow: Bool { self.parentIDs.isEmpty }
|
||||
@inlinable public var isDeep: Bool { self.children.isEmpty }
|
||||
|
||||
internal init(_ graph: ApkPackageGraph, id: Int, children: [ChildRef]) {
|
||||
self._graph = graph
|
||||
self.packageID = id
|
||||
self.children = children
|
||||
@ -35,15 +42,42 @@ extension ApkPackageGraphNode: Equatable, Hashable {
|
||||
}
|
||||
}
|
||||
|
||||
extension ApkPackageGraphNode {
|
||||
public struct ChildRef {
|
||||
let constraint: Constraint
|
||||
let packageID: Int
|
||||
let versionSpec: ApkVersionSpecification
|
||||
}
|
||||
|
||||
public enum Constraint {
|
||||
case dependency, installIf
|
||||
}
|
||||
}
|
||||
|
||||
extension ApkPackageGraphNode: CustomStringConvertible {
|
||||
public var description: String {
|
||||
var result = "node[\(self.package.name)]"
|
||||
if !self.parents.isEmpty {
|
||||
result += ", parents[\(self.parents.lazy.map(\.description).joined(separator: ", "))]"
|
||||
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"
|
||||
}
|
||||
}
|
||||
if !self.children.isEmpty {
|
||||
result += ", children[\(self.children.lazy.map(\.description).joined(separator: ", "))]"
|
||||
|
||||
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"
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
Reference in New Issue
Block a user