@@ -1119,6 +1119,14 @@ Symmetric difference between two sorted lists `a` and `b`.
1119
1119
Return the sorted list of elements belonging to `a` or to `b` but not to both.
1120
1120
1121
1121
Use [`PeriodicGraphs.symdiff_cycles!`](@ref) to provide a pre-allocated destination.
1122
+
1123
+ ## Example
1124
+ ```jldoctest
1125
+ julia> PeriodicGraphs.symdiff_cycles([3,4,5], [4,5,6])
1126
+ 2-element Vector{Int64}:
1127
+ 3
1128
+ 6
1129
+ ```
1122
1130
"""
1123
1131
symdiff_cycles (a, b) = symdiff_cycles! (Vector {Int} (undef, length (b) + length (a) - 1 ), a, b)
1124
1132
@@ -1282,7 +1290,8 @@ retrieve_track!(gauss::IterativeGaussianEliminationDecomposition) = retrieve_tra
1282
1290
1283
1291
Like [`PeriodicGraphs.intersect_cycles`](@ref) but stores the result in `c`.
1284
1292
1285
- `c` will be resized accordingly so its initial length does not matter.
1293
+ `c` will be resized accordingly so its initial length does not matter as long as it is
1294
+ at least as large as the resulting list.
1286
1295
"""
1287
1296
function intersect_cycles! (c:: Vector{T} , a:: Vector{T} , b:: Vector{T} ) where T
1288
1297
isempty (b) && (empty! (c); return c)
@@ -1301,6 +1310,7 @@ function intersect_cycles!(c::Vector{T}, a::Vector{T}, b::Vector{T}) where T
1301
1310
c[j] = xa
1302
1311
counter_b += 1
1303
1312
counter_b > lenb && @goto ret
1313
+ xb = b[counter_b]
1304
1314
end
1305
1315
end
1306
1316
@label ret
@@ -1315,10 +1325,86 @@ Intersection between two sorted lists `a` and `b`.
1315
1325
Return the sorted list of elements belonging to both `a` and `b`.
1316
1326
1317
1327
Use [`PeriodicGraphs.intersect_cycles!`](@ref) to provide a pre-allocated destination.
1328
+
1329
+ ## Example
1330
+ ```jldoctest
1331
+ julia> PeriodicGraphs.intersect_cycles([3,4,5], [4,5,6])
1332
+ 2-element Vector{Int64}:
1333
+ 4
1334
+ 5
1335
+ ```
1318
1336
"""
1319
1337
intersect_cycles (a, b) = intersect_cycles! (Vector {Int} (undef, min (length (a), length (b))), a, b)
1320
1338
1321
1339
1340
+ """
1341
+ union_cycles!(c::Vector{T}, a::Vector{T}, b::Vector{T}) where T
1342
+
1343
+ Like [`PeriodicGraphs.union_cycles`](@ref) but stores the result in `c`.
1344
+
1345
+ `c` will be resized accordingly so its initial length does not matter as long as it is
1346
+ at least as large as the resulting list.
1347
+ """
1348
+ function union_cycles! (c:: Vector{T} , a:: Vector{T} , b:: Vector{T} ) where T
1349
+ lenb = length (b)
1350
+ lena = length (a)
1351
+ counter_a = 0
1352
+ counter_b = 1
1353
+ y = lenb == 0 ? typemax (Int) : (@inbounds b[1 ])
1354
+ j = 1
1355
+ @inbounds while counter_a < lena
1356
+ counter_a += 1
1357
+ x = a[counter_a]
1358
+ while y < x
1359
+ c[j] = y
1360
+ j += 1
1361
+ counter_b += 1
1362
+ counter_b > lenb && @goto fillenda
1363
+ y = b[counter_b]
1364
+ end
1365
+ c[j] = x
1366
+ j += 1
1367
+ if y == x
1368
+ counter_b += 1
1369
+ if counter_b > lenb
1370
+ counter_a += 1
1371
+ @goto fillenda
1372
+ end
1373
+ y = b[counter_b]
1374
+ end
1375
+ end
1376
+ remaining_towriteb = lenb - counter_b + 1
1377
+ remaining_towriteb > 0 && unsafe_copyto! (c, j, b, counter_b, remaining_towriteb)
1378
+ @inbounds resize! (c, (j + remaining_towriteb - 1 ) % UInt)
1379
+ return c
1380
+
1381
+ @label fillenda
1382
+ remaining_towritea = lena - counter_a + 1
1383
+ remaining_towritea > 0 && unsafe_copyto! (c, j, a, counter_a, remaining_towritea)
1384
+ @inbounds resize! (c, (j + remaining_towritea - 1 ) % UInt)
1385
+ return c
1386
+ end
1387
+
1388
+ """
1389
+ union_cycles(a, b)
1390
+
1391
+ Union between two sorted lists `a` and `b`.
1392
+ Return the sorted list of elements belonging to `a` or `b` or both.
1393
+
1394
+ Use [`PeriodicGraphs.union_cycles!`](@ref) to provide a pre-allocated destination.
1395
+
1396
+ ## Example
1397
+ ```jldoctest
1398
+ julia> PeriodicGraphs.union_cycles([3,4,5], [4,5,6])
1399
+ 4-element Vector{Int64}:
1400
+ 3
1401
+ 4
1402
+ 5
1403
+ 6
1404
+ ```
1405
+ """
1406
+ union_cycles (a, b) = union_cycles! (Vector {Int} (undef, length (a) + length (b)), a, b)
1407
+
1322
1408
# function retrieve_vcycle(ecycle, known_pairs)
1323
1409
# fst_pair = known_pairs[ecycle[1]]
1324
1410
# last_pair = known_pairs[ecycle[end]]
0 commit comments