struct RakeBstSpec<S, A>(PhantomData<fn() -> (S, A)>);Tuple Fields§
§0: PhantomData<fn() -> (S, A)>Implementations§
Source§impl<S, A> RakeBstSpec<S, A>where
S: TopTreeSpec,
A: TopTreeAction<S>,
impl<S, A> RakeBstSpec<S, A>where
S: TopTreeSpec,
A: TopTreeAction<S>,
Sourceunsafe fn apply(
node: NonNull<BstNode<RakeData<S, A>, WithParent<RakeData<S, A>>>>,
action: &A::Action,
)
unsafe fn apply( node: NonNull<BstNode<RakeData<S, A>, WithParent<RakeData<S, A>>>>, action: &A::Action, )
Examples found in repository?
crates/competitive/src/tree/top_tree.rs (line 184)
157 fn top_down(mut node: BstDataMutRef<'_, Self>) {
158 let pointer = node.node;
159 if node.reborrow().into_data().index_and_reverse & 1 != 0 {
160 node.data_mut().index_and_reverse &= !1;
161 for child in unsafe { pointer.as_ref().child }.into_iter().flatten() {
162 unsafe { Self::toggle(child) };
163 }
164 }
165
166 if !Self::is_unit(&node.reborrow().into_data().heavy_action) {
167 let action = replace(
168 &mut node.data_mut().heavy_action,
169 <A::ActionMonoid as Unital>::unit(),
170 );
171 for child in unsafe { pointer.as_ref().child }.into_iter().flatten() {
172 unsafe { Self::apply_heavy(child, &action) };
173 }
174 }
175 if !Self::is_unit(&node.reborrow().into_data().light_action) {
176 let action = replace(
177 &mut node.data_mut().light_action,
178 <A::ActionMonoid as Unital>::unit(),
179 );
180 for child in unsafe { pointer.as_ref().child }.into_iter().flatten() {
181 unsafe { Self::apply_light(child, &action) };
182 }
183 if let Some(light) = node.reborrow().into_data().light {
184 unsafe { RakeBstSpec::<S, A>::apply(light, &action) };
185 }
186 }
187 }
188
189 #[inline]
190 fn bottom_up(node: BstDataMutRef<'_, Self>) {
191 let pointer = node.node;
192 let data = unsafe { &mut (*pointer.as_ptr()).data };
193 let mut sum = if let Some(light) = data.light {
194 S::add_vertex(unsafe { &light.as_ref().data.sum }, &data.info)
195 } else {
196 S::vertex(&data.info)
197 };
198 if let Some(left) = unsafe { pointer.as_ref().child[0] } {
199 sum = S::compress(unsafe { &left.as_ref().data.sum }, &sum);
200 }
201 if let Some(right) = unsafe { pointer.as_ref().child[1] } {
202 sum = S::compress(&sum, unsafe { &right.as_ref().data.sum });
203 }
204 data.sum = sum;
205 }
206
207 fn merge(_left: Option<BstRoot<Self>>, _right: Option<BstRoot<Self>>) -> Option<BstRoot<Self>> {
208 unreachable!("top trees do not merge auxiliary trees through BstSpec")
209 }
210
211 fn split<Seeker>(
212 _node: Option<BstRoot<Self>>,
213 _seeker: Seeker,
214 _equal_side: EqualSide,
215 ) -> (Option<BstRoot<Self>>, Option<BstRoot<Self>>)
216 where
217 Seeker: BstSeeker<Spec = Self>,
218 {
219 unreachable!("top trees do not split auxiliary trees through BstSpec")
220 }
221}
222
223impl<S, A> RakeBstSpec<S, A>
224where
225 S: TopTreeSpec,
226 A: TopTreeAction<S>,
227{
228 #[inline]
229 unsafe fn apply(mut node: RakePtr<S, A>, action: &A::Action) {
230 let data = unsafe { &mut node.as_mut().data };
231 A::act_point(&mut data.key, action);
232 A::act_point(&mut data.sum, action);
233 TopBstSpec::<S, A>::compose(&mut data.action, action);
234 TopBstSpec::<S, A>::compose(&mut data.buffer, action);
235 }
236}
237
238impl<S, A> BstSpec for RakeBstSpec<S, A>
239where
240 S: TopTreeSpec,
241 A: TopTreeAction<S>,
242{
243 type Parent = WithParent<Self::Data>;
244 type Data = RakeData<S, A>;
245
246 #[inline]
247 fn top_down(mut node: BstDataMutRef<'_, Self>) {
248 if TopBstSpec::<S, A>::is_unit(&node.reborrow().into_data().action) {
249 return;
250 }
251 let pointer = node.node;
252 let action = replace(
253 &mut node.data_mut().action,
254 <A::ActionMonoid as Unital>::unit(),
255 );
256 for child in unsafe { pointer.as_ref().child }.into_iter().flatten() {
257 unsafe { Self::apply(child, &action) };
258 }
259 }Trait Implementations§
Source§impl<S, A> BstSpec for RakeBstSpec<S, A>where
S: TopTreeSpec,
A: TopTreeAction<S>,
impl<S, A> BstSpec for RakeBstSpec<S, A>where
S: TopTreeSpec,
A: TopTreeAction<S>,
type Parent = WithParent<<RakeBstSpec<S, A> as BstSpec>::Data>
type Data = RakeData<S, A>
fn top_down(node: BstDataMutRef<'_, Self>)
fn bottom_up(node: BstDataMutRef<'_, Self>)
fn merge( _left: Option<BstRoot<Self>>, _right: Option<BstRoot<Self>>, ) -> Option<BstRoot<Self>>
fn split<Seeker>(
_node: Option<BstRoot<Self>>,
_seeker: Seeker,
_equal_side: EqualSide,
) -> (Option<BstRoot<Self>>, Option<BstRoot<Self>>)where
Seeker: BstSeeker<Spec = Self>,
Auto Trait Implementations§
impl<S, A> Freeze for RakeBstSpec<S, A>
impl<S, A> RefUnwindSafe for RakeBstSpec<S, A>
impl<S, A> Send for RakeBstSpec<S, A>
impl<S, A> Sync for RakeBstSpec<S, A>
impl<S, A> Unpin for RakeBstSpec<S, A>
impl<S, A> UnsafeUnpin for RakeBstSpec<S, A>
impl<S, A> UnwindSafe for RakeBstSpec<S, A>
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