30 #include "../../common/STLUtils.h"
31 #include "../cache/AbstractCachePolicy.h"
32 #include "../cache/AbstractCachePolicyFactory.h"
33 #include "../loader/AbstractGraphLoaderStrategy.h"
63 std::map<int, GraphData*>::iterator itMap = m_graphDataMap.begin();
65 while(itMap != m_graphDataMap.end())
69 te::graph::GraphData::VertexMap::iterator it = d->
getVertexMap().find(
id);
73 m_policy->accessed(d->
getId());
82 if(m_dataManager != 0)
84 m_dataManager->loadGraphDataByVertexId(
id,
this);
86 return checkCacheByVertexId(
id);
95 std::map<int, GraphData*>::iterator itMap = m_graphDataMap.begin();
97 while(itMap != m_graphDataMap.end())
101 te::graph::GraphData::EdgeMap::iterator it = d->
getEdgeMap().find(
id);
105 m_policy->accessed(d->
getId());
114 if(m_dataManager != 0)
116 m_dataManager->loadGraphDataByEdgeId(
id,
this);
118 return checkCacheByEdgeId(
id);
127 if(m_graphDataMap.empty())
129 return createGraphData();
133 std::map<int, GraphData*>::iterator itMap = m_graphDataMap.begin();
136 size_t maxSize = m_metadata->m_maxCacheSize - 1;
138 while(itMap != m_graphDataMap.end())
153 m_policy->update(gdId);
155 return m_graphDataMap[gdId];
159 if(m_graphDataMap.size() < m_metadata->m_maxVecCacheSize)
161 return createGraphData();
165 if(m_graphDataMap.size() == m_metadata->m_maxVecCacheSize)
169 m_policy->toRemove(idxToRemove);
175 removeGraphData(d->
getId());
177 return createGraphData();
185 if(m_graphDataMap.size() == m_metadata->m_maxVecCacheSize)
192 m_graphDataMap.insert(std::map<int, GraphData*>::value_type(d->
getId(), d));
194 m_policy->added(d->
getId());
201 std::map<int, GraphData*>::iterator it = m_graphDataMap.find(idx);
203 if(it == m_graphDataMap.end())
211 m_graphDataMap.erase(it);
218 m_dataManager->saveGraphData(data);
224 std::map<int, GraphData*>::iterator it = m_graphDataMap.begin();
226 while(it != m_graphDataMap.end())
234 m_dataManager->saveGraphData(d);
243 m_graphDataMap.clear();
249 std::map<int, GraphData*>::iterator itMap = m_graphDataMap.begin();
251 while(itMap != m_graphDataMap.end())
255 te::graph::GraphData::VertexMap::iterator it = d->
getVertexMap().find(
id);
259 m_policy->accessed(d->
getId());
273 std::map<int, GraphData*>::iterator itMap = m_graphDataMap.begin();
275 while(itMap != m_graphDataMap.end())
279 te::graph::GraphData::EdgeMap::iterator it = d->
getEdgeMap().find(
id);
283 m_policy->accessed(d->
getId());
296 int id = m_graphDataCounter;
298 ++m_graphDataCounter;
void clearCache()
Used to remove from memory all elements loaded.
~GraphCache()
Default destructor.
AbstractCachePolicy * m_policy
Cache policy to control the cache in memory.
te::graph::GraphMetadata * getMetadata()
It returns a pointer to a class that describes the graph metadata.
VertexMap & getVertexMap()
It returns the the vertex map.
GraphData * getGraphDataByEdgeId(int id)
Get a graph data from vector using a edge id information. if not found a new graph data has to be loa...
int getGraphDataId()
Protected function used to define a new value of Id to a graph data.
int getId()
Get data identifier.
void removeGraphData(int idx)
Used to remove a graph data from cache.
GraphData * checkCacheByVertexId(int id)
This functions check in cache if the vertex element with a given id was alredy in memory...
This class define a important struct used to group a map of vertex and edges. A flag is used to indic...
GraphMetadata * m_metadata
Graph metadata information.
AbstractGraphLoaderStrategy * getLoaderStrategy()
Function used to get the current loader strategy.
This class is used to set the main functions of a cache policy.
GraphData * getGraphData()
Get a graph data.
This class defines a interface to access the graph elements inside a data source. Its use a implement...
GraphData * createGraphData()
Creates a new graph data structure.
void saveGraphData(GraphData *data)
Save the graph data structure inside a data source.
EdgeMap & getEdgeMap()
It returns the the edge map.
Class used to manager the graph data elements. This class uses a cache policy to control the elements...
GraphData * checkCacheByEdgeId(int id)
This functions check in cache if the edge element with a given id was alredy in memory.
#define TE_DEFAULT_CACHE_POLICY_TYPE
This definition is used to set the default cache policy.
This class define a important struct used to group a map of vertex and edges. A flag is used to indic...
bool isDirty()
Used to check the graph data state.
GraphDataManager * m_dataManager
Used to load and save GraphData information from a DataSource.
GraphData * getGraphDataByVertexId(int id)
Get a graph data from vector using a vertex id information. if not found a new graph data has to be l...
GraphCache(AbstractCachePolicy *cp, GraphDataManager *dm)
Default constructor.
void FreeContents(boost::unordered_map< K, V * > &m)
This function can be applied to a map of pointers. It will delete each pointer in the map...
int m_graphDataCounter
Graph data identifier counter.
static AbstractCachePolicy * make()
It creates and returns default cache policy.