SortedSeq

Struct SortedSeq 

Source
pub struct SortedSeq<T>(/* private fields */);
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), Some(&(-3)));
assert_eq!(seq.at(1), Some(&(-1)));
assert_eq!(seq.at(2), Some(&2));
assert_eq!(seq.at(3), Some(&5));
assert_eq!(seq.at(4), None);

§Panics

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

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

Implementations§

Source§

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

Source

pub fn new(values: Vec<T>) -> Self

Source

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

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

Source

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

index 番目の値を返します

§Examples
use zarts::SortedSeq;

let seq = SortedSeq::new(vec![4, 16, 9, 1]);
// 1, 4, 9, 16
assert_eq!(seq.at(0), Some(&1));
assert_eq!(seq.at(1), Some(&4));
assert_eq!(seq[2], 9);
assert_eq!(seq[3], 16);
assert_eq!(seq.at(4), None);
Source

pub fn len(&self) -> usize

集合のサイズを返します

Source

pub fn is_empty(&self) -> bool

Source

pub fn iter(&self) -> impl Iterator<Item = &T>

Trait Implementations§

Source§

impl<T: Clone> Clone for SortedSeq<T>

Source§

fn clone(&self) -> SortedSeq<T>

Returns a duplicate of the value. Read more
1.0.0§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
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>

Source§

type Output = T

The returned type after indexing.
Source§

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

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

impl<T: PartialEq> PartialEq for SortedSeq<T>

Source§

fn eq(&self, other: &SortedSeq<T>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<T: Eq> Eq for SortedSeq<T>

Source§

impl<T> StructuralPartialEq for SortedSeq<T>

Auto Trait Implementations§

§

impl<T> Freeze for SortedSeq<T>

§

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§

§

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

§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

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

§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
§

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

§

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

Mutably borrows from an owned value. Read more
§

impl<T> CloneToUninit for T
where T: Clone,

§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
§

impl<T> From<T> for T

§

fn from(t: T) -> T

Returns the argument unchanged.

§

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

§

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> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
§

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

§

type Error = Infallible

The type returned in the event of a conversion error.
§

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

Performs the conversion.
§

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.
§

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

Performs the conversion.