struct SubtreeSum;Implementations§
Source§impl SubtreeSum
impl SubtreeSum
Sourcefn apply(data: &mut SubtreeSumData, action: u64)
fn apply(data: &mut SubtreeSumData, action: u64)
Examples found in repository?
crates/library_checker/src/tree/dynamic_tree_subtree_add_subtree_sum.rs (line 66)
63 fn top_down(data: &mut Self::Data, children: [Option<&mut Self::Data>; 2]) {
64 let action = std::mem::replace(&mut data.lazy, 0);
65 for child in children.into_iter().flatten() {
66 Self::apply(child, action);
67 }
68 }
69
70 fn bottom_up(data: &mut Self::Data, children: [Option<&Self::Data>; 2]) {
71 data.sum = data.value
72 + data.virtual_sum
73 + children
74 .into_iter()
75 .flatten()
76 .map(|child| child.sum)
77 .sum::<u64>();
78 data.size = 1
79 + data.virtual_size
80 + children
81 .into_iter()
82 .flatten()
83 .map(|child| child.size)
84 .sum::<u64>();
85 }
86
87 fn reverse(_data: &mut Self::Data) {}
88
89 fn attach_virtual(parent: &mut Self::Data, child: &mut Self::Data) {
90 child.path_parent_lazy = parent.virtual_lazy;
91 parent.virtual_sum += child.sum;
92 parent.virtual_size += child.size;
93 }
94
95 fn detach_virtual(parent: &mut Self::Data, child: &mut Self::Data) {
96 Self::apply(child, parent.virtual_lazy - child.path_parent_lazy);
97 parent.virtual_sum -= child.sum;
98 parent.virtual_size -= child.size;
99 }
100
101 fn transfer_path_parent(old_root: &mut Self::Data, new_root: &mut Self::Data) {
102 new_root.path_parent_lazy = std::mem::replace(&mut old_root.path_parent_lazy, 0);
103 }
104}
105
106impl LinkCutTreeSubtreeFold for SubtreeSum {
107 type Subtree = u64;
108
109 fn fold_subtree(data: &Self::Data) -> Self::Subtree {
110 data.sum
111 }
112}
113
114impl LinkCutTreeSubtreeUpdate for SubtreeSum {
115 type SubtreeAction = u64;
116
117 fn update_subtree(data: &mut Self::Data, action: &Self::SubtreeAction) {
118 Self::apply(data, *action);
119 }Trait Implementations§
Source§impl LinkCutTreeSpec for SubtreeSum
impl LinkCutTreeSpec for SubtreeSum
Source§const ROOT_TO_NODE_TOP_DOWN: bool = false
const ROOT_TO_NODE_TOP_DOWN: bool = false
Whether splay must propagate from the auxiliary root before rotations.
type Value = u64
type Data = SubtreeSumData
fn new(value: Self::Value) -> Self::Data
fn value(data: &Self::Data) -> &Self::Value
fn value_mut(data: &mut Self::Data) -> &mut Self::Value
fn top_down(data: &mut Self::Data, children: [Option<&mut Self::Data>; 2])
fn bottom_up(data: &mut Self::Data, children: [Option<&Self::Data>; 2])
fn reverse(_data: &mut Self::Data)
fn attach_virtual(parent: &mut Self::Data, child: &mut Self::Data)
fn detach_virtual(parent: &mut Self::Data, child: &mut Self::Data)
Source§fn transfer_path_parent(old_root: &mut Self::Data, new_root: &mut Self::Data)
fn transfer_path_parent(old_root: &mut Self::Data, new_root: &mut Self::Data)
Moves state associated with the same path-parent edge after a splay.
Source§const MODIFY_REQUIRES_ACCESS: bool = true
const MODIFY_REQUIRES_ACCESS: bool = true
Whether
modify must expose the node to update virtual subtree state.Source§impl LinkCutTreeSubtreeFold for SubtreeSum
impl LinkCutTreeSubtreeFold for SubtreeSum
Source§impl LinkCutTreeSubtreeUpdate for SubtreeSum
impl LinkCutTreeSubtreeUpdate for SubtreeSum
type SubtreeAction = u64
fn update_subtree(data: &mut Self::Data, action: &Self::SubtreeAction)
Auto Trait Implementations§
impl Freeze for SubtreeSum
impl RefUnwindSafe for SubtreeSum
impl Send for SubtreeSum
impl Sync for SubtreeSum
impl Unpin for SubtreeSum
impl UnsafeUnpin for SubtreeSum
impl UnwindSafe for SubtreeSum
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
Mutably borrows from an owned value. Read more