From a202a349411ad676df43a83f92aa8bfe93496cef Mon Sep 17 00:00:00 2001 From: Paul Schaub Date: Wed, 5 Jul 2023 18:06:23 +0200 Subject: [PATCH] Pour comments onto Path --- .../org/pgpainless/wot/dijkstra/sq/Path.kt | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/wot-dijkstra/src/main/kotlin/org/pgpainless/wot/dijkstra/sq/Path.kt b/wot-dijkstra/src/main/kotlin/org/pgpainless/wot/dijkstra/sq/Path.kt index 9a2c01eb..e023eba0 100644 --- a/wot-dijkstra/src/main/kotlin/org/pgpainless/wot/dijkstra/sq/Path.kt +++ b/wot-dijkstra/src/main/kotlin/org/pgpainless/wot/dijkstra/sq/Path.kt @@ -38,7 +38,7 @@ class Path( return if (edges.isEmpty()) { root } else { - edges[edges.size - 1].target + edges.last().target } } @@ -48,8 +48,7 @@ class Path( */ val certificates: List get() { - val certs: MutableList = ArrayList() - certs.add(root) + val certs: MutableList = mutableListOf(root) for (certification in edges) { certs.add(certification.target) } @@ -67,7 +66,7 @@ class Path( * List of edges. */ val certifications: List - get() = ArrayList(edges) + get() = edges.toList() /** * Trust amount of the path. @@ -99,16 +98,20 @@ class Path( "Not enough depth." } + // root is c's target -> illegal cycle var cyclic = root.fingerprint == certification.target.fingerprint for ((i, edge) in edges.withIndex()) { if (cyclic) { break } + // existing edge points to c's target -> illegal cycle if (edge.target.fingerprint == certification.target.fingerprint) { - cyclic = if (i == edges.size - 1) { - edge.userId == certification.userId - } else { + cyclic = if (edges.lastIndex != i) { + // Cycle in the middle of the ~~street~~ path true + } else { + // Not a cycle, if we point to a different user-id + edge.userId == certification.userId } } }