9 #ifndef __DIADES__UTILS__INFOMANAGER__HH__ 10 #define __DIADES__UTILS__INFOMANAGER__HH__ 14 #include<unordered_map> 50 template<
typename _Info,
52 typename _NullInfo = NullValue<_Info>,
53 typename _NullInfoId = NullValue<_InfoId>,
54 typename _Hash = std::hash<_Info> >
107 return "Diades::Utils::InfoManager";
119 using Map = std::unordered_map<size_t, std::vector<InfoId> >;
153 template<
typename _Iterator>
173 template<
typename InfoIdIterator>
216 _infoMap(
std::move(other._infoMap)),
217 _infos(
std::move(other._infos)),
218 _infoIds(
std::move(other._infoIds)){}
229 _infoMap = std::move(other._infoMap);
230 _infos = std::move(other._infos);
231 _infoIds = std::move(other._infoIds);
249 if(!(info == nullInfo))
251 auto it = _infoMap.find(
Hash()(info));
252 if(it != _infoMap.end())
254 return(std::find_if(it->second.begin(),
256 [&info,
this](
size_t index)
258 return info == _infos[index]; }))
279 return _infos.size() >
id &&
id !=
nullInfoId;
304 return infoId(info) == id;
306 if(
id >= _infos.size())
308 _infos.resize(
id + 1, nullInfo);
309 _infoIds.resize(
id + 1, nullInfoId);
313 _infoMap[
Hash()(info)].push_back(
id);
332 size_t hashInfo =
Hash()(info);
333 auto it = _infoMap.find(hashInfo);
334 if(it != _infoMap.end())
336 auto it2 = std::find_if(it->second.begin(),
338 [&info,
this](
size_t index)
340 return info == _infos[index]; });
342 if(it2 != it->second.end())
346 _infos.push_back(info);
347 _infoIds.push_back(_infos.size() - 1);
348 it->second.push_back(_infos.size() - 1);
349 return it->second.back();
351 _infos.push_back(info);
352 _infoIds.push_back(_infos.size() - 1);
353 _infoMap[hashInfo].push_back(_infos.size() - 1);
354 return _infos.size() - 1;
371 if(
id >= _infos.size())
394 Msg(
"initialise: capacity %1% is null, try capacity = 1 at least")
398 _infos.reserve(capacity);
399 _infoIds.reserve(capacity);
407 const std::vector<Info> &
420 return _infoIds.begin();
430 return _infoIds.end();
441 template<
typename InfoIdIterator>
471 return _infos.size();
495 result = (_infos[index] == manager.
_infos[index]);
InfoIdRangeInfoIterator< InfoIdIterator > infoIdRangeInfoIterator(InfoIdIterator iterator) const
std::hash< std::string > Hash
InfoManager & appendWith(const InfoManager &manager)
bool isNullId(const InfoId &infoId) const
InfoIdIterator end() const
bool setInfo(const Info &info, InfoId id)
typename std::vector< InfoId >::const_iterator InfoIdIterator
InfoManager & operator=(InfoManager &&other)
std::vector< InfoId > _infoIds
bool hasInfo(const Info &info) const
InfoManager & initialise(unsigned capacity)
bool isEquivalentTo(const InfoManager &manager) const
InfoIdIterator begin() const
bool hasInfoId(InfoId id) const
InfoManager & operator=(InfoManager const &other)
virtual ~InfoManager()=default
std::vector< Info > _infos
bool isConsistentWith(const InfoManager &manager) const
#define require(Exception, expr, message)
Namespace of the Diades project.
size_t numberOfInfos() const
const Data & operator()(const MapStructure &m, Iterator it) const
bool isNull(const Info &info) const
ConstIterator on the Net.
InfoManager & makeUnion(const InfoManager &m1, const InfoManager &m2)
std::unordered_map< size_t, std::vector< InfoId > > Map
InfoManager(InfoManager &&other)
const Info & getInfo(InfoId id) const
InfoId infoId(const Info &info)
const std::vector< Info > & storage() const
InfoManager & makeIntersection(const InfoManager &m1, const InfoManager &m2)