@@ -101,6 +101,22 @@ public let PrimsNonStrongRef: [BenchmarkInfo] = ({
101
101
touchGlobalInfo ( )
102
102
blackHole ( unmanagedPrimsState)
103
103
} ) )
104
+ benchmarks. append ( BenchmarkInfo (
105
+ name: " Prims.NonStrongRef.UnmanagedUGR " ,
106
+ runFunction: run_PrimsUnmanagedUGR,
107
+ tags: [ . validation, . algorithm, . api] ,
108
+ setUpFunction: {
109
+ touchGlobalInfo ( )
110
+ blackHole ( unmanagedUGRPrimsState)
111
+ } ) )
112
+ benchmarks. append ( BenchmarkInfo (
113
+ name: " Prims.NonStrongRef.UnmanagedUGR.ClosureAccess " ,
114
+ runFunction: run_PrimsUnmanagedUGRClosureAccess,
115
+ tags: [ . validation, . algorithm, . api] ,
116
+ setUpFunction: {
117
+ touchGlobalInfo ( )
118
+ blackHole ( unmanagedUGRPrimsState)
119
+ } ) )
104
120
return benchmarks
105
121
} ) ( )
106
122
@@ -650,6 +666,7 @@ let weakPrimsState = PrimsState(WeakGraphNode.self)
650
666
let unownedSafePrimsState = PrimsState ( UnownedSafeGraphNode . self)
651
667
let unownedUnsafePrimsState = PrimsState ( UnownedUnsafeGraphNode . self)
652
668
let unmanagedPrimsState = PrimsState ( UnmanagedGraphNode . self)
669
+ let unmanagedUGRPrimsState = PrimsState ( UnmanagedUGRGraphNode . self)
653
670
654
671
//===----------------------------------------------------------------------===//
655
672
// Protocols
@@ -765,6 +782,46 @@ extension UnmanagedVarBox : Hashable where T : Hashable {
765
782
}
766
783
}
767
784
785
+ struct UnmanagedUGRVarBox < T : AnyObject & Hashable > {
786
+ var _value : Unmanaged < T >
787
+
788
+ init ( _ inputValue: T ) {
789
+ _value = Unmanaged< T> . passRetained( inputValue)
790
+ }
791
+ }
792
+
793
+ extension UnmanagedUGRVarBox : ValueBox where T : GraphNode {
794
+ typealias ValueType = T
795
+
796
+ func free( ) {
797
+ _value. release ( )
798
+ }
799
+
800
+ var value : T { return _value. _withUnsafeGuaranteedRef { $0 } }
801
+
802
+ func withValue< Result> ( _ f: ( ValueType ) throws -> Result ) rethrows -> Result {
803
+ try _value. _withUnsafeGuaranteedRef { try f ( $0) }
804
+ }
805
+ }
806
+
807
+ extension UnmanagedUGRVarBox : Equatable where T : Equatable {
808
+ }
809
+
810
+ func == < T> ( lhs: UnmanagedUGRVarBox < T > , rhs: UnmanagedUGRVarBox < T > ) -> Bool {
811
+ return lhs. _value. _withUnsafeGuaranteedRef { x in
812
+ return rhs. _value. _withUnsafeGuaranteedRef { y in
813
+ return x == y
814
+ } }
815
+ }
816
+
817
+ extension UnmanagedUGRVarBox : Hashable where T : Hashable {
818
+ func hash( into hasher: inout Hasher ) {
819
+ _value. _withUnsafeGuaranteedRef {
820
+ hasher. combine ( ObjectIdentifier ( $0) )
821
+ }
822
+ }
823
+ }
824
+
768
825
//===----------------------------------------------------------------------===//
769
826
// Graph Node Implementations
770
827
//===----------------------------------------------------------------------===//
@@ -887,6 +944,41 @@ func ==(lhs: UnmanagedGraphNode, rhs: UnmanagedGraphNode) -> Bool {
887
944
return lhs === rhs
888
945
}
889
946
947
+
948
+ final class UnmanagedUGRGraphNode {
949
+ /// This id is only meant for dumping the state of the graph. It is not meant
950
+ /// to be used functionally by the algorithm.
951
+ var id : Int
952
+
953
+ var adjList : Array < UnmanagedUGRVarBox < UnmanagedUGRGraphNode > >
954
+
955
+ init ( id inputId: Int ) {
956
+ id = inputId
957
+ adjList = Array < UnmanagedUGRVarBox < UnmanagedUGRGraphNode > > ( )
958
+ }
959
+
960
+ deinit {
961
+ for x in adjList {
962
+ x. free ( )
963
+ }
964
+ }
965
+ }
966
+
967
+ extension UnmanagedUGRGraphNode : GraphNode {
968
+ typealias BoxType = UnmanagedUGRVarBox < UnmanagedUGRGraphNode >
969
+ }
970
+
971
+ extension UnmanagedUGRGraphNode : Equatable { }
972
+ extension UnmanagedUGRGraphNode : Hashable {
973
+ func hash( into hasher: inout Hasher ) {
974
+ hasher. combine ( ObjectIdentifier ( self ) )
975
+ }
976
+ }
977
+
978
+ func == ( lhs: UnmanagedUGRGraphNode , rhs: UnmanagedUGRGraphNode ) -> Bool {
979
+ return lhs === rhs
980
+ }
981
+
890
982
//===----------------------------------------------------------------------===//
891
983
// Edge Implementation
892
984
//===----------------------------------------------------------------------===//
@@ -1236,3 +1328,19 @@ public func run_PrimsUnmanagedClosureAccess(_ N: Int) {
1236
1328
run_PrimsNonStrongRefClosureAccess ( state)
1237
1329
}
1238
1330
}
1331
+
1332
+ @inline ( never)
1333
+ public func run_PrimsUnmanagedUGR( _ N: Int ) {
1334
+ let state = unmanagedUGRPrimsState
1335
+ for _ in 0 ..< N {
1336
+ run_PrimsNonStrongRef ( state)
1337
+ }
1338
+ }
1339
+
1340
+ @inline ( never)
1341
+ public func run_PrimsUnmanagedUGRClosureAccess( _ N: Int ) {
1342
+ let state = unmanagedUGRPrimsState
1343
+ for _ in 0 ..< N {
1344
+ run_PrimsNonStrongRefClosureAccess ( state)
1345
+ }
1346
+ }
0 commit comments