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]
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 Default for IdGenerator
[src]
impl Default for IdGenerator
[src]Auto Trait Implementations
impl RefUnwindSafe for IdGenerator
impl RefUnwindSafe for IdGenerator
impl Send for IdGenerator
impl Send for IdGenerator
impl Sync for IdGenerator
impl Sync for IdGenerator
impl Unpin for IdGenerator
impl Unpin for IdGenerator
impl UnwindSafe for IdGenerator
impl UnwindSafe for IdGenerator