use super::{AssignStorageSiteTrait, CircularAlgo, HasIngestCapacityTrait, SteadyAlgo};
use crate::_auxlib as aux;
#[allow(non_snake_case)]
pub fn has_ingest_capacity<Uint: aux::UnsignedTrait>(S: Uint, T: Uint) -> bool {
let _0: Uint = Uint::zero();
let _4: Uint = Uint::from_u32(4).unwrap();
let _5: Uint = Uint::from_u32(5).unwrap();
let _6: Uint = Uint::from_u32(6).unwrap();
if S < _6 || S % _6 != _0 {
return false;
}
let sixth_S: Uint = S / _6;
let five_sixth_S: Uint = _5 * sixth_S;
let t_div_6: Uint = T / _6;
let t_mod_6: Uint = T % _6;
let adj_t_mod: Uint = if t_mod_6 < _5 { t_mod_6 } else { _4 };
let has_capacity_1st =
CircularAlgo::has_ingest_capacity(five_sixth_S, t_div_6 * _5 + adj_t_mod);
let has_capacity_2nd = T < _5 || SteadyAlgo::has_ingest_capacity(sixth_S, (T - _5) / _6);
has_capacity_1st && has_capacity_2nd
}
#[allow(non_snake_case)]
pub fn _assign_storage_site<Uint: aux::UnsignedTrait>(S: Uint, T: Uint) -> Uint {
debug_assert!(has_ingest_capacity(S, T));
let _5: Uint = Uint::from_u32(5).unwrap();
let _6: Uint = Uint::from_u32(6).unwrap();
let sixth_S: Uint = S / _6;
let five_sixth_S: Uint = _5 * sixth_S;
let remainder: Uint = T % _6;
if remainder < _5 {
let adj_T: Uint = (T / _6) * _5 + remainder;
let site: Uint = CircularAlgo::_assign_storage_site(five_sixth_S, adj_T);
if site == five_sixth_S {
S
} else {
site
}
} else {
let adj_T: Uint = T / _6;
let site: Uint = SteadyAlgo::_assign_storage_site(sixth_S, adj_T);
if site == sixth_S {
S
} else {
five_sixth_S + site
}
}
}
#[allow(non_snake_case)]
pub fn assign_storage_site<Uint: aux::UnsignedTrait>(S: Uint, T: Uint) -> Option<Uint> {
let k: Uint = _assign_storage_site(S, T);
if k == S {
None
} else {
Some(k)
}
}
pub struct Algo;
#[allow(non_snake_case)]
impl crate::dstream::HasIngestCapacityTrait for Algo {
fn has_ingest_capacity<Uint: aux::UnsignedTrait>(S: Uint, T: Uint) -> bool {
has_ingest_capacity::<Uint>(S, T)
}
}
#[allow(non_snake_case)]
impl crate::dstream::AssignStorageSiteTrait for Algo {
fn _assign_storage_site<Uint: aux::UnsignedTrait>(S: Uint, T: Uint) -> Uint {
_assign_storage_site::<Uint>(S, T)
}
fn assign_storage_site<Uint: aux::UnsignedTrait>(S: Uint, T: Uint) -> Option<Uint> {
assign_storage_site::<Uint>(S, T)
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_smoke_has_ingest_capacity() {
has_ingest_capacity::<u32>(24, 5);
}
#[test]
fn test_smoke_assign_storage_site() {
assign_storage_site::<u32>(24, 5);
}
#[test]
fn test_smoke_impl_assign_storage_site() {
_assign_storage_site::<u32>(24, 5);
}
}