Skip to main content

SearchTree

Struct SearchTree 

Source
pub struct SearchTree { /* private fields */ }
Expand description

A transaction search tree sorted by feerate order and searchable for probabilistic weighted sampling.

All log(n) expressions below are in base 64 (based on constants chosen within the sweep_bptree crate).

The tree has the following properties: 1. Linear time ordered access (ascending / descending) 2. Insertions/removals in log(n) time 3. Search for a weight point p ∈ [0, total_weight) in log(n) time 4. Compute the prefix weight of a key, i.e., the sum of weights up to that key (inclusive) according to key order, in log(n) time 5. Access the total weight in O(1) time. The total weight has numerical stability since it is recomputed from subtree weights for each item insertion/removal

Computing the prefix weight is a crucial operation if the tree is used for random sampling and the tree is highly imbalanced in terms of weight variance. See Frontier::sample_inplace() for more details.

Implementations§

Source§

impl SearchTree

Source

pub fn new() -> Self

Source

pub fn len(&self) -> usize

Source

pub fn is_empty(&self) -> bool

Source

pub fn insert(&mut self, key: FeerateTransactionKey) -> bool

Inserts a key into the tree in log(n) time. Returns false if the key was already in the tree.

Source

pub fn remove(&mut self, key: &FeerateTransactionKey) -> bool

Remove a key from the tree in log(n) time. Returns false if the key was not in the tree.

Source

pub fn search(&self, query: f64) -> &FeerateTransactionKey

Search for a weight point query ∈ [0, total_weight) in log(n) time

Source

pub fn remove_by_query(&mut self, query: f64) -> FeerateTransactionKey

Remove the key located by a weight point query ∈ [0, total_weight) in log(n) time.

Source

pub fn total_weight(&self) -> f64

Access the total weight in O(1) time

Source

pub fn prefix_weight(&self, key: &FeerateTransactionKey) -> f64

Computes the prefix weight of a key, i.e., the sum of weights up to that key (inclusive) according to key order, in log(n) time

Source

pub fn descending_iter( &self, ) -> impl DoubleEndedIterator<Item = &FeerateTransactionKey> + ExactSizeIterator + FusedIterator

Iterate the tree in descending key order (going down from the highest key). Linear in the number of keys actually iterated.

Source

pub fn ascending_iter( &self, ) -> impl DoubleEndedIterator<Item = &FeerateTransactionKey> + ExactSizeIterator + FusedIterator

Iterate the tree in ascending key order (going up from the lowest key). Linear in the number of keys actually iterated.

Source

pub fn first(&self) -> Option<&FeerateTransactionKey>

The lowest key in the tree (by key order)

Source

pub fn last(&self) -> Option<&FeerateTransactionKey>

The highest key in the tree (by key order)

Trait Implementations§

Source§

impl Clone for SearchTree

Source§

fn clone(&self) -> Self

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 Default for SearchTree

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

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> Any for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Source§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Source§

fn type_name(&self) -> &'static str

Source§

impl<T> AnySync for T
where T: Any + Send + Sync,

Source§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Sync + Send> ⓘ

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> CloneAny for T
where T: Any + Clone + Send + Sync,

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, U> ExactFrom<T> for U
where U: TryFrom<T>,

Source§

fn exact_from(value: T) -> U

Source§

impl<T, U> ExactInto<U> for T
where U: ExactFrom<T>,

Source§

fn exact_into(self) -> U

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.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T, U> OverflowingInto<U> for T
where U: OverflowingFrom<T>,

Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T, U> RoundingInto<U> for T
where U: RoundingFrom<T>,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> SaturatingInto<U> for T
where U: SaturatingFrom<T>,

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 = !

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

fn try_from(value: U) -> Result<T, !>

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

impl<T> UnsafeAny for T
where T: Any,

Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

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

impl<T, U> WrappingInto<U> for T
where U: WrappingFrom<T>,

Source§

fn wrapping_into(self) -> U