Struct zarts::SortedSeq

source ·
pub struct SortedSeq<T>(_);
Expand description

座標圧縮です。

Examples

use zarts::SortedSeq;
let values = vec![2, -1, -1, 5, -1, 2, -3];
// -3, -1, 2, 5
let seq = SortedSeq::new(values);
assert_eq!(seq.ord(&-3), 0);
assert_eq!(seq.ord(&-1), 1);
assert_eq!(seq.ord(&2), 2);
assert_eq!(seq.ord(&5), 3);

assert_eq!(seq.at(0), &(-3));
assert_eq!(seq.at(1), &(-1));
assert_eq!(seq.at(2), &2);
assert_eq!(seq.at(3), &5);

Panics

構築時に与えられなかったキーを引くとパニックです。

use zarts::SortedSeq;
let primes = vec![2, 3, 5, 7, 11];
let seq = SortedSeq::new(primes);
seq.ord(&4);

index が集合のサイズ以上だとパニックです。

use zarts::SortedSeq;
let values = vec![1, 1, 2, 2, 3, 4, 9, 9];
let seq = SortedSeq::new(values);
seq.at(5);

Implementations§

source§

impl<T> SortedSeq<T>where T: Ord,

source

pub fn new(values: impl IntoIterator<Item = T>) -> Self

source

pub fn ord(&self, value: &T) -> usize

集合内で小さいほうから何番目か (0-indexed) を返します

source

pub fn at(&self, index: usize) -> &T

index 番目の値を返します

source

pub fn size(&self) -> usize

集合のサイズを返します

Trait Implementations§

source§

impl<T> Debug for SortedSeq<T>where T: Debug,

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<T> FromIterator<T> for SortedSeq<T>where T: Ord,

source§

fn from_iter<I: IntoIterator<Item = T>>(iter: I) -> Self

Creates a value from an iterator. Read more
source§

impl<T> Index<usize> for SortedSeq<T>

§

type Output = T

The returned type after indexing.
source§

fn index(&self, index: usize) -> &Self::Output

Performs the indexing (container[index]) operation. Read more

Auto Trait Implementations§

§

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

§

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

§

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

§

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

§

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

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

const: unstable · 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 Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
const: unstable · source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.