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

View File

@ -49,16 +49,6 @@ impl TopsisCriterion {
/// A normalized array of `TopsisCriterion`. /// A normalized array of `TopsisCriterion`.
pub struct TopsisCriteria<const N_CRITERIA: usize>([TopsisCriterion; N_CRITERIA]); 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> { impl<const N: usize> TopsisCriteria<N> {
/// Create a new instance of normalized TOPSIS criteria. /// 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> { impl<const N: usize> TopsisMatrix<N> {
/// Values of the matrix for the fixed critierion with index `index`. /// Values of the matrix for the fixed critierion with index `index`.
fn fixed_criterion(&self, index: usize) -> Vec<f64> { 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 /// Compute the idealized alternatives from the given `matrix`. The `criteria` are required to know
/// if a critierion should be maximized or minimized. /// if a critierion should be maximized or minimized.
fn ideal_alternatives<const N: usize>( fn ideal_alternatives<const N: usize>(