pub struct PredicateHistogram {
pub predicate_iri: String,
pub total_count: u64,
pub null_count: u64,
pub distinct_count: u64,
pub buckets: Vec<HistogramBucket>,
}Expand description
Equi-depth histogram for the object values of a specific predicate.
All buckets have approximately equal count (depth), spread across the ordered value space.
Fields§
§predicate_iri: StringIRI of the predicate this histogram covers.
total_count: u64Total number of non-null values seen.
null_count: u64Number of null / missing object values.
distinct_count: u64Number of globally distinct object values (approximate, from build phase).
buckets: Vec<HistogramBucket>Equi-depth buckets (sorted by lower_bound ascending).
Implementations§
Source§impl PredicateHistogram
impl PredicateHistogram
Sourcepub fn new(predicate: &str, num_buckets: usize) -> Self
pub fn new(predicate: &str, num_buckets: usize) -> Self
Create an empty histogram for predicate with num_buckets bucket slots.
Sourcepub fn build_from_values(
predicate: &str,
values: &[String],
num_buckets: usize,
) -> Self
pub fn build_from_values( predicate: &str, values: &[String], num_buckets: usize, ) -> Self
Build an equi-depth histogram from values, targeting num_buckets buckets.
The approach is:
- Sort all (non-empty) values lexicographically.
- Split into
num_bucketsequal-sized slices. - For each slice compute distinct count via deduplication.
Complexity: O(n log n) where n = values.len().
Sourcepub fn estimate_selectivity_eq(&self, value: &str) -> f64
pub fn estimate_selectivity_eq(&self, value: &str) -> f64
Estimate the selectivity (fraction of rows) for an equality predicate object = value.
Returns a value in [0, 1]. Uses a uniform assumption within the containing bucket.
Sourcepub fn estimate_selectivity_range(&self, lo: &str, hi: &str) -> f64
pub fn estimate_selectivity_range(&self, lo: &str, hi: &str) -> f64
Estimate the selectivity for a range predicate lo <= object <= hi.
Returns a value in [0, 1].
Sourcepub fn estimate_cardinality(
&self,
total_triples: u64,
predicate_filter: Option<&str>,
) -> u64
pub fn estimate_cardinality( &self, total_triples: u64, predicate_filter: Option<&str>, ) -> u64
Estimate the expected cardinality for a pattern that filters this predicate’s objects.
If predicate_filter is Some(value) an equality filter is applied; otherwise all
triples with this predicate are returned.
total_triples is used as a fallback denominator when self.total_count is zero.
Sourcepub fn update_incremental(&mut self, new_values: &[String])
pub fn update_incremental(&mut self, new_values: &[String])
Incrementally update the histogram with additional observed values.
This is an approximate update: new values are inserted into the most appropriate existing
bucket (lowest lower_bound not greater than the value), and global counts are adjusted.
After many incremental updates, accuracy degrades and a full rebuild is recommended.
Sourcepub fn num_buckets(&self) -> usize
pub fn num_buckets(&self) -> usize
Returns the number of buckets in this histogram.
Trait Implementations§
Source§impl Clone for PredicateHistogram
impl Clone for PredicateHistogram
Source§fn clone(&self) -> PredicateHistogram
fn clone(&self) -> PredicateHistogram
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl Freeze for PredicateHistogram
impl RefUnwindSafe for PredicateHistogram
impl Send for PredicateHistogram
impl Sync for PredicateHistogram
impl Unpin for PredicateHistogram
impl UnsafeUnpin for PredicateHistogram
impl UnwindSafe for PredicateHistogram
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more