mirror of
https://github.com/pgpainless/pgpainless.git
synced 2024-12-25 12:27:58 +01:00
backwardPropagate wrapper: simulate backwardPropagateInternal calculating all paths in one go
This commit is contained in:
parent
4583b0a742
commit
7b7601326c
1 changed files with 48 additions and 5 deletions
|
@ -194,13 +194,56 @@ class Query(
|
||||||
* FIXME: public for unit tests (undo!)
|
* FIXME: public for unit tests (undo!)
|
||||||
*/
|
*/
|
||||||
fun backwardPropagate(targetFpr: Fingerprint, targetUserid: String, filter: CertificationFilter): HashMap<Fingerprint, Pair<Path, Int>> {
|
fun backwardPropagate(targetFpr: Fingerprint, targetUserid: String, filter: CertificationFilter): HashMap<Fingerprint, Pair<Path, Int>> {
|
||||||
|
// XXX: this is an experiment, calculating both variants is possibly not the most efficient approach.
|
||||||
|
|
||||||
// Prefer paths where the target User ID is self-signed as long as possible. (But .. Why?)
|
// However, in terms of semantics, this function now simulates what would happen if
|
||||||
val authPaths = backwardPropagateInternal(targetFpr, targetUserid, true, filter)
|
// backwardPropagateInternal() were generalized to find both types of paths:
|
||||||
if (authPaths.isNotEmpty()) return authPaths
|
|
||||||
|
|
||||||
// If we find no "self-signed" paths, return any others
|
// It would prefer shorter over longer paths, or higher trust amount - so this is what we do here.
|
||||||
return backwardPropagateInternal(targetFpr, targetUserid, false, filter)
|
|
||||||
|
val a = backwardPropagateInternal(targetFpr, targetUserid, true, filter)
|
||||||
|
val b = backwardPropagateInternal(targetFpr, targetUserid, false, filter)
|
||||||
|
|
||||||
|
val c = HashMap<Fingerprint, Pair<Path, Int>>()
|
||||||
|
|
||||||
|
val keys = a.keys.toMutableSet()
|
||||||
|
keys.addAll(b.keys)
|
||||||
|
|
||||||
|
for (fp in keys) {
|
||||||
|
val x = a[fp]
|
||||||
|
val y = b[fp]
|
||||||
|
|
||||||
|
if (x != null && y != null) {
|
||||||
|
// Pick the path we like better, first by length, then by amount
|
||||||
|
println("x: $x")
|
||||||
|
println("y: $y")
|
||||||
|
|
||||||
|
if (y.first.length < x.first.length) { // prefer smaller length
|
||||||
|
println("XX found two for $fp! -> picking y by length")
|
||||||
|
c[fp] = y
|
||||||
|
} else if (x.first.length < y.first.length) {
|
||||||
|
println("XX found two for $fp! -> picking x by length")
|
||||||
|
c[fp] = x
|
||||||
|
} else {
|
||||||
|
// length is the same, pick by amount
|
||||||
|
if (y.second > x.second) { // prefer bigger amount
|
||||||
|
println("XX found two for $fp! -> picking y by amount")
|
||||||
|
c[fp] = y
|
||||||
|
} else {
|
||||||
|
println("XX found two for $fp! -> picking x by amount")
|
||||||
|
c[fp] = x
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if (x != null) {
|
||||||
|
println("XX found one for $fp, in x")
|
||||||
|
c[fp] = x
|
||||||
|
} else if (y != null) {
|
||||||
|
println("XX found one for $fp, in y")
|
||||||
|
c[fp] = y
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return c
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in a new issue