mirror of
https://github.com/pgpainless/pgpainless.git
synced 2024-11-16 01:12:05 +01:00
Implement Root, Roots
This commit is contained in:
parent
8f9651e8fd
commit
9515eb0934
2 changed files with 58 additions and 0 deletions
|
@ -0,0 +1,10 @@
|
||||||
|
// SPDX-FileCopyrightText: 2023 Heiko Schaefer <heiko@schaefer@name>
|
||||||
|
//
|
||||||
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
|
package org.pgpainless.wot.dijkstra.sq
|
||||||
|
|
||||||
|
data class Root(val fingerprint: Fingerprint, val amount: Int) {
|
||||||
|
|
||||||
|
override fun toString() = "$fingerprint [$amount]"
|
||||||
|
}
|
|
@ -0,0 +1,48 @@
|
||||||
|
// SPDX-FileCopyrightText: 2023 Heiko Schaefer <heiko@schaefer@name>
|
||||||
|
//
|
||||||
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
|
package org.pgpainless.wot.dijkstra.sq
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A set of `Root`s (that can be used as the basis for authentication lookups).
|
||||||
|
*/
|
||||||
|
class Roots {
|
||||||
|
|
||||||
|
// Map for efficient lookup by Fingerprint
|
||||||
|
private val roots: Map<Fingerprint, Root>
|
||||||
|
|
||||||
|
constructor(roots: List<Root>) {
|
||||||
|
this.roots = roots.associateBy { it.fingerprint }
|
||||||
|
}
|
||||||
|
|
||||||
|
constructor() : this(listOf())
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the specified root.
|
||||||
|
*/
|
||||||
|
fun get(fpr: Fingerprint): Root? = roots[fpr]
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if `fpr` is contained in this set of roots.
|
||||||
|
*/
|
||||||
|
fun isRoot(fpr: Fingerprint) = roots.containsKey(fpr)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The set of fingerprints of all roots.
|
||||||
|
*/
|
||||||
|
fun fingerprints() = roots.keys
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A collection of all roots.
|
||||||
|
*/
|
||||||
|
fun roots() = roots.values
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The number of roots
|
||||||
|
*/
|
||||||
|
fun size() = roots.size
|
||||||
|
|
||||||
|
override fun toString() = roots.keys.sorted().joinToString(", ")
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in a new issue