mirror of
https://github.com/pgpainless/pgpainless.git
synced 2024-12-25 12:27:58 +01:00
q: simplify comparison, use comparator
This commit is contained in:
parent
98bccf78df
commit
18219aa186
1 changed files with 3 additions and 48 deletions
|
@ -494,55 +494,10 @@ class Query(
|
||||||
|
|
||||||
val currentFpCost = currentFpCost!! // shadow the variable
|
val currentFpCost = currentFpCost!! // shadow the variable
|
||||||
|
|
||||||
val cn = currentFp.next // cache value for debug output
|
// If the proposed Fp is better, replace it in the forward pointer list
|
||||||
logger.debug(" Current: {}, amount: {}, depth: {}",
|
if (proposedFpCost > currentFpCost) {
|
||||||
cn?.target ?: "target", currentFpCost.amount, currentFpCost.length)
|
logger.debug(" Preferring proposed: current {}, proposed {}", currentFpCost, proposedFpCost)
|
||||||
|
|
||||||
// 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
|
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)
|
|
||||||
|
|
||||||
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)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue