Vita
Classes | Public Member Functions | List of all members
vita::cache Class Reference

Implements a hash table that links individuals' signature to fitness (mainly used by the evaluator_proxy class). More...

#include <cache.h>

Public Member Functions

 cache (unsigned)
 Creates a new hash table. More...
 
void clear ()
 Clears the content and the statistical informations of the table. More...
 
void clear (const hash_t &)
 Clears the cached information for a specific individual. More...
 
 DISALLOW_COPY_AND_ASSIGN (cache)
 
const fitness_tfind (const hash_t &) const
 Looks for the fitness of an individual in the transposition table. More...
 
void insert (const hash_t &, const fitness_t &)
 Stores fitness information in the transposition table. More...
 
bool is_valid () const
 
bool load (std::istream &)
 
bool save (std::ostream &) const
 

Detailed Description

Implements a hash table that links individuals' signature to fitness (mainly used by the evaluator_proxy class).

During the evolution semantically equivalent (but syntactically distinct) individuals are often generated and cache can give a significant speed improvement avoiding the recalculation of shared information.

Definition at line 31 of file cache.h.

Constructor & Destructor Documentation

◆ cache()

vita::cache::cache ( unsigned  bits)
explicit

Creates a new hash table.

Parameters
[in]bits2^bits is the number of elements of the table

Definition at line 24 of file cache.cc.

Member Function Documentation

◆ clear() [1/2]

void vita::cache::clear ( )

Clears the content and the statistical informations of the table.

Note
Allocated size isn't changed.

Definition at line 45 of file cache.cc.

◆ clear() [2/2]

void vita::cache::clear ( const hash_t h)

Clears the cached information for a specific individual.

Parameters
[in]hindividual's signature whose informations we have to clear

Definition at line 63 of file cache.cc.

◆ find()

const fitness_t & vita::cache::find ( const hash_t h) const

Looks for the fitness of an individual in the transposition table.

Parameters
[in]hindividual's signature to look for
Returns
the fitness of the individual. If the individuals isn't present returns an empty fitness

Definition at line 81 of file cache.cc.

◆ insert()

void vita::cache::insert ( const hash_t h,
const fitness_t fitness 
)

Stores fitness information in the transposition table.

Parameters
[in]ha (possibly) new individual's signature to be stored in the table
[in]fitnessthe fitness of the individual

Definition at line 102 of file cache.cc.

◆ is_valid()

bool vita::cache::is_valid ( ) const
Returns
true if the object passes the internal consistency check

Definition at line 180 of file cache.cc.

◆ load()

bool vita::cache::load ( std::istream &  in)
Parameters
[in]ininput stream
Returns
true if the object is correctly loaded
Note
If the load operation isn't successful the current object isn't changed.

Definition at line 121 of file cache.cc.

◆ save()

bool vita::cache::save ( std::ostream &  out) const
Parameters
[out]outoutput stream
Returns
true if the object was saved correctly

Definition at line 155 of file cache.cc.


The documentation for this class was generated from the following files: