Struct ContentTreeRaw

Source
pub struct ContentTreeRaw<E: ContentTraits, I: TreeMetrics<E>, const INT_ENTRIES: usize = DEFAULT_IE, const LEAF_ENTRIES: usize = DEFAULT_LE> { /* private fields */ }
Expand description

A ContentTree is an efficient packed list of RLE entries, allowing for arbitrary inserts and deletes anywhere in the range.

use content_tree::ContentTree;
use content_tree::testrange::TestRange;

let mut tree = ContentTree::new();
tree.push(TestRange { id: 0, len: 100, is_activated: true });
tree.push(TestRange { id: 100, len: 50, is_activated: true });

assert_eq!(tree.iter().collect::<Vec<TestRange>>(), vec![
    TestRange { id: 0, len: 150, is_activated: true }
]);

Implementations§

Source§

impl<E: ContentTraits, I: TreeMetrics<E>, const IE: usize, const LE: usize> ContentTreeRaw<E, I, IE, LE>

Source

pub fn new() -> Pin<Box<Self>>

Source

pub fn len(&self) -> I::Value

Source

pub fn unsafe_cursor_at_query<F, G>( &self, raw_pos: usize, stick_end: bool, offset_to_num: F, entry_to_num: G, ) -> UnsafeCursor<E, I, IE, LE>
where F: Fn(I::Value) -> usize, G: Fn(E) -> usize,

WARNING: This method doesn’t actually figure out the cursor position at the item. The offset stored in the cursor contains the final offset. For cursor_at_offset this will be correct, or any time the content size corresponds to offset size.

Source

pub fn unsafe_cursor_at_start(&self) -> UnsafeCursor<E, I, IE, LE>

Source

pub fn unsafe_cursor_at_end(&self) -> UnsafeCursor<E, I, IE, LE>

Source

pub fn next_entry_or_panic( cursor: &mut UnsafeCursor<E, I, IE, LE>, marker: &mut I::Update, )

Source

pub fn check(&self)

Source

pub fn print_ptr_tree(&self)

Source

pub fn print_stats(&self, name: &str, detailed: bool)

Source

pub fn count_entries(&self) -> usize

Source

pub fn count_nodes(&self) -> (usize, usize)

Source

pub fn count_total_memory(&self) -> usize

Source§

impl<E: ContentTraits + Searchable, I: TreeMetrics<E>, const IE: usize, const LE: usize> ContentTreeRaw<E, I, IE, LE>

Source

pub unsafe fn unsafe_cursor_before_item( loc: E::Item, ptr: NonNull<NodeLeaf<E, I, IE, LE>>, ) -> UnsafeCursor<E, I, IE, LE>

Returns a cursor right before the named location, referenced by the pointer.

Source

pub fn cursor_before_item( &self, loc: E::Item, ptr: NonNull<NodeLeaf<E, I, IE, LE>>, ) -> Cursor<'_, E, I, IE, LE>

Source

pub fn mut_cursor_before_item<'a>( self: &'a mut Pin<Box<Self>>, loc: E::Item, ptr: NonNull<NodeLeaf<E, I, IE, LE>>, ) -> MutCursor<'a, E, I, IE, LE>

Source§

impl<E: ContentTraits + ContentLength, I: FindContent<E>, const IE: usize, const LE: usize> ContentTreeRaw<E, I, IE, LE>

Source

pub fn content_len(&self) -> usize

Source

pub fn unsafe_cursor_at_content_pos( &self, pos: usize, stick_end: bool, ) -> UnsafeCursor<E, I, IE, LE>

Source

pub fn cursor_at_content_pos( &self, pos: usize, stick_end: bool, ) -> Cursor<'_, E, I, IE, LE>

Source

pub fn mut_cursor_at_content_pos<'a>( self: &'a mut Pin<Box<Self>>, pos: usize, stick_end: bool, ) -> MutCursor<'a, E, I, IE, LE>

Source§

impl<E: ContentTraits, I: FindOffset<E>, const IE: usize, const LE: usize> ContentTreeRaw<E, I, IE, LE>

Source

pub fn offset_len(&self) -> usize

Source

pub fn unsafe_cursor_at_offset_pos( &self, pos: usize, stick_end: bool, ) -> UnsafeCursor<E, I, IE, LE>

Source

pub fn cursor_at_offset_pos( &self, pos: usize, stick_end: bool, ) -> Cursor<'_, E, I, IE, LE>

Source

pub fn mut_cursor_at_offset_pos<'a>( self: &'a mut Pin<Box<Self>>, pos: usize, stick_end: bool, ) -> MutCursor<'a, E, I, IE, LE>

