[][src]Struct gen_vec::exposed::IndexAllocator

pub struct IndexAllocator { /* fields omitted */ }

Allocates and deallocates indices for a ExposedGenVec

Implementations

impl IndexAllocator[src]

pub fn new() -> IndexAllocator[src]

Returns a new empty IndexAllocator

Examples

use gen_vec::exposed::IndexAllocator;
let mut allocator: IndexAllocator = IndexAllocator::new();

pub fn with_capacity(capacity: usize) -> IndexAllocator[src]

Returns a IndexAllocator with initial capacity of capacity

Allows the IndexAllocator to hold capacity elements before allocating more space

Examples

use gen_vec::exposed::IndexAllocator;
let mut allocator: IndexAllocator = IndexAllocator::with_capacity(5);

pub fn allocate(&mut self) -> Index[src]

Allocates and returns a new Index

Activates a freed index if there are any, otherwise creates and adds a new index to active_indices

Examples

use gen_vec::Index;
use gen_vec::exposed::IndexAllocator;

let mut allocator: IndexAllocator = IndexAllocator::new();
let index: Index = allocator.allocate();

pub fn deallocate(&mut self, index: Index)[src]

Frees index if it hasn't been already.

Afterwards, index is added to the pool of free indices available for reuse

Examples

use gen_vec::Index;
use gen_vec::exposed::IndexAllocator;

let mut allocator: IndexAllocator = IndexAllocator::new();
let index: Index = allocator.allocate();
allocator.deallocate(index);

pub fn deallocate_all(&mut self)[src]

Frees all active indices and adds them to the pool of free indices

Examples

use gen_vec::exposed::IndexAllocator;
use gen_vec::Index;

let mut allocator: IndexAllocator = IndexAllocator::new();
for _ in 0..10
{
    allocator.allocate();
}
assert_eq!(allocator.num_active(), 10);
assert_eq!(allocator.num_free(), 0);

allocator.deallocate_all();
assert_eq!(allocator.num_active(), 0);
assert_eq!(allocator.num_free(), 10);

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

Reserved capacity within the IndexAllocator

Examples

use gen_vec::exposed::IndexAllocator;

let mut allocator: IndexAllocator = IndexAllocator::with_capacity(5);
assert_eq!(allocator.capacity(), 5);

pub fn reserve(&mut self, additional: usize)[src]

Reserves extra space for at least additional more elements

More space may be allocated to avoid frequent re-allocations (as per the specifications of std::vec::Vec)

Examples

use gen_vec::Index;
use gen_vec::exposed::IndexAllocator;

let mut allocator: IndexAllocator = IndexAllocator::new();
let index: Index = allocator.allocate();
allocator.reserve(4);
assert!(allocator.capacity() >= 4);

pub fn is_active(&self, index: Index) -> bool[src]

Returns if index is still active and hasn't been deallocated

Examples

use gen_vec::Index;
use gen_vec::exposed::IndexAllocator;

let mut allocator: IndexAllocator = IndexAllocator::new();
let index: Index = allocator.allocate();
assert!(allocator.is_active(index));
allocator.deallocate(index);
assert!(!allocator.is_active(index));

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

Returns the number of free indices waiting to be allocated and reused

Examples

use gen_vec::Index;
use gen_vec::exposed::IndexAllocator;

let mut allocator: IndexAllocator = IndexAllocator::new();
assert_eq!(allocator.num_free(), 0);

let index: Index = allocator.allocate();

allocator.deallocate(index);
assert_eq!(allocator.num_free(), 1);

let index: Index = allocator.allocate();
assert_eq!(allocator.num_free(), 0);

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

Returns the number of active indices

Examples

use gen_vec::Index;
use gen_vec::exposed::IndexAllocator;

let mut allocator: IndexAllocator = IndexAllocator::new();
assert_eq!(allocator.num_active(), 0);

let index: Index = allocator.allocate();
assert_eq!(allocator.num_active(), 1);

allocator.deallocate(index);
assert_eq!(allocator.num_active(), 0);

Trait Implementations

impl Debug for IndexAllocator[src]

impl Default for IndexAllocator[src]

Auto Trait Implementations

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