Struct umgap::rmq::RMQ

source ·
pub struct RMQ<T: Ord + Display> {
    pub array: Vec<T>,
    pub block_min: Vec<usize>,
    pub sparse: Vec<Vec<usize>>,
    pub labels: Vec<usize>,
}
Expand description

Represents a Range Minimum Query (RMQ), which can efficiently return the minimal value in a given range of an array.

Fields§

§array: Vec<T>

The full array.

§block_min: Vec<usize>

The absolute position (i.e. the index in array) of the minimum for each block.

§sparse: Vec<Vec<usize>>

sparse[i][j] is the position of the minimum in block[i] to block[i + 2^(j+1) - 1].

§labels: Vec<usize>

The j’th bit of labels[i] is 1 iff j is the first position (in the block) left of i where array[j] < array[i].

Implementations§

source§

impl<T: Ord + Display> RMQ<T>

source

pub fn new(array: Vec<T>) -> RMQ<T>

Constructs an RMQ for the given array.

source

pub fn block_min(array: &[T]) -> Vec<usize>

Calculates the position of each block’s minimum.

source

pub fn sparse(array: &[T], block_min: &[usize]) -> Vec<Vec<usize>>

Calculate the values of the sparse field.

source

pub fn labels(array: &[T]) -> Vec<usize>

Calculate the values of the label field.

source

pub fn query(&self, start: usize, end: usize) -> usize

Returns the position of the minimal value in a given sublist.

Auto Trait Implementations§

§

impl<T> RefUnwindSafe for RMQ<T>
where T: RefUnwindSafe,

§

impl<T> Send for RMQ<T>
where T: Send,

§

impl<T> Sync for RMQ<T>
where T: Sync,

§

impl<T> Unpin for RMQ<T>
where T: Unpin,

§

impl<T> UnwindSafe for RMQ<T>
where T: UnwindSafe,

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.

§

impl<T> Pointable for T

§

const ALIGN: usize = _

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

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

§

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.