refactor: encapsulate read-only Theta sketch views#151
Conversation
| #[allow(private_bounds)] | ||
| pub fn update<V>(&mut self, sketch: ThetaSketchView<V>) -> Result<(), Error> | ||
| where | ||
| V: RawThetaSketchView<ThetaEntry>, | ||
| { |
There was a problem hiding this comment.
This would make the document of update cannot linked to RawThetaSketchView and remain a dead link on docs.rs.
Let me think of how to expose the symbols here.
There was a problem hiding this comment.
To avoid trait here, we can use enum to dispatch.🤔
There was a problem hiding this comment.
Another way is to export using new trait like TupleSketchView. We don't need to test it, and it can be sealed::Sealed. And thetacommon can internal and not export to user.
pub trait TupleSketchView<S>: sealed::Sealed {
/// Return the 16-bit seed hash.
fn seed_hash(&self) -> u16;
/// Return theta as a `u64` threshold.
fn theta(&self) -> u64;
/// Return whether this sketch has not received any updates.
fn is_empty(&self) -> bool;
/// Return whether retained entries are ordered by ascending hash.
fn is_ordered(&self) -> bool;
/// Return an iterator over retained entries.
fn iter(&self) -> impl Iterator<Item = TupleEntry<S>> + '_;
/// Return the number of retained entries.
fn num_retained(&self) -> usize;
}
impl<S, T> RawThetaSketchView<TupleEntry<S>> for T
where
T: TupleSketchView<S> + ?Sized,
{
fn seed_hash(&self) -> u16 {
TupleSketchView::seed_hash(self)
}
fn theta(&self) -> u64 {
TupleSketchView::theta(self)
}
fn is_empty(&self) -> bool {
TupleSketchView::is_empty(self)
}
fn is_ordered(&self) -> bool {
TupleSketchView::is_ordered(self)
}
fn iter(&self) -> impl Iterator<Item = TupleEntry<S>> + '_ {
TupleSketchView::iter(self)
}
fn num_retained(&self) -> usize {
TupleSketchView::num_retained(self)
}
}
tisonkun
left a comment
There was a problem hiding this comment.
Looks like an incorrect abstraction.
I think we can review and merge the tuple sketches code and later try to factor out the abstraction.
So far, I don't see a concrete reason for all these abstratcions. We can inline the ThetaSketchView if this is the only impl.
Summary
Validation