Struct content_tree::ContentTreeRaw [−][src]
pub struct ContentTreeRaw<E: ContentTraits, I: TreeIndex<E>, const INT_ENTRIES: usize, const LEAF_ENTRIES: usize> { /* fields omitted */ }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.raw_iter().collect::<Vec<TestRange>>(), vec![
TestRange { id: 0, len: 150, is_activated: true }
]);Implementations
impl<E: ContentTraits, I: TreeIndex<E>, const IE: usize, const LE: usize> ContentTreeRaw<E, I, IE, LE>
impl<E: ContentTraits, I: TreeIndex<E>, const IE: usize, const LE: usize> ContentTreeRaw<E, I, IE, LE>
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::IndexValue) -> usize,
G: Fn(E) -> usize,
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().
Iterate through all entries in the content tree. This iterator will yield all entries merged according to the methods in SplitableSpan.
pub fn next_entry_or_panic(
cursor: &mut UnsafeCursor<E, I, IE, LE>,
marker: &mut I::IndexUpdate
)
impl<E: ContentTraits + Searchable, I: TreeIndex<E>, const IE: usize, const LE: usize> ContentTreeRaw<E, I, IE, LE>
impl<E: ContentTraits + Searchable, I: TreeIndex<E>, const IE: usize, const LE: usize> ContentTreeRaw<E, I, IE, LE>
pub unsafe fn cursor_before_item(
loc: E::Item,
ptr: NonNull<NodeLeaf<E, I, IE, LE>>
) -> UnsafeCursor<E, I, IE, LE>
pub unsafe fn 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.
impl<E: ContentTraits + ContentLength, I: FindContent<E>, const IE: usize, const LE: usize> ContentTreeRaw<E, I, IE, LE>
impl<E: ContentTraits + ContentLength, I: FindContent<E>, const IE: usize, const LE: usize> ContentTreeRaw<E, I, IE, LE>
pub fn unsafe_cursor_at_content_pos(
&self,
pos: usize,
stick_end: bool
) -> UnsafeCursor<E, I, IE, LE>
pub fn cursor_at_content_pos(
&self,
pos: usize,
stick_end: bool
) -> Cursor<'_, E, I, IE, LE>ⓘ
impl<E: ContentTraits, I: FindOffset<E>, const IE: usize, const LE: usize> ContentTreeRaw<E, I, IE, LE>
impl<E: ContentTraits, I: FindOffset<E>, const IE: usize, const LE: usize> ContentTreeRaw<E, I, IE, LE>
pub fn unsafe_cursor_at_offset_pos(
&self,
pos: usize,
stick_end: bool
) -> UnsafeCursor<E, I, IE, LE>
pub fn cursor_at_offset_pos(
&self,
pos: usize,
stick_end: bool
) -> Cursor<'_, E, I, IE, LE>ⓘ
impl<E: ContentTraits + Searchable, I: FindOffset<E>, const IE: usize, const LE: usize> ContentTreeRaw<E, I, IE, LE>
impl<E: ContentTraits + Searchable, I: FindOffset<E>, const IE: usize, const LE: usize> ContentTreeRaw<E, I, IE, LE>
impl<E: ContentTraits + ContentLength + Searchable, I: FindContent<E>, const IE: usize, const LE: usize> ContentTreeRaw<E, I, IE, LE>
impl<E: ContentTraits + ContentLength + Searchable, I: FindContent<E>, const IE: usize, const LE: usize> ContentTreeRaw<E, I, IE, LE>
impl<E: ContentTraits, I: TreeIndex<E>, const IE: usize, const LE: usize> ContentTreeRaw<E, I, IE, LE>
impl<E: ContentTraits, I: TreeIndex<E>, const IE: usize, const LE: usize> ContentTreeRaw<E, I, IE, LE>
This file contains the core code for content-tree’s mutation operations.
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>>),
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>>),
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>>),
Push a new entry to the end of the tree. The new entry will be merged with the existing last entry if possible.
pub unsafe fn unsafe_mutate_entry_notify<MapFn, N>(
map_fn: MapFn,
cursor: &mut UnsafeCursor<E, I, IE, LE>,
replace_max: usize,
flush_marker: &mut I::IndexUpdate,
notify: &mut N
) -> usize where
N: FnMut(E, NonNull<NodeLeaf<E, I, IE, LE>>),
MapFn: FnOnce(&mut E),
pub unsafe fn unsafe_mutate_entry_notify<MapFn, N>(
map_fn: MapFn,
cursor: &mut UnsafeCursor<E, I, IE, LE>,
replace_max: usize,
flush_marker: &mut I::IndexUpdate,
notify: &mut N
) -> usize where
N: FnMut(E, NonNull<NodeLeaf<E, I, IE, LE>>),
MapFn: FnOnce(&mut E),
Replace as much of the current entry from cursor onwards as we can
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>>),
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.
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>>),
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.
impl<E: ContentTraits + Toggleable, I: TreeIndex<E>, const IE: usize, const LE: usize> ContentTreeRaw<E, I, IE, LE>
impl<E: ContentTraits + Toggleable, I: TreeIndex<E>, const IE: usize, const LE: usize> ContentTreeRaw<E, I, IE, LE>
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>>),
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).