Source§

impl<E: ContentTraits + Searchable, I: FindOffset<E>, const IE: usize, const LE: usize> ContentTreeRaw<E, I, IE, LE>

Source

pub fn at_offset(&self, pos: usize) -> Option<E::Item>

Source§

impl<E: ContentTraits + ContentLength + Searchable, I: FindContent<E>, const IE: usize, const LE: usize> ContentTreeRaw<E, I, IE, LE>

Source

pub fn at_content(&self, pos: usize) -> Option<E::Item>

Source§

impl<E: ContentTraits, I: TreeMetrics<E>, const IE: usize, const LE: usize> ContentTreeRaw<E, I, IE, LE>

This file contains the core code for content-tree’s mutation operations.

Source

pub unsafe fn unsafe_insert_notify<F>( cursor: &mut UnsafeCursor<E, I, IE, LE>, new_entry: E, notify: F, )
where F: FnMut(E, NonNull<NodeLeaf<E, I, IE, LE>>),

Source

pub fn insert_at_start_notify<F>( self: &mut Pin<Box<Self>>, new_entry: E, notify: F, )
where F: FnMut(E, NonNull<NodeLeaf<E, I, IE, LE>>),

Source

pub fn insert_at_start(self: &mut Pin<Box<Self>>, new_entry: E)

Source

pub fn push_notify<F>(self: &mut Pin<Box<Self>>, new_entry: E, notify: F)
where F: FnMut(E, NonNull<NodeLeaf<E, I, IE, LE>>),

Source

pub fn push(self: &mut Pin<Box<Self>>, new_entry: E)

Push a new entry to the end of the tree. The new entry will be merged with the existing last entry if possible.

Source

pub unsafe fn unsafe_replace_entry_notify<N>( cursor: &mut UnsafeCursor<E, I, IE, LE>, items: &[E], notify: N, )
where N: FnMut(E, NonNull<NodeLeaf<E, I, IE, LE>>),

Replace the current entry with the items passed via items[]. Items.len must be <= 3. The cursor offset is ignored. This is a fancy method - use sparingly.

Source

pub unsafe fn unsafe_replace_entry_simple_notify<N>( cursor: &mut UnsafeCursor<E, I, IE, LE>, new_item: E, notify: N, )
where N: FnMut(E, NonNull<NodeLeaf<E, I, IE, LE>>),

Source

pub unsafe fn unsafe_mutate_single_entry_notify<MapFn, R, N>( map_fn: MapFn, cursor: &mut UnsafeCursor<E, I, IE, LE>, replace_max: usize, notify: N, ) -> (usize, R)
where N: FnMut(E, NonNull<NodeLeaf<E, I, IE, LE>>), MapFn: FnOnce(&mut E) -> R,

Source

pub unsafe fn unsafe_mutate_entries_notify<MapFn, N>( map_fn: MapFn, cursor: &mut UnsafeCursor<E, I, IE, LE>, replace_len: usize, notify: N, )
where N: FnMut(E, NonNull<NodeLeaf<E, I, IE, LE>>), MapFn: Fn(&mut E),

Source

pub unsafe fn unsafe_replace_range_notify<N>( cursor: &mut UnsafeCursor<E, I, IE, LE>, new_entry: E, notify: N, )
where N: FnMut(E, NonNull<NodeLeaf<E, I, IE, LE>>),

Replace the range from cursor..cursor + replaced_len with new_entry.

Source

pub unsafe fn unsafe_delete_notify<F>( cursor: &mut UnsafeCursor<E, I, IE, LE>, del_items: usize, notify: F, )
where F: FnMut(E, NonNull<NodeLeaf<E, I, IE, LE>>),

Delete the specified number of items from the b-tree at the cursor. Cursor may be modified to point to the start of the next item.

Source

pub fn delete_at_start_notify<F>( self: &mut Pin<Box<Self>>, del_items: usize, notify: F, )
where F: FnMut(E, NonNull<NodeLeaf<E, I, IE, LE>>),

Source

pub fn delete_at_start(self: &mut Pin<Box<Self>>, del_items: usize)

Source§

impl<E: ContentTraits + Toggleable, I: TreeMetrics<E>, const IE: usize, const LE: usize> ContentTreeRaw<E, I, IE, LE>

Source

pub unsafe fn local_deactivate_notify<F>( self: &mut Pin<Box<Self>>, cursor: UnsafeCursor<E, I, IE, LE>, deleted_len: usize, notify: F, ) -> DeleteResult<E>
where F: FnMut(E, NonNull<NodeLeaf<E, I, IE, LE>>),

Source

