Struct ax_banyan::Forest

source ·
pub struct Forest<TT: TreeTypes, R>(/* private fields */);

Implementations§

source§

impl<T, R> Forest<T, R>
where T: TreeTypes, R: ReadOnlyStore<T::Link>,

basic random access append only tree

source

pub fn store(&self) -> &R

source§

impl<T: TreeTypes, R: ReadOnlyStore<T::Link>> Forest<T, R>

source

pub fn stream_trees<Q, S, V>( &self, query: Q, trees: S ) -> impl Stream<Item = Result<(u64, T::Key, V)>> + Send
where Q: Query<T> + Clone, S: Stream<Item = Tree<T, V>> + Send + 'static, V: BanyanValue,

Given a sequence of roots, will stream matching events in ascending order indefinitely.

This is implemented by calling stream_trees_chunked and just flattening the chunks.

source

pub fn stream_trees_chunked<S, Q, V, E, F>( &self, query: Q, trees: S, range: RangeInclusive<u64>, mk_extra: &'static F ) -> impl Stream<Item = Result<FilteredChunk<(u64, T::Key, V), E>>> + Send + 'static
where S: Stream<Item = Tree<T, V>> + Send + 'static, Q: Query<T> + Clone, V: BanyanValue, E: Send + 'static, F: Send + Sync + 'static + Fn(&NodeInfo<T, R>) -> E,

Given a sequence of roots, will stream chunks in ascending order until it arrives at range.end().

  • query: the query
  • roots: the stream of roots. It is assumed that trees later in this stream will be bigger
  • range: the range which to stream. It is up to the caller to ensure that we have events for this range.
  • mk_extra: a fn that allows to compute extra info from indices. this can be useful to get progress info even if the query does not match any events
source

pub fn stream_trees_chunked_threaded<S, Q, V, E, F>( &self, query: Q, trees: S, range: RangeInclusive<u64>, mk_extra: &'static F, thread_pool: ThreadPool ) -> impl Stream<Item = Result<FilteredChunk<(u64, T::Key, V), E>>> + Send + 'static
where S: Stream<Item = Tree<T, V>> + Send + 'static, Q: Query<T> + Clone, V: BanyanValue, E: Send + 'static, F: Send + Sync + 'static + Fn(&NodeInfo<T, R>) -> E,

Given a sequence of roots, will stream chunks in ascending order indefinitely.

Note that this method has no way to know when the query is done. So ending this stream, if desired, will have to be done by the caller using e.g. take_while(...).

  • query: the query
  • roots: the stream of roots. It is assumed that trees later in this stream will be bigger
  • range: the range which to stream. It is up to the caller to ensure that we have events for this range.
  • mk_extra: a fn that allows to compute extra info from indices. this can be useful to get progress info even if the query does not match any events
source

pub fn stream_trees_chunked_reverse<S, Q, V, E, F>( &self, query: Q, trees: S, range: RangeInclusive<u64>, mk_extra: &'static F ) -> impl Stream<Item = Result<FilteredChunk<(u64, T::Key, V), E>>> + Send + 'static
where S: Stream<Item = Tree<T, V>> + Send + 'static, Q: Query<T> + Clone, V: BanyanValue, E: Send + 'static, F: Send + Sync + 'static + Fn(&NodeInfo<T, R>) -> E,

Given a sequence of roots, will stream chunks in reverse order until it arrives at range.start().

Values within chunks are in ascending offset order, so if you flatten them you have to reverse them first.

  • query: the query
  • trees: the stream of roots. It is assumed that trees later in this stream will be bigger
  • range: the range which to stream. It is up to the caller to ensure that we have events for this range.
  • mk_extra: a fn that allows to compute extra info from indices. this can be useful to get progress info even if the query does not match any events
source§

impl<TT: TreeTypes, R: Clone> Forest<TT, R>

source

pub fn new(store: R, branch_cache: BranchCache<TT>) -> Self

source

pub fn transaction<W: BlockWriter<TT::Link>>( &self, f: impl FnOnce(R) -> (R, W) ) -> Transaction<TT, R, W>

source§

impl<T: TreeTypes, R: ReadOnlyStore<T::Link>> Forest<T, R>

source

pub fn load_stream_builder<V>( &self, secrets: Secrets, config: Config, link: T::Link ) -> Result<StreamBuilder<T, V>>

source

pub fn load_tree<V>( &self, secrets: Secrets, link: T::Link ) -> Result<Tree<T, V>>

source

pub fn dump<V>(&self, tree: &Tree<T, V>) -> Result<()>

dumps the tree structure

source

pub fn dump_graph<S, V>( &self, tree: &Tree<T, V>, f: impl Fn((usize, &NodeInfo<T, R>)) -> S + Clone ) -> Result<(Vec<(usize, usize)>, BTreeMap<usize, S>)>

dumps the tree structure

source

pub fn roots<V>(&self, tree: &StreamBuilder<T, V>) -> Result<Vec<Index<T>>>

sealed roots of the tree

source

pub fn left_roots<V>(&self, tree: &Tree<T, V>) -> Result<Vec<Tree<T, V>>>

leftmost branches of the tree as separate trees

source

pub fn check_invariants<V>( &self, tree: &StreamBuilder<T, V> ) -> Result<Vec<String>>

source

pub fn is_packed<V>(&self, tree: &Tree<T, V>) -> Result<bool>

source

pub fn assert_invariants<V>(&self, tree: &StreamBuilder<T, V>) -> Result<()>

source

pub fn stream_filtered<V: BanyanValue>( &self, tree: &Tree<T, V>, query: impl Query<T> + Clone + 'static ) -> impl Stream<Item = Result<(u64, T::Key, V)>> + 'static

source

pub fn iter_index<V>( &self, tree: &Tree<T, V>, query: impl Query<T> + Clone + 'static ) -> impl Iterator<Item = Result<Index<T>>> + 'static

Returns an iterator yielding all indexes that have values matching the provided query.

source

pub fn iter_index_reverse<V>( &self, tree: &Tree<T, V>, query: impl Query<T> + Clone + 'static ) -> impl Iterator<Item = Result<Index<T>>> + 'static

Returns an iterator yielding all indexes that have values matching the provided query in reverse order.

source

pub fn iter_filtered<V: BanyanValue>( &self, tree: &Tree<T, V>, query: impl Query<T> + Clone + 'static ) -> impl Iterator<Item = Result<(u64, T::Key, V)>> + 'static

source

pub fn iter_filtered_reverse<V: BanyanValue>( &self, tree: &Tree<T, V>, query: impl Query<T> + Clone + 'static ) -> impl Iterator<Item = Result<(u64, T::Key, V)>> + 'static

source

pub fn iter_from<V: BanyanValue>( &self, tree: &Tree<T, V> ) -> impl Iterator<Item = Result<(u64, T::Key, V)>> + 'static

source

pub fn iter_filtered_chunked<Q, V, E, F>( &self, tree: &Tree<T, V>, query: Q, mk_extra: &'static F ) -> impl Iterator<Item = Result<FilteredChunk<(u64, T::Key, V), E>>> + 'static
where Q: Query<T>, V: BanyanValue, E: Send + 'static, F: Fn(&NodeInfo<T, R>) -> E + Send + Sync + 'static,

source

pub fn iter_filtered_chunked_reverse<Q, V, E, F>( &self, tree: &Tree<T, V>, query: Q, mk_extra: &'static F ) -> impl Iterator<Item = Result<FilteredChunk<(u64, T::Key, V), E>>> + 'static
where Q: Query<T>, V: BanyanValue, E: Send + 'static, F: Fn(&NodeInfo<T, R>) -> E + Send + Sync + 'static,

source

pub fn stream_filtered_chunked<Q, V, E, F>( &self, tree: &Tree<T, V>, query: Q, mk_extra: &'static F ) -> impl Stream<Item = Result<FilteredChunk<(u64, T::Key, V), E>>> + 'static
where Q: Query<T>, V: BanyanValue, E: Send + 'static, F: Fn(&NodeInfo<T, R>) -> E + Send + Sync + 'static,

source

pub fn stream_filtered_chunked_reverse<Q, V, E, F>( &self, tree: &Tree<T, V>, query: Q, mk_extra: &'static F ) -> impl Stream<Item = Result<FilteredChunk<(u64, T::Key, V), E>>> + 'static
where Q: Query<T>, V: BanyanValue, E: Send + 'static, F: Fn(&NodeInfo<T, R>) -> E + Send + Sync + 'static,

source

pub fn get<V: BanyanValue>( &self, tree: &Tree<T, V>, offset: u64 ) -> Result<Option<(T::Key, V)>>

element at index

returns Ok(None) when offset is larger than count, or when hitting a purged part of the tree. Returns an error when part of the tree should be there, but could not be read.

source

pub fn collect<V: BanyanValue>( &self, tree: &Tree<T, V> ) -> Result<Vec<Option<(T::Key, V)>>>

Collects all elements from a stream. Might produce an OOM for large streams.

source

pub fn collect_from<V: BanyanValue>( &self, tree: &Tree<T, V>, offset: u64 ) -> Result<Vec<Option<(T::Key, V)>>>

Collects all elements from the given offset. Might produce an OOM for large streams.

Trait Implementations§

source§

impl<TT: TreeTypes, R> Clone for Forest<TT, R>

source§

fn clone(&self) -> Self

Returns a copy of the value. Read more
1.0.0 · source§

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

Performs copy-assignment from source. Read more
source§

impl<TT: Debug + TreeTypes, R: Debug> Debug for Forest<TT, R>

source§

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

Formats the value using the given formatter. Read more
source§

impl<T: TreeTypes, R> Deref for Forest<T, R>

§

type Target = ForestInner<T, R>

The resulting type after dereferencing.
source§

fn deref(&self) -> &Self::Target

Dereferences the value.

Auto Trait Implementations§

§

impl<TT, R> !RefUnwindSafe for Forest<TT, R>

§

impl<TT, R> Send for Forest<TT, R>
where R: Send + Sync,

§

impl<TT, R> Sync for Forest<TT, R>
where R: Send + Sync,

§

impl<TT, R> Unpin for Forest<TT, R>

§

impl<TT, R> !UnwindSafe for Forest<TT, R>

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> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T> Instrument for T

source§

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

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

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> References<RawCodec> for T

§

fn references<R, E>(_c: RawCodec, _r: &mut R, _set: &mut E) -> Result<(), Error>
where R: Read, E: Extend<Cid<64>>,

Scrape the references from an impl Read. Read more
source§

impl<T> Same for T

§

type Output = T

Should always be Self
source§

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

§

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>,

§

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>,

§

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.
source§

impl<T> WithSubscriber for T

source§

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
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

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