Remove more unused

This commit is contained in:
Dominik Werder
2024-10-28 13:21:19 +01:00
parent cf3c705823
commit 013c888265
21 changed files with 557 additions and 3956 deletions
-19
View File
@@ -1,6 +1,5 @@
use crate::container::ByteEstimate;
use crate::timebin::BinningggContainerBinsDyn;
use crate::timebin::TimeBinned;
use crate::AsAnyMut;
use crate::AsAnyRef;
use crate::Events;
@@ -253,21 +252,3 @@ impl CollectableDyn for Box<dyn CollectableDyn> {
CollectableDyn::new_collector(self.as_ref())
}
}
impl WithLen for Box<dyn TimeBinned> {
fn len(&self) -> usize {
WithLen::len(self.as_ref())
}
}
impl TypeName for Box<dyn TimeBinned> {
fn type_name(&self) -> String {
self.as_ref().type_name()
}
}
impl CollectableDyn for Box<dyn TimeBinned> {
fn new_collector(&self) -> Box<dyn CollectorDyn> {
self.as_ref().new_collector()
}
}
+1 -55
View File
@@ -23,7 +23,6 @@ use std::any::Any;
use std::collections::VecDeque;
use std::fmt;
use timebin::BinningggContainerEventsDyn;
use timebin::TimeBinnable;
pub trait WithLen {
fn len(&self) -> usize;
@@ -115,57 +114,12 @@ impl fmt::Display for MergeError {
impl std::error::Error for MergeError {}
pub trait IntoTimeBinnable: BoxedIntoTimeBinnable {
fn into_time_binnable(self) -> Box<dyn TimeBinnable>;
}
pub trait BoxedIntoTimeBinnable {
fn boxed_into_time_binnable(self: Box<Self>) -> Box<dyn TimeBinnable>;
}
impl<T> BoxedIntoTimeBinnable for T
where
T: IntoTimeBinnable,
{
fn boxed_into_time_binnable(self: Box<Self>) -> Box<dyn TimeBinnable> {
<Self as IntoTimeBinnable>::into_time_binnable(*self)
}
}
impl IntoTimeBinnable for Box<dyn IntoTimeBinnable + '_> {
fn into_time_binnable(self) -> Box<dyn TimeBinnable> {
<dyn IntoTimeBinnable as BoxedIntoTimeBinnable>::boxed_into_time_binnable(self)
}
}
impl IntoTimeBinnable for Box<dyn Events + '_> {
fn into_time_binnable(self) -> Box<dyn TimeBinnable> {
// <dyn IntoTimeBinnable as BoxedIntoTimeBinnable>::boxed_into_time_binnable(self)
// Box::new(*self)
// let a: Box<dyn Events> = err::todoval();
// let b: Box<dyn TimeBinnable> = Box::new(*a);
todo!()
}
}
// TODO can I remove the Any bound?
/// Container of some form of events, for use as trait object.
pub trait Events:
fmt::Debug
+ TypeName
+ Any
+ CollectableDyn
+ TimeBinnable
+ WithLen
+ ByteEstimate
+ Send
+ erased_serde::Serialize
+ EventsNonObj
+ IntoTimeBinnable
fmt::Debug + TypeName + Any + CollectableDyn + WithLen + ByteEstimate + Send + erased_serde::Serialize + EventsNonObj
{
fn as_time_binnable_ref(&self) -> &dyn TimeBinnable;
fn as_time_binnable_mut(&mut self) -> &mut dyn TimeBinnable;
fn verify(&self) -> bool;
fn output_info(&self) -> String;
fn as_collectable_mut(&mut self) -> &mut dyn CollectableDyn;
@@ -222,14 +176,6 @@ impl EventsNonObj for Box<dyn Events> {
}
impl Events for Box<dyn Events> {
fn as_time_binnable_ref(&self) -> &dyn TimeBinnable {
Events::as_time_binnable_ref(self.as_ref())
}
fn as_time_binnable_mut(&mut self) -> &mut dyn TimeBinnable {
Events::as_time_binnable_mut(self.as_mut())
}
fn verify(&self) -> bool {
Events::verify(self.as_ref())
}
-3
View File
@@ -1,4 +1,3 @@
use crate::timebin::TimeBinned;
use err::Error;
use netpod::log::Level;
use netpod::DiskStats;
@@ -202,5 +201,3 @@ mod levelserde {
de.deserialize_u32(VisitLevel)
}
}
erased_serde::serialize_trait_object!(TimeBinned);
-434
View File
@@ -135,437 +135,3 @@ pub trait BinnedEventsTimeweightTrait: fmt::Debug + Send {
fn input_done_range_open(&mut self) -> Result<(), BinningggError>;
fn output(&mut self) -> Result<Option<BinsBoxed>, BinningggError>;
}
/// Data in time-binned form.
pub trait TimeBinned: Any + TypeName + TimeBinnable + Resettable + CollectableDyn + erased_serde::Serialize {
fn clone_box_time_binned(&self) -> Box<dyn TimeBinned>;
fn as_time_binnable_ref(&self) -> &dyn TimeBinnable;
fn as_time_binnable_mut(&mut self) -> &mut dyn TimeBinnable;
fn as_collectable_mut(&mut self) -> &mut dyn CollectableDyn;
fn edges_slice(&self) -> (&[u64], &[u64]);
fn counts(&self) -> &[u64];
fn mins(&self) -> Vec<f32>;
fn maxs(&self) -> Vec<f32>;
fn avgs(&self) -> Vec<f32>;
fn validate(&self) -> Result<(), String>;
fn empty_like_self_box_time_binned(&self) -> Box<dyn TimeBinned>;
fn to_simple_bins_f32(&mut self) -> Box<dyn TimeBinned>;
fn drain_into_tb(&mut self, dst: &mut dyn TimeBinned, range: Range<usize>) -> Result<(), Error>;
}
impl Clone for Box<dyn TimeBinned> {
fn clone(&self) -> Self {
self.clone_box_time_binned()
}
}
impl TimeBinnable for Box<dyn TimeBinned> {
fn time_binner_new(
&self,
binrange: BinnedRangeEnum,
do_time_weight: bool,
emit_empty_bins: bool,
) -> Box<dyn TimeBinner> {
self.as_ref().time_binner_new(binrange, do_time_weight, emit_empty_bins)
}
fn to_box_to_json_result(&self) -> Box<dyn ToJsonResult> {
self.as_ref().to_box_to_json_result()
}
fn to_container_bins(&self) -> Box<dyn BinningggContainerBinsDyn> {
self.as_ref().to_container_bins()
}
}
pub trait TimeBinner: fmt::Debug + Send {
fn ingest(&mut self, item: &mut dyn TimeBinnable);
fn bins_ready_count(&self) -> usize;
fn bins_ready(&mut self) -> Option<Box<dyn TimeBinned>>;
/// If there is a bin in progress with non-zero count, push it to the result set.
/// With push_empty == true, a bin in progress is pushed even if it contains no counts.
fn push_in_progress(&mut self, push_empty: bool);
/// Implies `Self::push_in_progress` but in addition, pushes a zero-count bin if the call
/// to `push_in_progress` did not change the result count, as long as edges are left.
/// The next call to `Self::bins_ready_count` must return one higher count than before.
fn cycle(&mut self);
fn set_range_complete(&mut self);
fn empty(&self) -> Box<dyn TimeBinned>;
fn append_empty_until_end(&mut self);
}
// TODO remove the Any bound. Factor out into custom AsAny trait.
/// Provides a time-binned representation of the implementing type.
/// In contrast to `TimeBinnableType` this is meant for trait objects.
pub trait TimeBinnable: fmt::Debug + WithLen + CollectableDyn + Any + AsAnyRef + AsAnyMut + Send {
// TODO implementors may fail if edges contain not at least 2 entries.
fn time_binner_new(
&self,
binrange: BinnedRangeEnum,
do_time_weight: bool,
emit_empty_bins: bool,
) -> Box<dyn TimeBinner>;
// TODO just a helper for the empty result.
fn to_box_to_json_result(&self) -> Box<dyn ToJsonResult>;
// TODO temporary converter
fn to_container_bins(&self) -> Box<dyn BinningggContainerBinsDyn>;
}
impl WithLen for Box<dyn TimeBinnable> {
fn len(&self) -> usize {
WithLen::len(self.as_ref())
}
}
impl TimeBinnable for Box<dyn TimeBinnable> {
fn time_binner_new(
&self,
binrange: BinnedRangeEnum,
do_time_weight: bool,
emit_empty_bins: bool,
) -> Box<dyn TimeBinner> {
self.as_ref().time_binner_new(binrange, do_time_weight, emit_empty_bins)
}
fn to_box_to_json_result(&self) -> Box<dyn ToJsonResult> {
todo!()
}
fn to_container_bins(&self) -> Box<dyn BinningggContainerBinsDyn> {
self.as_ref().to_container_bins()
}
}
impl TimeBinnable for Box<dyn Events> {
fn time_binner_new(
&self,
binrange: BinnedRangeEnum,
do_time_weight: bool,
emit_empty_bins: bool,
) -> Box<dyn TimeBinner> {
TimeBinnable::time_binner_new(self.as_ref(), binrange, do_time_weight, emit_empty_bins)
}
fn to_box_to_json_result(&self) -> Box<dyn ToJsonResult> {
TimeBinnable::to_box_to_json_result(self.as_ref())
}
fn to_container_bins(&self) -> Box<dyn BinningggContainerBinsDyn> {
panic!("logic error this converter must not get used on events")
}
}
impl TypeName for Box<dyn TimeBinnable> {
fn type_name(&self) -> String {
format!("Box<dyn TimeBinnable> TODO TypeName for Box<dyn TimeBinnable>")
}
}
impl CollectableDyn for Box<dyn TimeBinnable> {
fn new_collector(&self) -> Box<dyn CollectorDyn> {
self.as_ref().new_collector()
}
}
#[derive(Debug)]
pub struct TimeBinnerDynStruct {
binrange: BinnedRangeEnum,
do_time_weight: bool,
binner: Option<Box<dyn TimeBinner>>,
emit_empty_bins: bool,
}
impl TimeBinnerDynStruct {
pub fn type_name() -> &'static str {
std::any::type_name::<Self>()
}
pub fn new(
binrange: BinnedRangeEnum,
do_time_weight: bool,
emit_empty_bins: bool,
binner: Box<dyn TimeBinner>,
) -> Self {
Self {
binrange,
do_time_weight,
binner: Some(binner),
emit_empty_bins,
}
}
}
impl TimeBinnerTy for TimeBinnerDynStruct {
type Input = Box<dyn TimeBinnable>;
type Output = Box<dyn TimeBinned>;
fn ingest(&mut self, item: &mut Self::Input) {
trace!("{} INGEST {:?}", Self::type_name(), item);
if self.binner.is_none() {
self.binner = Some(Box::new(TimeBinnableTy::time_binner_new(
item,
self.binrange.clone(),
self.do_time_weight,
self.emit_empty_bins,
)));
}
self.binner.as_mut().unwrap().as_mut().ingest(item.as_mut())
}
fn set_range_complete(&mut self) {
if let Some(k) = self.binner.as_mut() {
k.set_range_complete()
}
}
fn bins_ready_count(&self) -> usize {
if let Some(k) = self.binner.as_ref() {
k.bins_ready_count()
} else {
0
}
}
fn bins_ready(&mut self) -> Option<Self::Output> {
if let Some(k) = self.binner.as_mut() {
k.bins_ready()
} else {
None
}
}
fn push_in_progress(&mut self, push_empty: bool) {
if let Some(k) = self.binner.as_mut() {
k.push_in_progress(push_empty)
}
}
fn cycle(&mut self) {
if let Some(k) = self.binner.as_mut() {
k.cycle()
}
}
fn empty(&self) -> Option<Self::Output> {
if let Some(k) = self.binner.as_ref() {
Some(k.empty())
} else {
warn!("TimeBinnerDynStruct::empty called with binner None");
None
}
}
fn append_empty_until_end(&mut self) {
todo!()
}
}
impl TimeBinner for TimeBinnerDynStruct {
fn ingest(&mut self, _item: &mut dyn TimeBinnable) {
todo!()
}
fn bins_ready_count(&self) -> usize {
todo!()
}
fn bins_ready(&mut self) -> Option<Box<dyn TimeBinned>> {
todo!()
}
fn push_in_progress(&mut self, _push_empty: bool) {
todo!()
}
fn cycle(&mut self) {
todo!()
}
fn set_range_complete(&mut self) {
todo!()
}
fn empty(&self) -> Box<dyn TimeBinned> {
todo!()
}
fn append_empty_until_end(&mut self) {
todo!()
}
}
#[derive(Debug)]
pub struct TimeBinnerDynStruct2 {
binrange: BinnedRangeEnum,
do_time_weight: bool,
emit_empty_bins: bool,
binner: Option<Box<dyn TimeBinner>>,
}
impl TimeBinnerDynStruct2 {
pub fn type_name() -> &'static str {
std::any::type_name::<Self>()
}
pub fn new(
binrange: BinnedRangeEnum,
do_time_weight: bool,
emit_empty_bins: bool,
binner: Box<dyn TimeBinner>,
) -> Self {
Self {
binrange,
do_time_weight,
emit_empty_bins,
binner: Some(binner),
}
}
}
impl TimeBinnerTy for TimeBinnerDynStruct2 {
type Input = Box<dyn TimeBinned>;
type Output = Box<dyn TimeBinned>;
fn ingest(&mut self, item: &mut Self::Input) {
trace!("{} INGEST {:?}", Self::type_name(), item);
if self.binner.is_none() {
self.binner = Some(Box::new(TimeBinnableTy::time_binner_new(
item,
self.binrange.clone(),
self.do_time_weight,
self.emit_empty_bins,
)));
}
self.binner
.as_mut()
.unwrap()
.as_mut()
.ingest(item.as_time_binnable_mut())
}
fn set_range_complete(&mut self) {
if let Some(k) = self.binner.as_mut() {
k.set_range_complete()
}
}
fn bins_ready_count(&self) -> usize {
if let Some(k) = self.binner.as_ref() {
k.bins_ready_count()
} else {
0
}
}
fn bins_ready(&mut self) -> Option<Self::Output> {
if let Some(k) = self.binner.as_mut() {
k.bins_ready()
} else {
None
}
}
fn push_in_progress(&mut self, push_empty: bool) {
if let Some(k) = self.binner.as_mut() {
k.push_in_progress(push_empty)
}
}
fn cycle(&mut self) {
if let Some(k) = self.binner.as_mut() {
k.cycle()
}
}
fn empty(&self) -> Option<Self::Output> {
if let Some(k) = self.binner.as_ref() {
Some(k.empty())
} else {
warn!("TimeBinnerDynStruct::empty called with binner None");
None
}
}
fn append_empty_until_end(&mut self) {
todo!()
}
}
#[allow(unused)]
impl TimeBinner for TimeBinnerDynStruct2 {
fn ingest(&mut self, item: &mut dyn TimeBinnable) {
todo!()
}
fn bins_ready_count(&self) -> usize {
todo!()
}
fn bins_ready(&mut self) -> Option<Box<dyn TimeBinned>> {
todo!()
}
fn push_in_progress(&mut self, push_empty: bool) {
todo!()
}
fn cycle(&mut self) {
todo!()
}
fn set_range_complete(&mut self) {
todo!()
}
fn empty(&self) -> Box<dyn TimeBinned> {
todo!()
}
fn append_empty_until_end(&mut self) {
todo!()
}
}
impl TimeBinnableTy for Box<dyn TimeBinnable> {
type TimeBinner = TimeBinnerDynStruct;
fn time_binner_new(
&self,
binrange: BinnedRangeEnum,
do_time_weight: bool,
emit_empty_bins: bool,
) -> Self::TimeBinner {
let binner = self
.as_ref()
.time_binner_new(binrange.clone(), do_time_weight, emit_empty_bins);
TimeBinnerDynStruct::new(binrange, do_time_weight, emit_empty_bins, binner)
}
}
impl TimeBinnableTy for Box<dyn TimeBinned> {
type TimeBinner = TimeBinnerDynStruct2;
fn time_binner_new(
&self,
binrange: BinnedRangeEnum,
do_time_weight: bool,
emit_empty_bins: bool,
) -> Self::TimeBinner {
let binner = self
.as_time_binnable_ref()
.time_binner_new(binrange.clone(), do_time_weight, emit_empty_bins);
TimeBinnerDynStruct2::new(binrange, do_time_weight, emit_empty_bins, binner)
}
}
pub trait TimeBinnerIngest: fmt::Debug + TypeName + Send {
fn ingest_inrange(&mut self, item: &mut dyn TimeBinnable) -> Result<(), Error>;
}
-24
View File
@@ -3,7 +3,6 @@ use crate::collect_s::CollectedDyn;
use crate::streamitem::RangeCompletableItem;
use crate::streamitem::Sitemty;
use crate::streamitem::StreamItem;
use crate::timebin::TimeBinnable;
use crate::Events;
use err::Error;
use futures_util::stream;
@@ -16,11 +15,6 @@ use std::task::Poll;
pub trait EventStreamTrait: Stream<Item = Sitemty<Box<dyn Events>>> + WithTransformProperties + Send {}
pub trait TimeBinnableStreamTrait:
Stream<Item = Sitemty<Box<dyn TimeBinnable>>> + WithTransformProperties + Send
{
}
pub trait CollectableStreamTrait:
Stream<Item = Sitemty<Box<dyn CollectableDyn>>> + WithTransformProperties + Send
{
@@ -137,24 +131,6 @@ where
}
}
pub struct TimeBinnableStreamBox(pub Pin<Box<dyn TimeBinnableStreamTrait>>);
impl WithTransformProperties for TimeBinnableStreamBox {
fn query_transform_properties(&self) -> TransformProperties {
self.0.query_transform_properties()
}
}
impl Stream for TimeBinnableStreamBox {
type Item = <dyn TimeBinnableStreamTrait as Stream>::Item;
fn poll_next(mut self: Pin<&mut Self>, cx: &mut Context) -> Poll<Option<Self::Item>> {
self.0.poll_next_unpin(cx)
}
}
impl TimeBinnableStreamTrait for TimeBinnableStreamBox {}
pub struct CollectableStreamBox(pub Pin<Box<dyn CollectableStreamTrait>>);
impl Stream for CollectableStreamBox {