Struct granite::chain::Chain[][src]

pub struct Chain<T, S, I> where
    I: List<Element = S>,
    S: List<Element = T>, 
{ /* fields omitted */ }

A list data structure wrapping a list of lists used to prevent lag spikes when dealing with huge numbers of elements.

The usual heap array — Vec — has a major weakness if it is used to store large amounts of data: horrible lag spikes will occur during insertions and when capacity is exhausted and more elements need to be inserted (reallocation and relocation of a huge data set). Copying 256 bytes is not a major performance problem, copying 1024 bytes is something that you can afford to do once in a while, and copying 1 GiB is definitely not something you’d want to do, especially in performance-critical code.

Insertion problems can be partially solved by wrapping the Vec in a SparseStorage and its insert_and_shiftfix, but only if remove_and_shiftfix is also used at least exactly as much as insert_and_shiftfix. Insertions without removals and full reallocations, however, are left unsolved.

Chain resolves the issue by limiting the capacity to which a single list storage can be used (technically doesn’t have to be Vec, though that’s what makes the most sense to use), allocating small buffers anew without touching bigger old ones if more space is requested.

Implementations

impl<T, S, I> Chain<T, S, I> where
    S: List<Element = T>,
    I: List<Element = S>, 
[src]

pub fn set_limit(&mut self, limit: usize)[src]

Sets the limit (in elements, not bytes) to which a buffer will be used before an additional allocation will be performed.

The limit must be even, i.e. a multiple of 2, due to how the limit is stored internally. Check out the source code if you’re curious.

pub fn limit(&self) -> usize[src]

Returns the currently set limit to which a buffer will be used before an additional allocation will be performed.

pub fn allocate_to_limit(&mut self, allocate_to_limit: bool)[src]

Sets whether additional buffers will be allocated to the limit right away or will first allocate as much as needed and only then rellocate to the limit. Enabled by default.

pub fn allocates_to_limit(&self) -> bool[src]

Returns whether allocate_to_limit is enabled.

pub fn num_storages(&self) -> usize[src]

Returns the number of separate storages used.

Trait Implementations

impl<T: Clone, S: Clone, I: Clone> Clone for Chain<T, S, I> where
    I: List<Element = S>,
    S: List<Element = T>, 
[src]

impl<T: Copy, S: Copy, I: Copy> Copy for Chain<T, S, I> where
    I: List<Element = S>,
    S: List<Element = T>, 
[src]

impl<T: Debug, S: Debug, I: Debug> Debug for Chain<T, S, I> where
    I: List<Element = S>,
    S: List<Element = T>, 
[src]

impl<T, S, I> ListStorage for Chain<T, S, I> where
    S: List<Element = T>,
    I: List<Element = S>, 
[src]

type Element = T

The type of values in the container.

fn add(&mut self, element: Self::Element) -> usize[src]

Uses push under the hood. The Chain should be wrapped in SparseStorage, not vice versa.

Auto Trait Implementations

impl<T, S, I> RefUnwindSafe for Chain<T, S, I> where
    I: RefUnwindSafe

impl<T, S, I> Send for Chain<T, S, I> where
    I: Send

impl<T, S, I> Sync for Chain<T, S, I> where
    I: Sync

impl<T, S, I> Unpin for Chain<T, S, I> where
    I: Unpin

impl<T, S, I> UnwindSafe for Chain<T, S, I> where
    I: UnwindSafe

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> Slottable for T where
    T: Copy
[src]

impl<T, E> Storage for T where
    T: ListStorage<Element = E>,
    E: MoveFix
[src]

type Key = usize

The type used for element naming.

type Element = E

The type of the elements stored.

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.