Address

Struct Address 

Source
pub struct Address {
    pub id: usize,
    pub offset: Offset,
}
Expand description

Item/entry location in a BTreeMap.

Each item in a B-Tree is addressed by a node identifier and an offset in the node. We write @id:offset the address of the item contained in the node id at offset offset.

                                  ┌────────────────┐
                                  │ node 0      ┌──┼─── this item address is `@0:1`
                                  │┌────────┐ ┌─v─┐│
                       ┌───────── ││ item 0 │ │ 1 ││ ──────────┐
                       │          │└────────┘ └───┘│           │
                       │          └────────────────┘           │
                       │                   │                   │
              ┌─────────────────┐ ┌─────────────────┐ ┌─────────────────┐
              │ node 1          │ │ node 2          │ │ node 3          │
              │┌───┐ ┌───┐ ┌───┐│ │┌───┐ ┌───┐ ┌───┐│ │┌───┐ ┌───┐ ┌───┐│
              ││ 0 │ │ 1 │ │ 2 ││ ││ 0 │ │ 1 │ │ 2 ││ ││ 0 │ │ 1 │ │ 2 ││
              │└─^─┘ └───┘ └───┘│ │└───┘ └───┘ └─^─┘│ │└───┘ └───┘ └───┘│
              └──┼──────────────┘ └──────────────┼──┘ └─────────────────┘
                 └─ this item address is `@1:0`  └─ this item address is `@2:2`

§Validity

An item adress addr is valid in a given BTreeMap if it addr.id refers to an existing node and if addr.offset is comprised between -1 and the number of items in the node (included). We say that addr is occupied if it points to an actual item (addr.offset at least 0 and less than the number of items in the node).

The following diagram shows all the valid address in a B-Tree.

                                            ┌───────────┐
                                            │ node 0    │
                                       ┌───┐│┌───┐ ┌───┐│┌───┐
                  ┌────────────────────│-1 │││ 0 │ │ 1 │││ 2 │─────────────────┐
                  │                    └───┘│└───┘ └───┘│└───┘                 │
                  │                         └───────────┘                      │
                  │                               │                            │
         ┌─────────────────┐             ┌─────────────────┐             ┌───────────┐
         │ node 1          │             │ node 2          │             │ node 3    │    
    ┌───┐│┌───┐ ┌───┐ ┌───┐│┌───┐   ┌───┐│┌───┐ ┌───┐ ┌───┐│┌───┐   ┌───┐│┌───┐ ┌───┐│┌───┐
    │-1 │││ 0 │ │ 1 │ │ 2 │││ 3 │   │-1 │││ 0 │ │ 1 │ │ 2 │││ 3 │   │-1 │││ 0 │ │ 1 │││ 2 │
    └───┘│└───┘ └───┘ └───┘│└───┘   └───┘│└───┘ └───┘ └───┘│└───┘   └───┘│└───┘ └───┘│└───┘
         └─────────────────┘             └─────────────────┘             └───────────┘

Note how some valid addresses are outside of nodes bounds. Even is thoses addresses do not refers to any items, they can be useful to operate on the tree.

§Back addresses

A “back address” is a valid address whose offset is at least 0. If addr.offset is equal to the number of items in the node then it doesn’t actually refer to an existing item in the node, but it can be used to insert a new item with BTreeExt::insert_at.

The following diagram shows all the back addresses in a node.

                       ┌───────────┄┄┄┄┄───────┐      
                       │ node i                │       
                       │┌───┐ ┌───┐     ┌─────┐│┌───┐  where `n` is
                       ││ 0 │ │ 1 │ ... │ n-1 │││ n │  the number of items in the node.
                       │└───┘ └───┘     └─────┘│└───┘  
                       └───────────┄┄┄┄┄───────┘   

Note that an address with offset -1 is not a back address.

§Front addresses

A “front address” is a valid address whose offset is less that the number of items in the node. If addr.offset is equal to -1, then it doesn’t actually refer to an existing item in the node.

The following diagram shows all the front addresses in a node.

                            ┌───────────┄┄┄┄┄───────┐      
                            │ node i                │       
                       ┌───┐│┌───┐ ┌───┐     ┌─────┐│  where `n` is
                       │-1 │││ 0 │ │ 1 │ ... │ n-1 ││  the number of items in the node.
                       └───┘│└───┘ └───┘     └─────┘│  
                            └───────────┄┄┄┄┄───────┘   

Note that an address with offset n is not a front address.

§Safety

It is not safe to use an address addr in which addr.id is not the identifier of any node currently used by the tree.

Fields§

§id: usize

Identifier of the node.

§offset: Offset

Offset in the node.

Implementations§

Source§

impl Address

Source

pub fn new(id: usize, offset: Offset) -> Address

Creates a new address from the identifier of the node and the offset in the node.

Source

pub fn nowhere() -> Address

Address in the empty tree.

This is the unique valid address address in an ampty tree. It is only valid in the empty tree.

Source

pub fn is_nowhere(&self) -> bool

Checks if the address is nowhere.

Trait Implementations§

Source§

impl Clone for Address

Source§

fn clone(&self) -> Address

Returns a duplicate 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 Debug for Address

Source§

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

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

impl Display for Address

Source§

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

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

impl PartialEq for Address

Source§

fn eq(&self, other: &Address) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Copy for Address

Source§

impl Eq for Address

Source§

impl StructuralPartialEq for Address

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

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> 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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. 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.