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
impl SearchTree
pub fn new() -> Self
pub fn len(&self) -> usize
pub fn is_empty(&self) -> bool
Sourcepub fn insert(&mut self, key: FeerateTransactionKey) -> bool
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.
Sourcepub fn remove(&mut self, key: &FeerateTransactionKey) -> bool
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.
Sourcepub fn search(&self, query: f64) -> &FeerateTransactionKey
pub fn search(&self, query: f64) -> &FeerateTransactionKey
Search for a weight point query ∈ [0, total_weight)
in log(n) time
Sourcepub fn total_weight(&self) -> f64
pub fn total_weight(&self) -> f64
Access the total weight in O(1) time
Sourcepub fn prefix_weight(&self, key: &FeerateTransactionKey) -> f64
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
Sourcepub fn descending_iter(
&self,
) -> impl DoubleEndedIterator<Item = &FeerateTransactionKey> + ExactSizeIterator + FusedIterator
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.
Sourcepub fn ascending_iter(
&self,
) -> impl DoubleEndedIterator<Item = &FeerateTransactionKey> + ExactSizeIterator + FusedIterator
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.
Sourcepub fn first(&self) -> Option<&FeerateTransactionKey>
pub fn first(&self) -> Option<&FeerateTransactionKey>
The lowest key in the tree (by key order)
Sourcepub fn last(&self) -> Option<&FeerateTransactionKey>
pub fn last(&self) -> Option<&FeerateTransactionKey>
The highest key in the tree (by key order)
Trait Implementations§
Auto Trait Implementations§
impl !Freeze for SearchTree
impl RefUnwindSafe for SearchTree
impl Send for SearchTree
impl Sync for SearchTree
impl Unpin for SearchTree
impl UnwindSafe for SearchTree
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<S> CastArc for Swhere
S: CastFromSync + ?Sized,
impl<S> CastArc for Swhere
S: CastFromSync + ?Sized,
Source§impl<T> CastFrom for Twhere
T: Any + 'static,
impl<T> CastFrom for Twhere
T: Any + 'static,
Source§fn ref_any(&self) -> &(dyn Any + 'static)
fn ref_any(&self) -> &(dyn Any + 'static)
Any
, which is backed by the type implementing this trait.Source§fn mut_any(&mut self) -> &mut (dyn Any + 'static)
fn mut_any(&mut self) -> &mut (dyn Any + 'static)
Any
, which is backed by the type implementing this trait.Source§impl<T> CastFromSync for T
impl<T> CastFromSync for T
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