From a1ef11f3f4f739ccd5555fa5239a69ffbdeca5c0 Mon Sep 17 00:00:00 2001 From: Max Bachmann Date: Wed, 29 Nov 2023 05:51:12 +0100 Subject: [PATCH] slignt cleanup --- src/distance/osa.rs | 51 ++++++++++++++++++++++++++------------------- 1 file changed, 29 insertions(+), 22 deletions(-) diff --git a/src/distance/osa.rs b/src/distance/osa.rs index 9584283..89ecdac 100644 --- a/src/distance/osa.rs +++ b/src/distance/osa.rs @@ -216,13 +216,15 @@ pub struct NoScoreCutoff; #[derive(Default, Clone)] pub struct WithScoreCutoff(T); -pub struct IndividualComparator { +pub struct IndividualComparator { score_cutoff: CutoffType, score_hint: Option, - metric_type: PhantomData, + metric_type: PhantomData, } -impl Default for IndividualComparator { +impl Default + for IndividualComparator +{ fn default() -> Self { Self { score_cutoff: Default::default(), @@ -232,7 +234,9 @@ impl Default for IndividualComparator MetricUsize for IndividualComparator { +impl MetricUsize + for IndividualComparator +{ fn maximum(&self, len1: usize, len2: usize) -> usize { len1.max(len2) } @@ -292,7 +296,7 @@ impl MetricUsize for IndividualComparator IndividualComparator { +impl IndividualComparator { pub fn with_score_hint(mut self, score_hint: impl Into) -> Self { self.score_hint = Some(score_hint.into()); self @@ -301,7 +305,7 @@ impl IndividualComparator pub fn with_score_cutoff( self, score_cutoff: impl Into, - ) -> IndividualComparator> { + ) -> IndividualComparator> { IndividualComparator { score_hint: self.score_hint, score_cutoff: WithScoreCutoff(score_cutoff.into()), @@ -427,19 +431,19 @@ impl IndividualComparator> { } pub fn distance() -> IndividualComparator { - IndividualComparator::::default() + IndividualComparator::default() } pub fn similarity() -> IndividualComparator { - IndividualComparator::::default() + IndividualComparator::default() } pub fn normalized_distance() -> IndividualComparator { - IndividualComparator::::default() + IndividualComparator::default() } pub fn normalized_similarity() -> IndividualComparator { - IndividualComparator::::default() + IndividualComparator::default() } pub struct BatchComparator { @@ -447,15 +451,15 @@ pub struct BatchComparator { pm: BlockPatternMatchVector, } -pub struct BatchComparatorBuilder<'a, Elem1, T, ResultType, CutoffType> { +pub struct BatchComparatorBuilder<'a, Elem1, MetricType, ResultType, CutoffType> { cache: &'a BatchComparator, score_cutoff: CutoffType, score_hint: Option, - metric_type: PhantomData, + metric_type: PhantomData, } -impl MetricUsize - for BatchComparatorBuilder<'_, Elem1, T, ResultType, CutoffType> +impl MetricUsize + for BatchComparatorBuilder<'_, Elem1, MetricType, ResultType, CutoffType> { fn maximum(&self, len1: usize, len2: usize) -> usize { len1.max(len2) @@ -496,7 +500,9 @@ impl MetricUsize } } -impl<'a, Elem1, T, ResultType> BatchComparatorBuilder<'a, Elem1, T, ResultType, NoScoreCutoff> { +impl<'a, Elem1, MetricType, ResultType> + BatchComparatorBuilder<'a, Elem1, MetricType, ResultType, NoScoreCutoff> +{ fn new(cache: &'a BatchComparator) -> Self { Self { cache, @@ -507,8 +513,8 @@ impl<'a, Elem1, T, ResultType> BatchComparatorBuilder<'a, Elem1, T, ResultType, } } -impl<'a, Elem1, T, ResultType, CutoffType> - BatchComparatorBuilder<'a, Elem1, T, ResultType, CutoffType> +impl<'a, Elem1, MetricType, ResultType, CutoffType> + BatchComparatorBuilder<'a, Elem1, MetricType, ResultType, CutoffType> { pub fn with_score_hint(mut self, score_hint: impl Into) -> Self { self.score_hint = Some(score_hint.into()); @@ -518,7 +524,8 @@ impl<'a, Elem1, T, ResultType, CutoffType> pub fn with_score_cutoff( self, score_cutoff: impl Into, - ) -> BatchComparatorBuilder<'a, Elem1, T, ResultType, WithScoreCutoff> { + ) -> BatchComparatorBuilder<'a, Elem1, MetricType, ResultType, WithScoreCutoff> + { BatchComparatorBuilder { cache: self.cache, score_hint: self.score_hint, @@ -672,26 +679,26 @@ where pub fn normalized_distance<'a>( &'a self, ) -> BatchComparatorBuilder<'a, Elem1, NormDist, f64, NoScoreCutoff> { - BatchComparatorBuilder::<'a, Elem1, NormDist, f64, NoScoreCutoff>::new(self) + BatchComparatorBuilder::new(self) } /// Normalized similarity calculated similar to [`normalized_similarity`] pub fn normalized_similarity<'a>( &'a self, ) -> BatchComparatorBuilder<'a, Elem1, NormSim, f64, NoScoreCutoff> { - BatchComparatorBuilder::<'a, Elem1, NormSim, f64, NoScoreCutoff>::new(self) + BatchComparatorBuilder::new(self) } /// Distance calculated similar to [`distance`] pub fn distance<'a>(&'a self) -> BatchComparatorBuilder<'a, Elem1, Dist, usize, NoScoreCutoff> { - BatchComparatorBuilder::<'a, Elem1, Dist, usize, NoScoreCutoff>::new(self) + BatchComparatorBuilder::new(self) } /// Similarity calculated similar to [`similarity`] pub fn similarity<'a>( &'a self, ) -> BatchComparatorBuilder<'a, Elem1, Sim, usize, NoScoreCutoff> { - BatchComparatorBuilder::<'a, Elem1, Sim, usize, NoScoreCutoff>::new(self) + BatchComparatorBuilder::new(self) } }