pub unsafe fn unsafe_remote_deactivate_notify<F>( cursor: &mut UnsafeCursor<E, I, IE, LE>, max_deleted_len: usize, notify: F, ) -> (usize, bool)
where F: FnMut(E, NonNull<NodeLeaf<E, I, IE, LE>>),

Deactivate up to max_deleted_len from the marker tree, at the location specified by cursor. We will always process at least one item. Consumers of this API should call this in a loop.

If the entry is already marked as deleted, unlike local_deactivate, this method does nothing. local_deactivate will skip over deleted items and delete something else.

Returns the number of items we tried to deactivate, and whether we were successful. (eg (1, true) means we marked 1 item for deletion. (2, false) means we skipped past 2 items which were already deactivated.

TODO: It might be cleaner to make the caller check for deleted items if we return 0.

TODO: Consider returning / mutating the cursor. Subsequent items will probably be in this node. It would be marginally faster to find a cursor using a hint, and subsequent deletes in the txn we’re applying will usually be in this node (usually the next item in this node).

Source

pub unsafe fn unsafe_remote_reactivate_notify<F>( cursor: &mut UnsafeCursor<E, I, IE, LE>, max_len: usize, notify: F, ) -> (usize, bool)
where F: FnMut(E, NonNull<NodeLeaf<E, I, IE, LE>>),

Source§

impl<E: ContentTraits, I: FindOffset<E>, const IE: usize, const LE: usize> ContentTreeRaw<E, I, IE, LE>

Source

pub fn insert_at_offset_notify<F>( self: &mut Pin<Box<Self>>, pos: usize, new_entry: E, notify: F, )
where F: FnMut(E, NonNull<NodeLeaf<E, I, IE, LE>>),

Source

pub fn insert_at_offset(self: &mut Pin<Box<Self>>, pos: usize, new_entry: E)

Source

pub fn replace_range_at_offset_notify<N>( self: &mut Pin<Box<Self>>, offset: usize, new_entry: E, notify: N, )
where N: FnMut(E, NonNull<NodeLeaf<E, I, IE, LE>>),

Source

pub fn replace_range_at_offset( self: &mut Pin<Box<Self>>, offset: usize, new_entry: E, )

Source

pub fn delete_at_offset_notify<F>( self: &mut Pin<Box<Self>>, pos: usize, del_items: usize, notify: F, )
where F: FnMut(E, NonNull<NodeLeaf<E, I, IE, LE>>),

Source

pub fn delete_at_offset(self: &mut Pin<Box<Self>>, pos: usize, del_items: usize)

Source§

impl<E: ContentTraits + ContentLength, I: FindContent<E>, const IE: usize, const LE: usize> ContentTreeRaw<E, I, IE, LE>

Source

pub fn insert_at_content_notify<F>( self: &mut Pin<Box<Self>>, pos: usize, new_entry: E, notify: F, )
where F: FnMut(E, NonNull<NodeLeaf<E, I, IE, LE>>),

Source

pub fn insert_at_content(self: &mut Pin<Box<Self>>, pos: usize, new_entry: E)

Source

pub fn replace_range_at_content_notify<N>( self: &mut Pin<Box<Self>>, pos: usize, new_entry: E, notify: N, )
where N: FnMut(E, NonNull<NodeLeaf<E, I, IE, LE>>),

Source

pub fn replace_range_at_content( self: &mut Pin<Box<Self>>, pos: usize, new_entry: E, )

Source

pub fn delete_at_content_notify<F>( self: &mut Pin<Box<Self>>, pos: usize, del_items: usize, notify: F, )
where F: FnMut(E, NonNull<NodeLeaf<E, I, IE, LE>>),

Source

pub fn delete_at_content( self: &mut Pin<Box<Self>>, pos: usize, del_items: usize, )

Source§

impl<E: ContentTraits + ContentLength + Toggleable, I: FindContent<E>, const IE: usize, const LE: usize> ContentTreeRaw<E, I, IE, LE>

Source

pub fn local_deactivate_at_content_notify<F>( self: &mut Pin<Box<Self>>, offset: usize, deleted_len: usize, notify: F, ) -> DeleteResult<E>
where F: FnMut(E, NonNull<NodeLeaf<E, I, IE, LE>>),

Source§

impl<E: ContentTraits, I: TreeMetrics<E>, const IE: usize, const LE: usize> ContentTreeRaw<E, I, IE, LE>

Source

pub fn cursor_at_start(&self) -> Cursor<'_, E, I, IE, LE>

Source

pub fn cursor_at_end(&self) -> Cursor<'_, E, I, IE, LE>

Source

pub fn cursor_at_query<F, G>( &self, raw_pos: usize, stick_end: bool, offset_to_num: F, entry_to_num: G, ) -> Cursor<'_, E, I, IE, LE>
where F: Fn(I::Value) -> usize, G: Fn(E) -> usize,

Source

pub fn mut_cursor_at_start<'a>( self: &'a mut Pin<Box<Self>>, ) -> MutCursor<'a, E, I, IE, LE>

