Skip to main content

Stree

Struct Stree 

Source
pub struct Stree<K: Key> { /* private fields */ }
Expand description

S-Tree

Implementations§

Source§

impl<K: Key> Stree<K>

Source

pub const DEFAULT_NODE_SIZE: u16 = 16

Source

pub const DEFAULT_PAYLOAD_PREFETCH_SIZE: usize

Default size for prefetching payload data (1MB)

Source

pub fn compute_payload_prefetch_size( num_items: usize, estimated_avg_payload_size: Option<usize>, prefetch_factor: Option<f32>, ) -> usize

Compute the optimal payload prefetch size based on tree characteristics.

This method estimates the appropriate size to prefetch from the payload section. It takes into account the number of items in the tree and adapts the prefetch size to balance between memory usage and HTTP request reduction.

§Arguments
  • num_items - Number of items in the tree
  • estimated_avg_payload_size - Estimated average size of each payload entry (default: 64 bytes)
  • prefetch_factor - Adjustment factor for the prefetch size (default: 1.0)
§Returns

The recommended payload prefetch size in bytes

Source

pub fn build(nodes: &[NodeItem<K>], branching_factor: u16) -> Result<Stree<K>>

Source

pub fn from_buf( data: impl Read, num_items: usize, branching_factor: u16, ) -> Result<Stree<K>>

Source

pub async fn from_http<T: AsyncHttpRangeClient>( client: &mut AsyncBufferedHttpRangeClient<T>, index_begin: usize, num_items: usize, node_size: u16, ) -> Result<Stree<K>>

Source

pub fn find_exact(&self, key: K) -> Result<Vec<SearchResultItem>>

Source

pub fn stream_find_exact<R: Read + Seek + ?Sized>( data: &mut R, num_items: usize, branching_factor: u16, key: K, ) -> Result<Vec<SearchResultItem>>

Source

pub fn find_range(&self, lower: K, upper: K) -> Result<Vec<SearchResultItem>>

Finds all items with keys in the specified range [lower, upper]

This implementation uses a partition-based approach for efficient range searches:

  1. Find partition points for both the lower and upper bounds
  2. Process only the relevant leaf nodes between these partition points
  3. Filter items within those leaf nodes by the actual range bounds

Special cases:

  • If lower > upper, returns an empty result (invalid range)
  • If lower == upper, delegates to find_exact for consistent behavior
Source

pub fn find_range_strict( &self, lower: K, lower_strict: bool, upper: K, upper_strict: bool, ) -> Result<Vec<SearchResultItem>>

Finds all items whose key lies within the range, with each bound independently strict (exclusive) or inclusive.

This is what Gt/Lt/Ne lower to. They must NOT be expressed as an inclusive range minus find_exact: the subtraction removes FEATURE OFFSETS, but a feature’s CityObjects can carry several values of the same indexed attribute and the writer indexes each occurrence, so one feature offset appears under several keys. A feature holding both k and some k' > k is returned by the range scan (via k') and also by find_exact(k) (via k), so subtracting deletes a genuine match. Filtering by bound strictness at the leaf cannot make that mistake, and costs one traversal instead of two.

Source

pub fn stream_find_range<R: Read + Seek + ?Sized>( data: &mut R, num_items: usize, branching_factor: u16, lower: K, upper: K, ) -> Result<Vec<SearchResultItem>>

Source

pub fn stream_find_range_strict<R: Read + Seek + ?Sized>( data: &mut R, num_items: usize, branching_factor: u16, lower: K, lower_strict: bool, upper: K, upper_strict: bool, ) -> Result<Vec<SearchResultItem>>

Streaming counterpart of Stree::find_range_strict: each bound is independently strict (exclusive) or inclusive, so Gt/Lt/Ne need no unsound subtraction on feature offsets.

Source

pub fn find_partition(&self, key: K) -> Result<usize>

Finds the partition point for a key in the tree Returns the index in the leaf level where the key would be inserted

