TTMath  0.9.4
 C++ bignum library
Data Structures | Public Member Functions
ttmath::History< ValueType > Class Template Reference

#include <ttmathobjects.h>

Public Member Functions

 History ()
 
 History (typename buffer_type::size_type new_size)
 
void Add (const ValueType &key, const ValueType &value, ErrorCode err)
 
bool Get (const ValueType &key, ValueType &value, ErrorCode &err)
 
bool Remove (const ValueType &key)
 

Detailed Description

template<class ValueType>
class ttmath::History< ValueType >

objects of the class History are used to keep values in functions which take a lot of time during calculating, for instance in the function Factorial(x)

it means that when we're calculating e.g. Factorial(1000) and the Factorial finds that we have calculated it before, the value (result) is taken from the history

Definition at line 605 of file ttmathobjects.h.

Constructor & Destructor Documentation

§ History() [1/2]

template<class ValueType>
ttmath::History< ValueType >::History ( )

default constructor default max size of the History's container is 15 items

Definition at line 634 of file ttmathobjects.h.

635  {
636  buffer_max_size = 15;
637  }

§ History() [2/2]

template<class ValueType>
ttmath::History< ValueType >::History ( typename buffer_type::size_type  new_size)

a constructor which takes another value of the max size of the History's container

Definition at line 644 of file ttmathobjects.h.

645  {
646  buffer_max_size = new_size;
647  }

Member Function Documentation

§ Add()

template<class ValueType>
void ttmath::History< ValueType >::Add ( const ValueType &  key,
const ValueType &  value,
ErrorCode  err 
)

this method adds one item into the History if the size of the container is greater than buffer_max_size the first item will be removed

Definition at line 655 of file ttmathobjects.h.

656  {
657  Item item;
658  item.key = key;
659  item.value = value;
660  item.err = err;
661 
662  buffer.insert( buffer.end(), item );
663 
664  if( buffer.size() > buffer_max_size )
665  buffer.erase(buffer.begin());
666  }

§ Get()

template<class ValueType>
bool ttmath::History< ValueType >::Get ( const ValueType &  key,
ValueType &  value,
ErrorCode err 
)

this method checks whether we have an item which has the key equal 'key'

if there's such item the method sets the 'value' and the 'err' and returns true otherwise it returns false and 'value' and 'err' remain unchanged

Definition at line 676 of file ttmathobjects.h.

677  {
678  typename buffer_type::iterator i = buffer.begin();
679 
680  for( ; i != buffer.end() ; ++i )
681  {
682  if( i->key == key )
683  {
684  value = i->value;
685  err = i->err;
686  return true;
687  }
688  }
689 
690  return false;
691  }

§ Remove()

template<class ValueType>
bool ttmath::History< ValueType >::Remove ( const ValueType &  key)

this methods deletes an item

we assume that there is only one item with the 'key' (this methods removes the first one)

Definition at line 700 of file ttmathobjects.h.

701  {
702  typename buffer_type::iterator i = buffer.begin();
703 
704  for( ; i != buffer.end() ; ++i )
705  {
706  if( i->key == key )
707  {
708  buffer.erase(i);
709  return true;
710  }
711  }
712 
713  return false;
714  }

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