use std::ops::Bound;
use crate::common::counter::hardware_counter::HardwareCounterCell;
use crate::common::types::PointOffsetType;
use super::Encodable;
use crate::segment::common::operation_error::OperationResult;
use crate::segment::index::field_index::histogram::Histogram;
use crate::segment::index::field_index::numeric_point::{Numericable, Point};
use crate::segment::index::field_index::stored_point_to_values::StoredValue;
use crate::segment::index::payload_config::StorageType;
use crate::segment::telemetry::PayloadIndexTelemetry;
pub trait NumericIndexRead<T: Encodable + Numericable + Default + StoredValue> {
fn check_values_any(
&self,
idx: PointOffsetType,
check_fn: impl Fn(&T) -> bool,
hw_counter: &HardwareCounterCell,
) -> bool;
fn get_values(&self, idx: PointOffsetType) -> Option<Box<dyn Iterator<Item = T> + '_>>;
fn values_count(&self, idx: PointOffsetType) -> Option<usize>;
fn total_unique_values_count(&self) -> OperationResult<usize>;
fn values_range<'a>(
&'a self,
start_bound: Bound<Point<T>>,
end_bound: Bound<Point<T>>,
hw_counter: &'a HardwareCounterCell,
) -> OperationResult<impl Iterator<Item = PointOffsetType> + 'a>;
fn orderable_values_range(
&self,
start_bound: Bound<Point<T>>,
end_bound: Bound<Point<T>>,
) -> OperationResult<impl DoubleEndedIterator<Item = (T, PointOffsetType)> + '_>;
fn values_range_size(
&self,
start_bound: Bound<Point<T>>,
end_bound: Bound<Point<T>>,
hw_counter: &HardwareCounterCell,
) -> OperationResult<usize> {
Ok(self
.values_range(start_bound, end_bound, hw_counter)?
.count())
}
fn get_histogram(&self) -> &Histogram<T>;
fn get_points_count(&self) -> usize;
fn get_max_values_per_point(&self) -> usize;
fn storage_type(&self) -> StorageType;
fn ram_usage_bytes(&self) -> usize;
fn telemetry_index_type(&self) -> &'static str;
fn values_is_empty(&self, idx: PointOffsetType) -> bool {
self.values_count(idx).unwrap_or(0) == 0
}
fn get_telemetry_data(&self) -> PayloadIndexTelemetry {
PayloadIndexTelemetry {
field_name: None,
points_count: self.get_points_count(),
points_values_count: self.get_histogram().get_total_count(),
histogram_bucket_size: Some(self.get_histogram().current_bucket_size()),
index_type: self.telemetry_index_type(),
}
}
}