8#ifndef FMToutputnodecache_H
9#define FMToutputnodecache_H
13#include <unordered_map>
15#include <boost/serialization/serialization.hpp>
16#include <boost/serialization/map.hpp>
17#include <boost/serialization/vector.hpp>
25 template <
class tvdescriptor,
class titerator>
29 template<
class Archive>
30 void serialize(Archive& ar,
const unsigned int version)
32 ar & BOOST_SERIALIZATION_NVP(inmemorynodes);
34 ar & BOOST_SERIALIZATION_NVP(searchtree);
36 std::vector<tvdescriptor>inmemorynodes;
37 titerator
const * beginit;
38 titerator
const * endit;
40 mutable std::map<Core::FMToutputsource,std::vector<tvdescriptor>>searchtree;
41 typedef typename std::map<Core::FMToutputsource,std::vector<tvdescriptor>>::const_iterator notecacheit;
42 const std::vector<tvdescriptor>& getcleandescriptors(
const Core::FMToutputnode& targetnode,
const std::vector<Core::FMTaction>& actions,
43 const std::vector<Core::FMTtheme>&themes,
bool& exactnode)
const
47 typename std::map<Core::FMToutputsource, std::vector<tvdescriptor>>::const_iterator parent = this->getparentnode(targetnode, actions, exactnode);
51 return parent->second;
55 std::vector<tvdescriptor> cleaned;
58 if (parent != searchtree.end())
60 cleaned = parent->second;
62 getactionrebuild(targetnode, actions, cleaned, exactnode);
65 std::vector<tvdescriptor>toremove;
73 for (
typename std::map<
Core::FMToutputsource, std::vector<tvdescriptor>>::const_reverse_iterator sit = searchtree.rbegin();
74 sit != searchtree.rend(); sit++)
80 toremove.insert(toremove.end(), sit->second.begin(), sit->second.end());
83 if (!toremove.empty())
86 std::vector<tvdescriptor>difference;
87 std::sort(toremove.begin(), toremove.end());
88 std::set_difference(cleaned.begin(), cleaned.end(),
89 toremove.begin(), toremove.end(), std::inserter(difference, difference.begin()));
93 std::pair<notecacheit, bool> returniterator;
95 return (returniterator.first)->second;
98 const std::vector<Core::FMTaction>& actions,
99 std::vector<tvdescriptor>& cleaned,
100 bool& exactnode)
const
104 if (!actionname.empty() && !aggregatesptr.empty())
106 std::map<std::string, std::vector< notecacheit>>potentials;
109 potentials[attributeptr->getname()] = std::vector< notecacheit>();
111 for (notecacheit sit = searchtree.begin();
112 sit != searchtree.end(); sit++)
114 if (sit->first.issubsetof(targetnode.
source, actions))
116 const std::string nodeaction = sit->first.getaction();
117 potentials[nodeaction].push_back(sit);
122 if (potentials.at(attributeptr->getname()).empty())
127 typename std::vector< notecacheit>::const_iterator testting = potentials.begin()->second.begin();
128 while (testting != potentials.begin()->second.end())
131 std::vector<tvdescriptor>finalselection((*testting)->second);
132 size_t insertingdone = 1;
133 for (
const auto& attribute : potentials)
137 for (notecacheit it : potentials.at(attribute.first))
139 if ((*testting)->first.issamebutdifferentaction(it->first))
141 finalselection.insert(finalselection.end(), it->second.begin(), it->second.end());
151 if (insertingdone == potentials.size())
153 std::sort(finalselection.begin(), finalselection.end());
155 finalselection.erase(std::unique(finalselection.begin(), finalselection.end()),finalselection.end());
156 if ((*testting)->first.issamebutdifferentaction(targetnode.
source))
159 cleaned = finalselection;
162 std::vector<tvdescriptor>intersection;
163 std::set_intersection(cleaned.begin(), cleaned.end(),
164 finalselection.begin(), finalselection.end(), std::inserter(intersection, intersection.begin()));
165 cleaned = intersection;
174 notecacheit getparentnode(
const Core::FMToutputnode& targetnode,
const std::vector<Core::FMTaction>& actions,
bool& exactnode)
const
176 notecacheit parentit = searchtree.find(targetnode.
source);
177 if (parentit != searchtree.end())
182 parentit = searchtree.begin();
184 while (parentit != searchtree.end())
192 return searchtree.end();
205 inmemorynodes(initialnodes), beginit(nullptr), endit(nullptr), searchtree()
207 inmemorynodes.shrink_to_fit();
208 std::sort(inmemorynodes.begin(),inmemorynodes.end());
212 inmemorynodes(), beginit(&first), endit(&last), searchtree()
223 searchtree.erase(node.
source);
228 size_t largestsize = 0;
229 unsigned long long removedmemory = 0;
230 notecacheit largestiterator = searchtree.end();
231 for (
typename std::map<
Core::FMToutputsource, std::vector<tvdescriptor>>::iterator mapit = searchtree.begin(); mapit != searchtree.end(); mapit++)
233 size_t sizeofvec = mapit->second.size();
234 if (sizeofvec > largestsize)
236 largestsize = mapit->second.size();
237 largestiterator = mapit;
241 if (largestiterator != searchtree.end())
243 removedmemory = largestsize *
sizeof(tvdescriptor);
245 searchtree.erase(largestiterator);
247 return removedmemory;
250 const std::vector<Core::FMTtheme>&themes,
bool& exactvecticies)
const
252 return this->getcleandescriptors(targetnode, actions, themes, exactvecticies);
256 searchtree[targetnode.
source] = verticies;
257 searchtree[targetnode.
source].shrink_to_fit();
264 inmemorynodes.clear();
267 void rebase(
const titerator& beginofdevs,
const titerator& endofdevs)
269 beginit = &beginofdevs;
274 if (beginit==
nullptr)
276 if (inmemorynodes.size() < rhs.inmemorynodes.size())
278 inmemorynodes = rhs.inmemorynodes;
282 searchtree.insert(rhs.searchtree.begin(), rhs.searchtree.end());
287 if (beginit!=
nullptr)
289 for (titerator it = *beginit; it != *endit; ++it)
291 refvecs.push_back(*it);
293 refvecs.shrink_to_fit();
294 std::sort(refvecs.begin(), refvecs.end());
297 refvecs = inmemorynodes;
Definition: FMTaction.hpp:42
Definition: FMTaction.hpp:327
std::vector< const FMTaction * > getallaggregates(const std::vector< FMTaction > &actions, bool aggregateonly=false) const
Definition: FMTmask.hpp:96
bool isnotthemessubset(const FMTmask &rhs, const std::vector< FMTtheme > &themes) const
Definition: FMToutputnode.hpp:20
FMToutputsource source
Definition: FMToutputnode.hpp:22
Definition: FMToutputsource.hpp:40
const std::string & getaction() const
Definition: FMToutputsource.hpp:102
bool issubsetof(const FMToutputsource &rhs, const std::vector< Core::FMTaction > &actions) const
const FMTmask & getmask() const
Definition: FMToutputsource.hpp:92
Definition: FMToutputnodecache.hpp:27
void insert(const FMToutputnodecache &rhs)
Definition: FMToutputnodecache.hpp:272
void setvalidverticies(const Core::FMToutputnode &targetnode, const std::vector< tvdescriptor > &verticies) const
Definition: FMToutputnodecache.hpp:254
~FMToutputnodecache()=default
void pushtovector(std::vector< tvdescriptor > &refvecs) const
Definition: FMToutputnodecache.hpp:285
void rebase(const titerator &beginofdevs, const titerator &endofdevs)
Definition: FMToutputnodecache.hpp:267
void clear()
Definition: FMToutputnodecache.hpp:259
FMToutputnodecache & operator=(const FMToutputnodecache &rhs)=default
FMToutputnodecache(const std::vector< tvdescriptor > &initialnodes)
Definition: FMToutputnodecache.hpp:204
FMToutputnodecache(const FMToutputnodecache &rhs)=default
friend class boost::serialization::access
Definition: FMToutputnodecache.hpp:28
void erasenode(const Core::FMToutputnode &node)
Definition: FMToutputnodecache.hpp:221
FMToutputnodecache(const titerator &first, const titerator &last)
Definition: FMToutputnodecache.hpp:211
const std::vector< tvdescriptor > & getverticies(const Core::FMToutputnode &targetnode, const std::vector< Core::FMTaction > &actions, const std::vector< Core::FMTtheme > &themes, bool &exactvecticies) const
Definition: FMToutputnodecache.hpp:249
FMToutputnodecache()=default
unsigned long long removelargest()
Definition: FMToutputnodecache.hpp:226
Namespace for using/building unidirectional graphs in FMT.
Definition: FMTareaparser.hpp:31