SeekBySize

Struct SeekBySize 

Source
struct SeekBySize<T> {
    index: usize,
    _marker: PhantomData<fn() -> T>,
}

Fields§

§index: usize§_marker: PhantomData<fn() -> T>

Implementations§

Source§

impl<T> SeekBySize<T>

Source

fn new(index: usize) -> Self

Examples found in repository?
crates/competitive/src/data_structure/splay_tree/sequence.rs (line 311)
306    fn range<R>(&mut self, range: R) -> NodeRange<'_, LazyAggSplay<T>>
307    where
308        R: RangeBounds<usize>,
309    {
310        let start = match range.start_bound() {
311            Bound::Included(&index) => Bound::Included(SeekBySize::new(index)),
312            Bound::Excluded(&index) => Bound::Excluded(SeekBySize::new(index)),
313            Bound::Unbounded => Bound::Unbounded,
314        };
315        let end = match range.end_bound() {
316            Bound::Included(&index) => Bound::Included(SeekBySize::new(index)),
317            Bound::Excluded(&index) => Bound::Excluded(SeekBySize::new(index)),
318            Bound::Unbounded => Bound::Unbounded,
319        };
320        self.root.range(start, end)
321    }
322    pub fn update<R>(&mut self, range: R, x: T::Act)
323    where
324        R: RangeBounds<usize>,
325    {
326        if let Some(root) = self.range(range).root_mut().root_data_mut() {
327            LazyAggSplay::<T>::update_lazy(root, &x);
328        }
329    }
330    pub fn fold<R>(&mut self, range: R) -> T::Agg
331    where
332        R: RangeBounds<usize>,
333    {
334        if let Some(root) = self.range(range).root().root() {
335            root.data().agg.clone()
336        } else {
337            T::agg_unit()
338        }
339    }
340    pub fn reverse<R>(&mut self, range: R)
341    where
342        R: RangeBounds<usize>,
343    {
344        if let Some(root) = self.range(range).root_mut().root_data_mut() {
345            LazyAggSplay::<T>::reverse(root);
346        }
347    }
348    pub fn get(&mut self, index: usize) -> Option<&T::Key> {
349        self.root.splay_by(SeekBySize::new(index))?;
350        self.root.root().map(|root| &root.data().key)
351    }
352    pub fn modify<F>(&mut self, index: usize, f: F)
353    where
354        F: FnOnce(&T::Key) -> T::Key,
355    {
356        self.root.splay_by(SeekBySize::new(index)).unwrap();
357        let data = self.root.root_data_mut().unwrap().data_mut();
358        data.key = f(&data.key);
359        LazyAggSplay::<T>::bottom_up(self.root.root_data_mut().unwrap());
360    }
361    pub fn insert(&mut self, index: usize, x: T::Key) {
362        assert!(index <= self.length);
363        self.root.splay_by(SeekBySize::new(index));
364        let agg = T::single_agg(&x);
365        unsafe {
366            let node = NodeRef::from_data(
367                LazyAggElement {
368                    key: x,
369                    agg,
370                    lazy: T::act_unit(),
371                    size: 1,
372                    rev: false,
373                },
374                self.alloc.deref_mut(),
375            );
376            if index == self.length {
377                self.root.insert_right(node);
378            } else {
379                self.root.insert_left(node);
380            }
381        }
382        self.length += 1;
383    }
384    pub fn remove(&mut self, index: usize) -> Option<T::Key> {
385        if index >= self.length {
386            return None;
387        }
388        self.root.splay_by(SeekBySize::new(index));
389        self.length -= 1;
390        let node = self.root.take_root().unwrap().into_dying();
391        unsafe { Some(node.into_data(self.alloc.deref_mut()).key) }
392    }

Trait Implementations§

Source§

impl<T> SplaySeeker for SeekBySize<T>
where T: LazyMapMonoid,

Source§

type S = LazyAggSplay<T>

Source§

fn splay_seek(&mut self, node: NodeRef<Immut<'_>, Self::S>) -> Ordering

Auto Trait Implementations§

§

impl<T> Freeze for SeekBySize<T>

§

impl<T> RefUnwindSafe for SeekBySize<T>

§

impl<T> Send for SeekBySize<T>

§

impl<T> Sync for SeekBySize<T>

§

impl<T> Unpin for SeekBySize<T>

§

impl<T> UnwindSafe for SeekBySize<T>

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.