use std::iter::Sum; use super::{ AnyMap, Date, DateMapChunkId, GenericMap, Height, HeightMap, MapValue, SerializedDateMap, }; pub type DateMap = GenericMap>; impl DateMap where Value: MapValue, { pub fn multi_insert_last( &mut self, dates: &[Date], source: &mut HeightMap, last_height: &mut DateMap, ) { dates.iter().for_each(|date| { self.insert_computed( *date, source .get_or_import(&last_height.get_or_import(date).unwrap()) .unwrap(), ); }); } pub fn multi_insert_sum_range( &mut self, dates: &[Date], height_map: &HeightMap, first_height: &mut DateMap, last_height: &mut DateMap, ) where Value: Sum, { dates.iter().for_each(|date| { let first_height = first_height.get_or_import(date).unwrap(); let last_height = last_height.get_or_import(date).unwrap(); let range = (*first_height)..=(*last_height); self.insert_computed(*date, height_map.sum_range(&range)); }) } } pub trait AnyDateMap: AnyMap { fn get_initial_first_unsafe_date(&self) -> Option; fn get_initial_last_date(&self) -> Option; fn as_any_map(&self) -> &(dyn AnyMap + Send + Sync); fn as_any_mut_map(&mut self) -> &mut dyn AnyMap; } impl AnyDateMap for DateMap where T: MapValue, { #[inline(always)] fn get_initial_first_unsafe_date(&self) -> Option { self.initial_first_unsafe_key } #[inline(always)] fn get_initial_last_date(&self) -> Option { self.initial_last_key } fn as_any_map(&self) -> &(dyn AnyMap + Send + Sync) { self } fn as_any_mut_map(&mut self) -> &mut dyn AnyMap { self } }