optimize other all comparison operators

This commit is contained in:
Mathieu Lacage
2006-12-12 14:31:16 +01:00
parent cd7c70b0a1
commit 873367522a
7 changed files with 55 additions and 34 deletions

View File

@@ -54,8 +54,9 @@ private:
uint32_t Last (void) const;
inline bool IsRoot (uint32_t id) const;
inline bool IsBottom (uint32_t id) const;
inline bool IsLess (uint32_t a, uint32_t b);
inline uint32_t Smallest (uint32_t a, uint32_t b);
inline bool IsLower (Scheduler::EventKey const*a, Scheduler::EventKey const*b) const;
inline bool IsLess (uint32_t a, uint32_t b) const;
inline uint32_t Smallest (uint32_t a, uint32_t b) const;
inline void Exch (uint32_t a, uint32_t b);
void BottomUp (void);

View File

@@ -31,14 +31,30 @@ SchedulerList::SchedulerList ()
SchedulerList::~SchedulerList ()
{}
bool
SchedulerList::IsLower (Scheduler::EventKey const*a, Scheduler::EventKey const*b) const
{
if (a->m_ns < b->m_ns)
{
return true;
}
else if (a->m_ns == b->m_ns &&
a->m_uid < b->m_uid)
{
return true;
}
else
{
return false;
}
}
EventId
SchedulerList::RealInsert (EventImpl *event, Scheduler::EventKey key)
{
Scheduler::EventKeyCompare compare;
for (EventsI i = m_events.begin (); i != m_events.end (); i++)
{
if (compare (key, i->second))
if (IsLower (&key, &i->second))
{
m_events.insert (i, std::make_pair (event, key));
return EventId (event, key.m_ns, key.m_uid);

View File

@@ -46,6 +46,8 @@ class SchedulerList : public Scheduler {
virtual EventImpl *RealRemove (EventId ev, Scheduler::EventKey *key);
virtual bool RealIsValid (EventId id);
inline bool IsLower (Scheduler::EventKey const*a, Scheduler::EventKey const*b) const;
typedef std::list<std::pair<EventImpl*, EventKey> > Events;
typedef std::list<std::pair<EventImpl*, EventKey> >::iterator EventsI;
Events m_events;

View File

@@ -43,6 +43,29 @@ SchedulerMap::SchedulerMap ()
SchedulerMap::~SchedulerMap ()
{}
/* Note the invariants which this function must provide:
* - irreflexibility: f (x,x) is false)
* - antisymmetry: f(x,y) = !f(y,x)
* - transitivity: f(x,y) and f(y,z) => f(x,z)
*/
bool
SchedulerMap::EventKeyCompare::operator () (struct EventKey a, struct EventKey b)
{
if (a.m_ns < b.m_ns)
{
return true;
}
else if (a.m_ns == b.m_ns && a.m_uid < b.m_uid)
{
return true;
}
else
{
return false;
}
}
EventId
SchedulerMap::RealInsert (EventImpl *event, Scheduler::EventKey key)

View File

@@ -45,9 +45,15 @@ private:
virtual EventImpl *RealRemove (EventId ev, Scheduler::EventKey *key);
virtual bool RealIsValid (EventId id);
typedef std::map<Scheduler::EventKey, EventImpl*, Scheduler::EventKeyCompare> EventMap;
typedef std::map<Scheduler::EventKey, EventImpl*, Scheduler::EventKeyCompare>::iterator EventMapI;
typedef std::map<Scheduler::EventKey, EventImpl*, Scheduler::EventKeyCompare>::const_iterator EventMapCI;
class EventKeyCompare {
public:
bool operator () (struct EventKey a, struct EventKey b);
};
typedef std::map<Scheduler::EventKey, EventImpl*, SchedulerMap::EventKeyCompare> EventMap;
typedef std::map<Scheduler::EventKey, EventImpl*, SchedulerMap::EventKeyCompare>::iterator EventMapI;
typedef std::map<Scheduler::EventKey, EventImpl*, SchedulerMap::EventKeyCompare>::const_iterator EventMapCI;
EventMap m_list;
uint32_t m_uid;

View File

@@ -27,29 +27,6 @@ namespace ns3 {
Scheduler::~Scheduler ()
{}
/* Note the invariants which this function must provide:
* - irreflexibility: f (x,x) is false)
* - antisymmetry: f(x,y) = !f(y,x)
* - transitivity: f(x,y) and f(y,z) => f(x,z)
*/
bool
Scheduler::EventKeyCompare::operator () (struct EventKey a, struct EventKey b)
{
if (a.m_ns < b.m_ns)
{
return true;
}
else if (a.m_ns == b.m_ns && a.m_uid < b.m_uid)
{
return true;
}
else
{
return false;
}
}
EventId
Scheduler::Insert (EventImpl *event, struct EventKey key)
{

View File

@@ -58,10 +58,6 @@ class Scheduler {
uint64_t m_ns;
uint32_t m_uid;
};
class EventKeyCompare {
public:
bool operator () (struct EventKey a, struct EventKey b);
};
virtual ~Scheduler () = 0;