From 163052cd25d927c9437a2234befd22c9d143c4d4 Mon Sep 17 00:00:00 2001 From: metamuffin Date: Sat, 11 Jun 2022 18:55:54 +0200 Subject: redundant Instance --- karld/src/condition.rs | 1 + karld/src/helper.rs | 12 ++++++++++-- karld/src/main.rs | 12 +++--------- 3 files changed, 14 insertions(+), 11 deletions(-) (limited to 'karld') diff --git a/karld/src/condition.rs b/karld/src/condition.rs index 81f7245..765e039 100644 --- a/karld/src/condition.rs +++ b/karld/src/condition.rs @@ -47,6 +47,7 @@ impl ConditionFind for Condition { match self { Condition::And(cs) => loop { // TODO improve efficiency for backward search + // TODO fix endless search let last_start = cs .iter() .map(|c| c.find_inverse_inclusive(Start, dir, from)) diff --git a/karld/src/helper.rs b/karld/src/helper.rs index 2e601b0..f106df6 100644 --- a/karld/src/helper.rs +++ b/karld/src/helper.rs @@ -1,5 +1,5 @@ use crate::condition::{ConditionFind, Direction, Edge}; -use chrono::{NaiveDate, NaiveDateTime}; +use chrono::NaiveDateTime; use karlcommon::{Schedule, Task}; use std::{collections::HashMap, ops::Range}; @@ -34,9 +34,17 @@ impl DiscreteCacheTask { } pub fn find(&mut self, from: NaiveDateTime, dir: Direction) -> Range> { - assert_eq!(dir, Direction::Forward); // 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); diff --git a/karld/src/main.rs b/karld/src/main.rs index 181c2be..35cca04 100644 --- a/karld/src/main.rs +++ b/karld/src/main.rs @@ -10,7 +10,7 @@ use crossbeam_channel::Sender; use helper::Overlaps; use interface::network_loop; use karlcommon::{ - ClientboundPacket, Condition, Instance, Property, ProtoError, Schedule, ServerboundPacket, Task, + ClientboundPacket, Condition, Property, ProtoError, Schedule, ServerboundPacket, Task, }; use log::{debug, error, info}; use std::{collections::HashMap, sync::RwLock}; @@ -118,10 +118,7 @@ pub fn handle_packet(client: u32, packet: ServerboundPacket, responder: Sender (), // TODO Schedule::Static(r) => { if range.overlaps(r.clone()) { - ocs.push(Instance { - of: t.id, - at: Some(r.start)..Some(r.end), - }) + ocs.push(Some(r.start)..Some(r.end)) } } Schedule::Condition(o) => { @@ -131,10 +128,7 @@ pub fn handle_packet(client: u32, packet: ServerboundPacket, responder: Sender e { -- cgit v1.2.3-70-g09d2