This is a key function that powers efficient range searches by finding the exact location where a key would be inserted in the leaf level. For range queries, we use this function to find the start and end points in the leaf level for a given range, then scan through just those leaf nodes.

Source

pub fn stream_find_partition<R: Read + Seek + ?Sized>( data: &mut R, num_items: usize, branching_factor: u16, key: K, ) -> Result<usize>

Source

pub async fn http_stream_find_exact<T: AsyncHttpRangeClient>( client: &mut AsyncBufferedHttpRangeClient<T>, index_begin: usize, feature_begin: usize, num_items: usize, branching_factor: u16, key: K, combine_request_threshold: usize, ) -> Result<Vec<HttpSearchResultItem>>

Source

pub async fn http_stream_find_partition<T: AsyncHttpRangeClient>( client: &mut AsyncBufferedHttpRangeClient<T>, index_begin: usize, num_items: usize, branching_factor: u16, key: K, _combine_request_threshold: usize, ) -> Result<usize>

Source

pub fn tree_size(num_items: usize) -> usize

Source

pub fn estimate_payload_section_size( num_items: usize, duplicate_percentage: Option<f32>, avg_duplicates_per_key: Option<f32>, ) -> usize

Estimate the total size of the payload section based on tree characteristics.

This method provides an estimate of how large the payload section might be based on the number of items in the tree and an estimated percentage of items with duplicate keys.

§Arguments
  • num_items - Number of items in the tree
  • duplicate_percentage - Estimated percentage of items with duplicate keys (0.0-1.0)
  • avg_duplicates_per_key - Average number of duplicates per duplicate key
§Returns

The estimated size of the payload section in bytes

Source

pub fn index_size( num_items: usize, branching_factor: u16, payload_size: usize, ) -> usize

Source

pub fn payload_size(&self) -> usize

Source

pub fn num_leaf_items(&self) -> usize

Source

pub fn num_items(&self) -> usize

Source

pub fn branching_factor(&self) -> u16

Source

pub fn stream_write<W: Write>(&self, out: &mut W) -> Result<usize>

Write all index nodes and any payload data

Source

pub async fn http_stream_find_range<T: AsyncHttpRangeClient>( client: &mut AsyncBufferedHttpRangeClient<T>, index_begin: usize, feature_begin: usize, num_items: usize, branching_factor: u16, lower: K, upper: K, combine_request_threshold: usize, ) -> Result<Vec<HttpSearchResultItem>>

Source

pub async fn http_stream_find_range_strict<T: AsyncHttpRangeClient>( client: &mut AsyncBufferedHttpRangeClient<T>, index_begin: usize, feature_begin: usize, num_items: usize, branching_factor: u16, lower: K, lower_strict: bool, upper: K, upper_strict: bool, combine_request_threshold: usize, ) -> Result<Vec<HttpSearchResultItem>>

HTTP counterpart of Stree::find_range_strict: each bound is independently strict (exclusive) or inclusive, so Gt/Lt/Ne need no unsound subtraction on feature offsets.

Trait Implementations§

Source§

impl<K: Clone + Key> Clone for Stree<K>

Source§

fn clone(&self) -> Stree<K>

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<K: Debug + Key> Debug for Stree<K>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<K> Freeze for Stree<K>

§

impl<K> RefUnwindSafe for Stree<K>
where K: RefUnwindSafe,

§

impl<K> Send for Stree<K>
where K: Send,

§

impl<K> Sync for Stree<K>
where K: Sync,

§

impl<K> Unpin for Stree<K>
where K: Unpin,

§

impl<K> UnsafeUnpin for Stree<K>

§

impl<K> UnwindSafe for Stree<K>
where K: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

§

impl<T> PolicyExt for T
where T: ?Sized,

§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] only if self and other return Action::Follow. Read more
§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] if either self or other returns Action::Follow. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

impl<A, B, T> HttpServerConnExec<A, B> for T
where B: Body,