1
0
Fork 0
mirror of https://github.com/pgpainless/pgpainless.git synced 2024-06-17 09:04:50 +02:00

q: simplify comparison, use comparator

This commit is contained in:
Heiko Schaefer 2023-07-10 21:11:25 +02:00
parent 98bccf78df
commit 18219aa186
No known key found for this signature in database
GPG key ID: 4A849A1904CCBD7D

View file

@ -494,55 +494,10 @@ class Query(
val currentFpCost = currentFpCost!! // shadow the variable
val cn = currentFp.next // cache value for debug output
logger.debug(" Current: {}, amount: {}, depth: {}",
cn?.target ?: "target", currentFpCost.amount, currentFpCost.length)
// We prefer a shorter path (in terms of
// edges) as this allows us to reach more of
// the graph.
//
// If the path length is equal, we prefer the
// larger amount of trust.
if (proposedFpCost.length < currentFpCost.length) {
if (proposedFpCost.amount < currentFpCost.amount) {
// We have two local optima: one has a shorter path, the other a
// higher trust amount. We prefer the shorter path.
logger.debug(" Preferring proposed: current has a shorter path ({} < {}), but worse amount of trust ({} < {})",
proposedFpCost.length, currentFpCost.length,
proposedFpCost.amount, currentFpCost.amount)
bestNextNode[issuerFpr] = proposedFp
} else {
// Proposed fp is strictly better.
logger.debug(" Preferring proposed: current has a shorter path ({} < {}), and a better amount of trust ({} < {})",
proposedFpCost.length, currentFpCost.length,
proposedFpCost.amount, currentFpCost.amount)
bestNextNode[issuerFpr] = proposedFp
}
} else if (proposedFpCost.length == currentFpCost.length
&& proposedFpCost.amount > currentFpCost.amount) {
// Strictly better.
logger.debug(" Preferring proposed fp: same path length ({}), better amount ({} > {})",
proposedFpCost.length,
proposedFpCost.amount, currentFpCost.amount)
// If the proposed Fp is better, replace it in the forward pointer list
if (proposedFpCost > currentFpCost) {
logger.debug(" Preferring proposed: current {}, proposed {}", currentFpCost, proposedFpCost)
bestNextNode[issuerFpr] = proposedFp
} else if (proposedFpCost.length > currentFpCost.length
&& proposedFpCost.amount > currentFpCost.amount) {
// There's another possible path through here.
logger.debug(" Preferring current fp: proposed has more trust ({} > {}), but a longer path ({} > {})",
proposedFpCost.amount, currentFpCost.amount,
proposedFpCost.length, currentFpCost.length)
} else {
logger.debug(" Preferring current fp: it is strictly better (depth: {}, {}; amount: {}, {})",
proposedFpCost.length, currentFpCost.length,
proposedFpCost.amount, currentFpCost.amount)
}
}
}