8 #ifndef __DIADES__AUTOMATA__EXPERIMENTAL__EVENTSET__HH__ 9 #define __DIADES__AUTOMATA__EXPERIMENTAL__EVENTSET__HH__ 11 #include <unordered_map> 15 #include <boost/functional/hash.hpp> 16 #include <boost/dynamic_bitset.hpp> 26 namespace Experimental
56 template <
typename Block,
typename Alloc>
struct hash<
boost::dynamic_bitset<Block, Alloc> >
59 size_t operator()(boost::dynamic_bitset<Block, Alloc>
const& bs)
const 62 std::vector<Block> blocks(bs.num_blocks());
63 boost::to_block_range(bs, std::inserter(blocks, blocks.begin()));
64 boost::hash_range(seed, blocks.begin(), blocks.end());
75 namespace Experimental
89 template<
typename EventLabel,
typename EventId>
97 typedef typename std::unordered_map<EventId, size_t>
Map;
110 return "Automata::Experimental::EventSetManager";
127 _idOfEvent(mgr._idOfEvent), _eventOfId(mgr._eventOfId)
135 _idOfEvent(mgr._idOfEvent), _eventOfId(mgr._eventOfId)
173 return _idOfEvent.find(e) != _idOfEvent.end();
182 return _eventOfId.find(c) != _eventOfId.end();
193 template<
typename EventIterator>
199 return encodeRange(first, last);
211 template<
typename EventIterator>
215 while (first != last)
217 if (!hasEvent(*first))
219 encodeNoCheck(*first);
234 auto it = _idOfEvent.find(e);
235 if ( it != _idOfEvent.end())
239 return encodeNoCheck(e);
249 size_t code = _idOfEvent.size();
250 _idOfEvent[e] = code;
251 _eventOfId[code] = e;
260 EventCode
code(EventId e)
const 262 require(Exception, hasEvent(e),
263 Msg(
"code: the event %1% has no code in this manager")
265 return (_idOfEvent.find(e)->second);
276 Msg(
"event: the code %1% does not in this manager")
278 return (_eventOfId.find(c)->second);
286 return _idOfEvent.size();
298 template<
typename EventIterator>
299 EventSet
eventSet(EventIterator first, EventIterator last)
const 301 EventSet result(numberOfEncodedEvents(),
false);
302 while (first != last)
305 Msg(
"eventSet: event %1% has no code in this manager")
307 result[code(*first)] =
true;
321 std::vector<EventId> result;
322 for(
unsigned index = 0; index < eventSet.size(); ++index)
328 result.push_back(event(index));
349 EventSet result(numberOfEncodedEvents(),
false);
350 size_t code = es.find_first();
351 while (code < es.npos)
353 auto it = _idOfEvent.find(mgr.
event(code));
354 if (it != _idOfEvent.end())
356 result[it->second] =
true;
358 code = es.find_next(code);
375 require(Exception, hasEvent(e),
376 Msg(
"eventSet: event %1% has no code in this manager")
378 EventSet result(numberOfEncodedEvents(),
false);
380 result[code(e)] =
true;
391 EventSet result(numberOfEncodedEvents(),
false);
403 bool contains(
const EventSet & eSet, EventId e)
const 405 require(Exception, hasEvent(e),
406 Msg(
"contains: event %1% has no code in this manager")
408 return eSet[code(e)];
424 std::vector<EventId> events;
425 if (numberOfEncodedEvents() > 0)
427 events.reserve(numberOfEncodedEvents());
428 std::transform(_idOfEvent.begin(),
430 std::back_inserter(events),
435 std::sort(events.begin(), events.end());
438 for (
unsigned i = 0; i < events.size(); ++i)
440 _idOfEvent[events[i]] = i;
441 _eventOfId[i] = events[i];
bool contains(const EventSet &eSet, EventId e) const
std::unordered_map< EventId, size_t > Map
Map data structure that contains the encoding of the involved Events.
EventSetManager(const EventSetManager &mgr)
boost::dynamic_bitset EventSet
EventSet a simple dynamic bitset represents a set of Events.
bool hasCode(EventCode c) const
bool hasEvent(EventId e) const
EventSetManager & initialise(EventIterator first, EventIterator last)
size_t numberOfEncodedEvents() const
std::vector< EventId > decodeEventSet(const EventSet &eventSet) const
EventSet emptySet() const
EventSet eventSet(EventId e) const
std::size_t hash_value(Diades::Graph::Edge const &e)
#define require(Exception, expr, message)
Namespace of the Diades project.
size_t EventCode
EventCode the code of an Event in the EventSetManager.
std::unordered_map< size_t, EventId > _eventOfId
mapping Event->Id
EventSetManager & operator=(const EventSetManager &mgr)
EventSetManager & encodeRange(EventIterator first, EventIterator last)
EventCode code(EventId e) const
EventId event(EventCode c) const
EventSet projectEventSet(const EventSetManager &mgr, const EventSet &es)
Diades::Utils::Exception< EventSetManager > Exception
EventCode encodeNoCheck(EventId e)
EventSetManager & sortCodes()
EventCode encode(EventId e)
static string typeName()
mapping Id->Event
size_t operator()(boost::dynamic_bitset< Block, Alloc > const &bs) const
EventSetManager(EventSetManager &&mgr)
EventSet eventSet(EventIterator first, EventIterator last) const
#define assertion(Exception, expr, message)