1
0
Fork 0
mirror of https://github.com/pgpainless/pgpainless.git synced 2024-12-25 12:27:58 +01:00

Pour comments onto Path

This commit is contained in:
Paul Schaub 2023-07-05 18:06:23 +02:00
parent 7fa8489d43
commit a202a34941
Signed by: vanitasvitae
GPG key ID: 62BEE9264BF17311

View file

@ -38,7 +38,7 @@ class Path(
return if (edges.isEmpty()) { return if (edges.isEmpty()) {
root root
} else { } else {
edges[edges.size - 1].target edges.last().target
} }
} }
@ -48,8 +48,7 @@ class Path(
*/ */
val certificates: List<CertSynopsis> val certificates: List<CertSynopsis>
get() { get() {
val certs: MutableList<CertSynopsis> = ArrayList() val certs: MutableList<CertSynopsis> = mutableListOf(root)
certs.add(root)
for (certification in edges) { for (certification in edges) {
certs.add(certification.target) certs.add(certification.target)
} }
@ -67,7 +66,7 @@ class Path(
* List of edges. * List of edges.
*/ */
val certifications: List<Certification> val certifications: List<Certification>
get() = ArrayList(edges) get() = edges.toList()
/** /**
* Trust amount of the path. * Trust amount of the path.
@ -99,16 +98,20 @@ class Path(
"Not enough depth." "Not enough depth."
} }
// root is c's target -> illegal cycle
var cyclic = root.fingerprint == certification.target.fingerprint var cyclic = root.fingerprint == certification.target.fingerprint
for ((i, edge) in edges.withIndex()) { for ((i, edge) in edges.withIndex()) {
if (cyclic) { if (cyclic) {
break break
} }
// existing edge points to c's target -> illegal cycle
if (edge.target.fingerprint == certification.target.fingerprint) { if (edge.target.fingerprint == certification.target.fingerprint) {
cyclic = if (i == edges.size - 1) { cyclic = if (edges.lastIndex != i) {
edge.userId == certification.userId // Cycle in the middle of the ~~street~~ path
} else {
true true
} else {
// Not a cycle, if we point to a different user-id
edge.userId == certification.userId
} }
} }
} }