Skip to main content

OrdAllocator

Struct OrdAllocator 

Source
pub struct OrdAllocator<K, T, O>
where K: Id, O: Collexetable<T>, T: FieldValue,
{ pub id_map: IdMap<K, T>, pub collex: FieldCollex<Pair<K, O>, T>, }

Fields§

§id_map: IdMap<K, T>§collex: FieldCollex<Pair<K, O>, T>

Implementations§

Source§

impl<K, V, E> OrdAllocator<K, V, E>
where K: Id, E: Collexetable<V>, V: FieldValue,

Source

pub fn new(span: Span<V>, unit: V) -> Result<Self, NewFieldCollexError<V>>

Source

pub fn with_capacity( span: Span<V>, unit: V, capacity: usize, ) -> Result<Self, WithCapacityFieldCollexError<V>>

Source

pub fn with_elements( span: Span<V>, unit: V, vec: Vec<E>, ) -> Result<Self, WithElementsFieldCollexError<V>>

Source

pub fn extend(&mut self, vec: Vec<E>)

Source

pub fn try_extend(&mut self, vec: Vec<E>) -> TryExtendResult<Pair<K, E>>

Source

pub fn insert(&mut self, elem: E) -> Result<K, InsertFieldCollexError<E>>

Source

pub fn remove(&mut self, id: K) -> Option<E>

Source

pub fn modify<F, R>( &mut self, id: K, f: F, ) -> Result<R, ModifyFieldCollexError<(R, E)>>
where F: Fn(&mut E) -> R,

Source

pub fn try_modify<F, R>( &mut self, id: K, f: F, ) -> Result<R, ModifyFieldCollexError<R>>
where F: Fn(&mut E) -> R,

Source

pub fn get_with_id(&self, id: K) -> Option<&E>

Source

pub fn into_raw_parts(self) -> (IdMap<K, V>, FieldCollex<Pair<K, E>, V>)

Source

pub fn from_raw_parts( id_map: IdMap<K, V>, collex: FieldCollex<Pair<K, E>, V>, ) -> Self

Methods from Deref<Target = FieldCollex<Pair<K, E>, V>>§

Source

pub fn iter(&self) -> Iter<'_, E, V>

获取不可变迭代器

Source

pub fn span(&self) -> &Span<V>

Source

pub fn unit(&self) -> &V

Source

pub fn size(&self) -> Option<usize>

返回最大块数量

若Span是无限区间,返回None

Source

pub fn len(&self) -> usize

返回已存在的块的数量

此值应小于等于最大块数量

Source

pub fn capacity(&self) -> usize

Returns the total number of elements the inner vector can hold without reallocating.

此值应小于等于最大块数量

Source

pub fn contains(&self, elem: &E) -> bool

查找对应是否存在与其collexate()值相同的元素

Source

pub fn contains_value(&self, value: V) -> bool

查找对应值是否存在

Source

pub fn first(&self) -> Option<&E>

找到第一个值的引用

Source

pub fn last(&self) -> Option<&E>

找最后一个值的引用

Source

pub fn extend(&mut self, vec: Vec<E>)

批量插入元素,忽略错误值。

Source

pub fn try_extend(&mut self, vec: Vec<E>) -> TryExtendResult<E>

批量插入元素,返回插入的情况。

Source

pub fn insert(&mut self, value: E) -> Result<(), InsertFieldCollexError<E>>

插入值

Source

pub fn remove(&mut self, target: V) -> Result<E, RemoveFieldCollexError>

删除对应值

Source

pub fn find_gt(&self, target: V) -> Option<&E>

Source

pub fn find_ge(&self, target: V) -> Option<&E>

Source

pub fn find_lt(&self, target: V) -> Option<&E>

Source

pub fn find_le(&self, target: V) -> Option<&E>

Source

pub fn find_closest(&self, target: V) -> Option<&E>

找到最近的

两边距离相等时返回更小的

Source

pub fn is_empty(&self) -> bool

判断本容器是否为空

为空不意味着内存占用为0。

Source

pub fn get(&self, value: V) -> Option<&E>

Source

pub fn unchecked_get(&self, value: V) -> &E

§Panics

找不到panic

Source

pub fn try_modify<F, R>( &mut self, value: V, op: F, ) -> Result<R, ModifyFieldCollexError<R>>
where F: Fn(&mut E) -> R,

闭包结束后,会根据Value是否发生变化来决定是否更新其在Collex中的位置

若更新后的值(仅指collexate值)无法容纳于本Collex,将报错并重置值。

Source

pub fn modify<F, R>( &mut self, value: V, op: F, ) -> Result<R, ModifyFieldCollexError<(R, E)>>
where F: Fn(&mut E) -> R,

闭包结束后,会根据Value是否发生变化来决定是否更新其在Collex中的位置

若更新后的值(仅指collexate值)无法容纳于本Collex,将直接通过错误类型的变体返还

Source

pub fn unchecked_modify<F, R>(&mut self, value: V, op: F) -> R
where F: Fn(&mut E) -> R,

闭包结束后,会根据Value是否发生变化来决定是否更新其在Collex中的位置

§Panics

若无法找到对应的元素,panic

若更新后的值(仅指collexate值)无法容纳于本Collex,将直接Panic

Trait Implementations§

Source§

impl<K, T, O> Debug for OrdAllocator<K, T, O>
where K: Id + Debug, O: Collexetable<T> + Debug, T: FieldValue + Debug,

Source§

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

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

impl<K, V, E> Deref for OrdAllocator<K, V, E>
where K: Id, E: Collexetable<V>, V: FieldValue,

Source§

type Target = FieldCollex<Pair<K, E>, V>

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Self::Target

Dereferences the value.
Source§

impl<K, V, E> DerefMut for OrdAllocator<K, V, E>
where K: Id, E: Collexetable<V>, V: FieldValue,

Source§

fn deref_mut(&mut self) -> &mut Self::Target

Mutably dereferences the value.
Source§

impl<'de, K, T, O> Deserialize<'de> for OrdAllocator<K, T, O>
where O: Collexetable<T> + Deserialize<'de>, T: FieldValue + Deserialize<'de>, K: Id + Deserialize<'de>,

Source§

fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl<K, T, O> Serialize for OrdAllocator<K, T, O>

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

§

impl<K, T, O> Freeze for OrdAllocator<K, T, O>
where T: Freeze,

§

impl<K, T, O> RefUnwindSafe for OrdAllocator<K, T, O>

§

impl<K, T, O> Send for OrdAllocator<K, T, O>
where T: Send, K: Send, O: Send,

§

impl<K, T, O> Sync for OrdAllocator<K, T, O>
where T: Sync, K: Sync, O: Sync,

§

impl<K, T, O> Unpin for OrdAllocator<K, T, O>
where T: Unpin, K: Unpin, O: Unpin,

§

impl<K, T, O> UnsafeUnpin for OrdAllocator<K, T, O>
where T: UnsafeUnpin,

§

impl<K, T, O> UnwindSafe for OrdAllocator<K, T, O>
where T: UnwindSafe, K: UnwindSafe, O: 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.

Source§

impl<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
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.
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,