ReFRACtor
FullPhysics::ArrayAdVectorCache< K, T, D > Class Template Reference

Caches ArrayAd objects using a std::vector. More...

#include <array_ad_cache.h>

+ Inheritance diagram for FullPhysics::ArrayAdVectorCache< K, T, D >:
+ Collaboration diagram for FullPhysics::ArrayAdVectorCache< K, T, D >:

Public Member Functions

 ArrayAdVectorCache (int prealloc_size=0)
 Optionally pass a preallocation size. More...
 
virtual std::vector< std::pair< K, ArrayAd< T, D > > > cached_data () const
 Obtain cached data up to last point inserted. More...
 
virtual void clear ()
 clear simply resets the location of of the cache index by default without clearing any memory. More...
 
virtual void clear (bool clear_memory)
 Clear the vector as well as reset insertion location. More...
 
virtual void erase (const K &key)
 Removes a specific item from the vector This call can be expensive since it will need to shift items down. More...
 
std::vector< std::pair< K, ArrayAd< T, D > > >::const_iterator find (const K &key) const
 Finds the requested item using a STL lower bound call. More...
 
std::vector< std::pair< K, ArrayAd< T, D > > >::iterator find (const K &key)
 Finds the requested item using a STL lower bound call. More...
 
virtual void insert (const K &key, const ArrayAd< T, D > &value)
 Insert the cached item into the currently available slot in the vector or creates a new slot. More...
 
virtual bool is_valid (const K &key) const
 
virtual ArrayAd< T, D > operator[] (const K &key) const
 Retrieve a specific key and error if it is no keys are available However, will return the closest one available. More...
 

Detailed Description

template<class K, class T, int D>
class FullPhysics::ArrayAdVectorCache< K, T, D >

Caches ArrayAd objects using a std::vector.

This class should be used when the cached data is calculated in order and will be used again in order. Using operator[] is slower than the same one from a map cache.

The cached data is available through a method so it can be looped over. Which is what you want anyways.

Additional speed can be obtained if the size of the data to cache is known beforehand and that size is passed during construction. The class will not release memory unless it is specifically instructed and will reuse the vector on subsequent clears and insertion cycles.

Definition at line 86 of file array_ad_cache.h.

Constructor & Destructor Documentation

◆ ArrayAdVectorCache()

template<class K , class T , int D>
FullPhysics::ArrayAdVectorCache< K, T, D >::ArrayAdVectorCache ( int  prealloc_size = 0)
inline

Optionally pass a preallocation size.

Definition at line 91 of file array_ad_cache.h.

Member Function Documentation

◆ cached_data()

template<class K , class T , int D>
virtual std::vector<std::pair<K, ArrayAd<T, D> > > FullPhysics::ArrayAdVectorCache< K, T, D >::cached_data ( ) const
inlinevirtual

Obtain cached data up to last point inserted.

Definition at line 177 of file array_ad_cache.h.

◆ clear() [1/2]

template<class K , class T , int D>
virtual void FullPhysics::ArrayAdVectorCache< K, T, D >::clear ( )
inlinevirtual

clear simply resets the location of of the cache index by default without clearing any memory.

Implements FullPhysics::ArrayAdCache< K, T, D >.

Definition at line 163 of file array_ad_cache.h.

◆ clear() [2/2]

template<class K , class T , int D>
virtual void FullPhysics::ArrayAdVectorCache< K, T, D >::clear ( bool  clear_memory)
inlinevirtual

Clear the vector as well as reset insertion location.

Definition at line 169 of file array_ad_cache.h.

◆ erase()

template<class K , class T , int D>
virtual void FullPhysics::ArrayAdVectorCache< K, T, D >::erase ( const K &  key)
inlinevirtual

Removes a specific item from the vector This call can be expensive since it will need to shift items down.

Implements FullPhysics::ArrayAdCache< K, T, D >.

Definition at line 151 of file array_ad_cache.h.

◆ find() [1/2]

template<class K , class T , int D>
std::vector<std::pair<K, ArrayAd<T, D> > >::const_iterator FullPhysics::ArrayAdVectorCache< K, T, D >::find ( const K &  key) const
inline

Finds the requested item using a STL lower bound call.

Definition at line 97 of file array_ad_cache.h.

◆ find() [2/2]

template<class K , class T , int D>
std::vector<std::pair<K, ArrayAd<T, D> > >::iterator FullPhysics::ArrayAdVectorCache< K, T, D >::find ( const K &  key)
inline

Finds the requested item using a STL lower bound call.

Definition at line 109 of file array_ad_cache.h.

◆ insert()

template<class K , class T , int D>
virtual void FullPhysics::ArrayAdVectorCache< K, T, D >::insert ( const K &  key,
const ArrayAd< T, D > &  value 
)
inlinevirtual

Insert the cached item into the currently available slot in the vector or creates a new slot.

Implements FullPhysics::ArrayAdCache< K, T, D >.

Definition at line 138 of file array_ad_cache.h.

◆ is_valid()

template<class K , class T , int D>
virtual bool FullPhysics::ArrayAdVectorCache< K, T, D >::is_valid ( const K &  key) const
inlinevirtual

Implements FullPhysics::ArrayAdCache< K, T, D >.

Definition at line 131 of file array_ad_cache.h.

◆ operator[]()

template<class K , class T , int D>
virtual ArrayAd<T, D> FullPhysics::ArrayAdVectorCache< K, T, D >::operator[] ( const K &  key) const
inlinevirtual

Retrieve a specific key and error if it is no keys are available However, will return the closest one available.

Implements FullPhysics::ArrayAdCache< K, T, D >.

Definition at line 122 of file array_ad_cache.h.


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

Copyright © 2017, California Institute of Technology.
ALL RIGHTS RESERVED.
U.S. Government Sponsorship acknowledged.
Generated Fri Aug 24 2018 15:44:12