Struct set_genome::IdGenerator[][src]

pub struct IdGenerator { /* fields omitted */ }

Acts as a generator and cache for ANN node identities.

For any evolution process you should only ever use exactly one IdGenerator and pass it around whenever one is required, as several operations and gurantees rely on the cache inside the generator to function as defined. Usually it suffices to use the <operation>_with_context functions on the crate::Genome and let the crate::GenomeContext handle the identity generation.

use set_genome::IdGenerator;
let id_generator = IdGenerator::default();

Implementations

impl IdGenerator[src]

pub fn next_id(&mut self) -> Id[src]

Returns the next unique identity.

let mut id_generator = IdGenerator::default();
assert_eq!(id_generator.next_id(), Id(0));
assert_eq!(id_generator.next_id(), Id(1));

pub fn cached_id_iter(&mut self, cache_key: (Id, Id)) -> IdIter<'_>[src]

Returns an iterator over identities for the given cache key which automatically extends the cache with new entries when iterated beyond the entries cached so far.

// cache is initially empty
let mut id_generator = IdGenerator::default();
// ask for any arbitrary cache entry
let mut id_iter = id_generator.cached_id_iter((Id(9), Id(9)));
// we get the next available id
assert_eq!(id_iter.next(), Some(Id(0)));
// the id_iter advanced the generator
assert_eq!(id_generator.next_id(), Id(1));
// asking for the same entry later returns the cached entry and then fresh ones
let mut id_iter = id_generator.cached_id_iter((Id(9), Id(9)));
assert_eq!(id_iter.next(), Some(Id(0)));
assert_eq!(id_iter.next(), Some(Id(2)));

Trait Implementations

impl Debug for IdGenerator[src]

impl Default for IdGenerator[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.

impl<V, T> VZip<V> for T where
    V: MultiLane<T>,