#include <FlyWeight.h>
Public Types | |||||||
typedef int | Proxy_t | ||||||
typedef std::map< ValueType, Proxy_t > | ValueToProxyMap | ||||||
typedef std::vector< ValueType > | ProxyToValueMap | ||||||
Public Member Functions | |||||||
FlyWeightLists () | |||||||
bool | empty () const | ||||||
FlyWeight | |||||||
A generic flyweight to store relatively bulky objects that are massively re-used, such as the source IDs in each TAP / TDP. Objects such as TAPs and TDPs often contain largely repeated data such as the source ID for all pulses coming from the same algorithm applied to the same detector channel. To reduce the redundancy and therefore save memory and some processing time, this class implements a simple version of the flyweight pattern, which replaces each different value with an int, but provides a similar interface to the object that it wraps. When we want to store a new value, it is searched for in the ProxyToValueMap and the index identifying where it is is saved is used instead. If the value has not been used already, it is added to the list of values
| |||||||
int | GetProxy (const ValueType &v) | ||||||
const ValueType & | GetValue (const Proxy_t &v) | ||||||
void | DumpTable () const | ||||||
Private Member Functions | |||||||
ClassDef (FlyWeightLists, 1) | |||||||
Private Attributes | |||||||
ProxyToValueMap | sProxyToVals | ||||||
ValueToProxyMap | sValsToProxies |
Definition at line 13 of file FlyWeight.h.
typedef int FlyWeightLists< ValueType, UniqueTag >::Proxy_t |
Definition at line 15 of file FlyWeight.h.
typedef std::vector<ValueType> FlyWeightLists< ValueType, UniqueTag >::ProxyToValueMap |
Definition at line 18 of file FlyWeight.h.
typedef std::map<ValueType,Proxy_t> FlyWeightLists< ValueType, UniqueTag >::ValueToProxyMap |
Definition at line 17 of file FlyWeight.h.
FlyWeightLists< ValueType, UniqueTag >::FlyWeightLists | ( | ) | [inline] |
Definition at line 15 of file FlyWeight.h.
FlyWeightLists< ValueType, UniqueTag >::ClassDef | ( | FlyWeightLists< ValueType, UniqueTag > | , | |
1 | ||||
) | [private] |
void FlyWeightLists< ValueType, UniqueTag >::DumpTable | ( | ) | const [inline] |
Definition at line 154 of file FlyWeight.h.
References FlyWeightLists< ValueType, UniqueTag >::sProxyToVals, and FlyWeightLists< ValueType, UniqueTag >::sValsToProxies.
00154 { 00155 std::cout<<"Proxy | Value | Proxy"<<std::endl; 00156 for(unsigned i=0;i<sProxyToVals.size();i++){ 00157 std::cout<<i<<" | "<<sProxyToVals[i]<<" | "<<sValsToProxies.find(sProxyToVals[i])->second<<std::endl; 00158 } 00159 }
bool FlyWeightLists< ValueType, UniqueTag >::empty | ( | ) | const [inline] |
Definition at line 23 of file FlyWeight.h.
00023 {return sProxyToVals.empty();}
int FlyWeightLists< ValueType, UniqueTag >::GetProxy | ( | const ValueType & | v | ) | [inline] |
Definition at line 140 of file FlyWeight.h.
References FlyWeightLists< ValueType, UniqueTag >::sProxyToVals, and FlyWeightLists< ValueType, UniqueTag >::sValsToProxies.
00140 { 00141 // Is this proxy already contained in the maps 00142 typename ValueToProxyMap::const_iterator it=sValsToProxies.find(v); 00143 if(it!=sValsToProxies.end()){ 00144 return it->second; 00145 } 00146 // if it's a new kind, add the source to the hash table 00147 int proxy=sValsToProxies.size(); 00148 sValsToProxies[v]=proxy; 00149 sProxyToVals.push_back(v); 00150 return proxy; 00151 }
const ValueType & FlyWeightLists< ValueType, UniqueTag >::GetValue | ( | const Proxy_t & | v | ) | [inline] |
Definition at line 134 of file FlyWeight.h.
References FlyWeightLists< ValueType, UniqueTag >::sProxyToVals.
00135 { 00136 return sProxyToVals.at(v); 00137 }
ProxyToValueMap FlyWeightLists< ValueType, UniqueTag >::sProxyToVals [private] |
ValueToProxyMap FlyWeightLists< ValueType, UniqueTag >::sValsToProxies [private] |
Definition at line 28 of file FlyWeight.h.
Referenced by FlyWeightLists< ValueType, UniqueTag >::DumpTable(), and FlyWeightLists< ValueType, UniqueTag >::GetProxy().