Skip to main content

Tree

Struct Tree 

Source
pub struct Tree {
    pub program: Pubkey,
    pub creator: Pubkey,
    pub tree_id: u32,
}
Expand description

A handle to one tree: (program, creator, tree_id). All PDA/seed logic lives here.

Fields§

§program: Pubkey§creator: Pubkey§tree_id: u32

Implementations§

Source§

impl Tree

Source

pub fn new(program: Pubkey, creator: Pubkey, tree_id: u32) -> Self

Source

pub fn header_pda(&self) -> (Pubkey, u8)

Source

pub fn alloc_pda(&self) -> (Pubkey, u8)

Source

pub fn node_pda(&self, idx: u64) -> (Pubkey, u8)

Source

pub fn header(&self, r: &dyn AccountReader) -> Option<Header>

Source

pub fn path(&self, r: &dyn AccountReader, key: &[u8; 32]) -> Option<Vec<u64>>

Descent path root..leaf (node_idx list) for key. Empty if the tree is empty. Mirrors the engine’s descent: lower_bound, then “key == separator -> go right”.

Source

pub fn insert_fast_ix( &self, r: &dyn AccountReader, authority: Pubkey, key: &[u8; 32], value: &[u8], ) -> Option<Instruction>

InsertFast: place a new key/value into an existing leaf (fails if the leaf is full -> caller falls back to insert for the cold split path).

Source

pub fn update_fast_ix( &self, r: &dyn AccountReader, authority: Pubkey, key: &[u8; 32], value: &[u8], ) -> Option<Instruction>

UpdateFast: overwrite the value of an existing key in place.

Source

pub fn delete_fast_ix( &self, r: &dyn AccountReader, authority: Pubkey, key: &[u8; 32], ) -> Option<Instruction>

DeleteFast: remove a key without rebalancing (a leaf may drop below MIN).

Source

pub fn find_ix( &self, r: &dyn AccountReader, key: &[u8; 32], ) -> Option<Instruction>

Find: returns the instruction; the caller reads return_data [found u8, value..].

Source

pub fn insert_ix( &self, r: &dyn AccountReader, payer: Pubkey, key: &[u8; 32], value: &[u8], rent_node: u64, ) -> Option<Instruction>

Insert (cold path): handles the empty-tree first insert and splits. Resolves the spare node PDAs (height+2 of them) the engine may need. rent_node = rent-exempt lamports for one node account (caller computes from its client).

Source

pub fn delete_ix( &self, r: &dyn AccountReader, payer: Pubkey, key: &[u8; 32], ) -> Option<Instruction>

Delete (cold path): removes a key and rebalances (borrow/merge), reclaiming rent to payer. Resolves, for each non-root level, which sibling the engine needs (right if our child is not the last, else left) by reading each parent. payer must be the tree authority (Delete is primary-only).

Source

pub fn cold_plan( &self, r: &dyn AccountReader, key: &[u8; 32], ) -> Option<(Vec<u64>, Vec<(Pubkey, u8)>)>

Resolve the cold-path Insert plan for key: the descent path and the spare node PDAs (height+2 of them, with bumps) the engine may consume on a split. Used to build a cold place when InsertFast hits a full leaf (ERR_NEED_SPLIT_SLOT).

Source

pub fn init_tree_ix( &self, payer: Pubkey, value_size: u16, fanout: u16, rent_hdr: u64, rent_alloc: u64, ) -> Instruction

InitTree. rent_hdr/rent_alloc from the caller’s client.

Source

pub fn scan( &self, r: &dyn AccountReader, max: usize, ) -> Vec<([u8; 32], Vec<u8>)>

In-order scan from the smallest key, up to max entries: (key, value) pairs. Walks the forward leaf chain via the AccountReader. For an orderbook this is the book in price-time order (best price first); take(1) = top of book.

Source

pub fn best(&self, r: &dyn AccountReader) -> Option<([u8; 32], Vec<u8>)>

The smallest entry (top of book), or None if empty.

Source

pub fn get(&self, r: &dyn AccountReader, key: &[u8; 32]) -> Option<Vec<u8>>

The value stored at key, or None if absent.

Source

pub fn scan_accounts( &self, r: &dyn AccountReader, max_entries: usize, ) -> Vec<Pubkey>

The header + the leaf account pubkeys a forward scan of up to max_entries would traverse. A K-order match tx references these, so they go in an Address Lookup Table (build the v0 message + ALT with solana-sdk’s address_lookup_table; the ALT program calls are standard Solana, not Torna-specific).

Trait Implementations§

Source§

impl Clone for Tree

Source§

fn clone(&self) -> Tree

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 Copy for Tree

Source§

impl Debug for Tree

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl Freeze for Tree

§

impl RefUnwindSafe for Tree

§

impl Send for Tree

§

impl Sync for Tree

§

impl Unpin for Tree

§

impl UnsafeUnpin for Tree

§

impl UnwindSafe for Tree

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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.

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> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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.
Source§

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

Source§

fn vzip(self) -> V