From a7abc26af31b69db06a5875fc3fbc756adc838b1 Mon Sep 17 00:00:00 2001 From: metamuffin Date: Mon, 13 Jun 2022 12:21:07 +0200 Subject: blub --- karld/src/helper.rs | 156 ++++++++++++++++++++++++++-------------------------- 1 file changed, 79 insertions(+), 77 deletions(-) (limited to 'karld/src/helper.rs') diff --git a/karld/src/helper.rs b/karld/src/helper.rs index f106df6..c5df979 100644 --- a/karld/src/helper.rs +++ b/karld/src/helper.rs @@ -1,85 +1,87 @@ -use crate::condition::{ConditionFind, Direction, Edge}; -use chrono::NaiveDateTime; -use karlcommon::{Schedule, Task}; -use std::{collections::HashMap, ops::Range}; +use std::ops::Range; -pub struct DiscreteCache { - tasks: HashMap, -} -pub struct DiscreteCacheTask { - inner: Task, - cached: Option>, - cache: Vec>, -} +// use crate::condition::{ConditionFind, Direction, Edge}; +// use chrono::NaiveDateTime; +// use karlcommon::{Schedule, Task}; +// use std::{collections::HashMap, ops::Range}; -impl DiscreteCache { - pub fn new_for(tasks: HashMap) -> Self { - Self { - tasks: HashMap::from_iter( - tasks - .into_iter() - .map(|(k, v)| (k, DiscreteCacheTask::new(v))), - ), - } - } -} +// pub struct DiscreteCache { +// tasks: HashMap, +// } +// pub struct DiscreteCacheTask { +// inner: Task, +// cached: Option>, +// cache: Vec>, +// } -impl DiscreteCacheTask { - pub fn new(inner: Task) -> Self { - Self { - inner, - cached: None, - cache: vec![], - } - } +// impl DiscreteCache { +// pub fn new_for(tasks: HashMap) -> Self { +// Self { +// tasks: HashMap::from_iter( +// tasks +// .into_iter() +// .map(|(k, v)| (k, DiscreteCacheTask::new(v))), +// ), +// } +// } +// } - pub fn find(&mut self, from: NaiveDateTime, dir: Direction) -> Range> { - // TODO cache - // if let Some(c) = self.cached {} - return self.find_uncached(from, dir); - } +// impl DiscreteCacheTask { +// pub fn new(inner: Task) -> Self { +// Self { +// inner, +// cached: None, +// cache: vec![], +// } +// } - pub fn find_uncached( - &mut self, - from: NaiveDateTime, - dir: Direction, - ) -> Range> { - assert_eq!(dir, Direction::Forward); // TODO undefined behaviour if dir is not forward (maybe it even works backward) - match &self.inner.schedule { - Schedule::Condition(o) => { - let start = o.find(Edge::Start, dir, from); - let end = o.find(Edge::End, dir, from); - match (start, end) { - (Some(start), Some(end)) => { - if end < start { - if let Some(start) = o.find(Edge::Start, dir.invert(), from) { - assert!(start < end); - Some(start)..Some(end) - } else { - None..Some(end) - } - } else { - Some(start)..Some(end) - } - } - (None, Some(end)) => { - if let Some(start) = o.find(Edge::Start, dir.invert(), from) { - assert!(start < end); - Some(start)..Some(end) - } else { - None..Some(end) - } - } - (Some(start), None) => Some(start)..None, - (None, None) => None..None, - } - } - Schedule::Never => None..None, - Schedule::Static(_) => None..None, // TODO - Schedule::Dynamic { .. } => None..None, // TODO - } - } -} +// pub fn find(&mut self, from: NaiveDateTime, dir: Direction) -> Range> { +// // TODO cache +// // if let Some(c) = self.cached {} +// return self.find_uncached(from, dir); +// } + +// pub fn find_uncached( +// &mut self, +// from: NaiveDateTime, +// dir: Direction, +// ) -> Range> { +// assert_eq!(dir, Direction::Forward); // TODO undefined behaviour if dir is not forward (maybe it even works backward) +// match &self.inner.schedule { +// Schedule::Condition(o) => { +// let start = o.find(Edge::Start, dir, from); +// let end = o.find(Edge::End, dir, from); +// match (start, end) { +// (Some(start), Some(end)) => { +// if end < start { +// if let Some(start) = o.find(Edge::Start, dir.invert(), from) { +// assert!(start < end); +// Some(start)..Some(end) +// } else { +// None..Some(end) +// } +// } else { +// Some(start)..Some(end) +// } +// } +// (None, Some(end)) => { +// if let Some(start) = o.find(Edge::Start, dir.invert(), from) { +// assert!(start < end); +// Some(start)..Some(end) +// } else { +// None..Some(end) +// } +// } +// (Some(start), None) => Some(start)..None, +// (None, None) => None..None, +// } +// } +// Schedule::Never => None..None, +// Schedule::Static(_) => None..None, // TODO +// Schedule::Dynamic { .. } => None..None, // TODO +// } +// } +// } pub trait Overlaps { fn overlaps(&self, v: T) -> bool; -- cgit v1.2.3-70-g09d2