Source

pub fn mut_cursor_at_end<'a>( self: &'a mut Pin<Box<Self>>, ) -> MutCursor<'a, E, I, IE, LE>

Source

pub fn mut_cursor_at_query<'a, F, G>( self: &'a mut Pin<Box<Self>>, raw_pos: usize, stick_end: bool, offset_to_num: F, entry_to_num: G, ) -> MutCursor<'a, E, I, IE, LE>
where F: Fn(I::Value) -> usize, G: Fn(E) -> usize,

Source§

impl<E: ContentTraits, I: TreeMetrics<E>, const IE: usize, const LE: usize> ContentTreeRaw<E, I, IE, LE>

Source

pub fn raw_iter(&self) -> Cursor<'_, E, I, IE, LE>

Iterate through all the items “raw” - which is to say, without merging anything.

This is different from iter() because in some editing situations the tree will not be perfectly flattened. That is, it may be possible to merge some items in the tree. This iterator method will not merge anything, and instead just iterate through all items as they are stored.

Whether specific items are merged or not is an implementation detail, and should not be relied upon by your application. If you expect all mergable items to be merged, use iter().

Source

pub fn iter(&self) -> MergeIter<Cursor<'_, E, I, IE, LE>>

Iterate through all entries in the content tree. This iterator will yield all entries merged according to the methods in SplitableSpan.

Source

pub fn item_iter(&self) -> ItemIterator<'_, E, I, IE, LE>

Source

pub fn node_iter(&self) -> NodeIter<'_, E, I, IE, LE>

Trait Implementations§

Source§

impl<'a, E: ContentTraits, I: TreeMetrics<E>, const IE: usize, const LE: usize> Cursors for &'a ContentTreeRaw<E, I, IE, LE>

Source§

type UnsafeCursor = UnsafeCursor<E, I, IE, LE>

Source§

type Cursor = SafeCursor<&'a ContentTreeRaw<E, I, IE, LE>, E, I, IE, LE>

Source§

type MutCursor = SafeCursor<&'a mut ContentTreeRaw<E, I, IE, LE>, E, I, IE, LE>

Source§

impl<E: ContentTraits, I: TreeMetrics<E>, const IE: usize, const LE: usize> Debug for ContentTreeRaw<E, I, IE, LE>

Source§

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

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

impl<E: ContentTraits + PartialEq, I: TreeMetrics<E>, const IE: usize, const LE: usize> PartialEq for ContentTreeRaw<E, I, IE, LE>

Source§

fn eq(&self, other: &Self) -> 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<E: ContentTraits + PartialEq, I: TreeMetrics<E>, const IE: usize, const LE: usize> Eq for ContentTreeRaw<E, I, IE, LE>

Auto Trait Implementations§

§

impl<E, I, const INT_ENTRIES: usize, const LEAF_ENTRIES: usize> Freeze for ContentTreeRaw<E, I, INT_ENTRIES, LEAF_ENTRIES>
where <I as TreeMetrics<E>>::Value: Freeze,

§

impl<E, I, const INT_ENTRIES: usize, const LEAF_ENTRIES: usize> RefUnwindSafe for ContentTreeRaw<E, I, INT_ENTRIES, LEAF_ENTRIES>

§

impl<E, I, const INT_ENTRIES: usize = DEFAULT_IE, const LEAF_ENTRIES: usize = DEFAULT_LE> !Send for ContentTreeRaw<E, I, INT_ENTRIES, LEAF_ENTRIES>

§

impl<E, I, const INT_ENTRIES: usize = DEFAULT_IE, const LEAF_ENTRIES: usize = DEFAULT_LE> !Sync for ContentTreeRaw<E, I, INT_ENTRIES, LEAF_ENTRIES>

§

impl<E, I, const INT_ENTRIES: usize = DEFAULT_IE, const LEAF_ENTRIES: usize = DEFAULT_LE> !Unpin for ContentTreeRaw<E, I, INT_ENTRIES, LEAF_ENTRIES>

§

impl<E, I, const INT_ENTRIES: usize, const LEAF_ENTRIES: usize> UnwindSafe for ContentTreeRaw<E, I, INT_ENTRIES, LEAF_ENTRIES>

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