reorder impl blocks

so they're next to their types

Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
This commit is contained in:
Wolfgang Bumiller 2022-11-11 11:30:48 +01:00
parent 060a1ec460
commit c83c8887c8
2 changed files with 24 additions and 24 deletions

View File

@ -19,14 +19,12 @@ pub struct StaticNodeUsage {
pub maxmem: usize,
}
#[derive(Serialize, Deserialize)]
#[serde(rename_all = "kebab-case")]
/// Static usage information of an HA resource.
pub struct StaticServiceUsage {
/// Number of assigned CPUs or CPU limit.
pub maxcpu: f64,
/// Maximum assigned memory in bytes.
pub maxmem: usize,
impl StaticNodeUsage {
/// Add usage of `service` to the node's usage.
pub fn add_service_usage(&mut self, service: &StaticServiceUsage) {
self.cpu = add_cpu_usage(self.cpu, self.maxcpu as f64, service.maxcpu);
self.mem += service.maxmem;
}
}
/// Calculate new CPU usage in percent.
@ -39,12 +37,14 @@ fn add_cpu_usage(old: f64, max: f64, add: f64) -> f64 {
}
}
impl StaticNodeUsage {
/// Add usage of `service` to the node's usage.
pub fn add_service_usage(&mut self, service: &StaticServiceUsage) {
self.cpu = add_cpu_usage(self.cpu, self.maxcpu as f64, service.maxcpu);
self.mem += service.maxmem;
}
#[derive(Serialize, Deserialize)]
#[serde(rename_all = "kebab-case")]
/// Static usage information of an HA resource.
pub struct StaticServiceUsage {
/// Number of assigned CPUs or CPU limit.
pub maxcpu: f64,
/// Maximum assigned memory in bytes.
pub maxmem: usize,
}
criteria_struct! {

View File

@ -49,16 +49,6 @@ impl TopsisCriterion {
/// A normalized array of `TopsisCriterion`.
pub struct TopsisCriteria<const N_CRITERIA: usize>([TopsisCriterion; N_CRITERIA]);
/// A normalized matrix used for scoring with the TOPSIS algorithm.
pub struct TopsisMatrix<const N_CRITERIA: usize>(Vec<[f64; N_CRITERIA]>);
/// Idealized alternatives from a `TopsisMatrix`. That is, the alternative consisting of the best
/// (respectively worst) value among the alternatives in the matrix for each single criterion.
struct TopsisIdealAlternatives<const N_CRITERIA: usize> {
best: [f64; N_CRITERIA],
worst: [f64; N_CRITERIA],
}
impl<const N: usize> TopsisCriteria<N> {
/// Create a new instance of normalized TOPSIS criteria.
///
@ -95,6 +85,9 @@ impl<const N: usize> TopsisCriteria<N> {
}
}
/// A normalized matrix used for scoring with the TOPSIS algorithm.
pub struct TopsisMatrix<const N_CRITERIA: usize>(Vec<[f64; N_CRITERIA]>);
impl<const N: usize> TopsisMatrix<N> {
/// Values of the matrix for the fixed critierion with index `index`.
fn fixed_criterion(&self, index: usize) -> Vec<f64> {
@ -136,6 +129,13 @@ impl<const N: usize> TopsisMatrix<N> {
}
}
/// Idealized alternatives from a `TopsisMatrix`. That is, the alternative consisting of the best
/// (respectively worst) value among the alternatives in the matrix for each single criterion.
struct TopsisIdealAlternatives<const N_CRITERIA: usize> {
best: [f64; N_CRITERIA],
worst: [f64; N_CRITERIA],
}
/// Compute the idealized alternatives from the given `matrix`. The `criteria` are required to know
/// if a critierion should be maximized or minimized.
fn ideal_alternatives<const N: usize>(