# HG changeset patch # User Chris Cannam # Date 1377705005 -3600 # Node ID 03927f6acee28197286af81d9b38ca26caa79e88 # Parent f66ed426a14f4cc775da69ecaf6033cc1fa5e429 Use a proper comparator for AgentList. The naive operator< wasn't being used because AgentList stores pointers, not values, so it was comparing by address. This was a pretty serious bug diff -r f66ed426a14f -r 03927f6acee2 AgentList.h --- a/AgentList.h Mon Oct 17 13:08:19 2011 +0100 +++ b/AgentList.h Wed Aug 28 16:50:05 2013 +0100 @@ -37,6 +37,14 @@ protected: Container list; + static bool agentComparator(const Agent *a, const Agent *b) { + if (a->beatInterval == b->beatInterval) { + return a->idNumber < b->idNumber; // ensure stable ordering + } else { + return a->beatInterval < b->beatInterval; + } + } + public: // expose some vector methods //!!! can we remove these again once the rest of AgentList is implemented? @@ -78,7 +86,21 @@ /** Sorts the AgentList by increasing beatInterval. */ void sort() { - std::sort(list.begin(), list.end()); +#ifdef DEBUG_BEATROOT + std::cerr << "sort: before: "; + for (iterator i = list.begin(); i != list.end(); ++i) { + std::cerr << (*i)->idNumber << " "; + } + std::cerr << std::endl; +#endif + std::sort(list.begin(), list.end(), agentComparator); +#ifdef DEBUG_BEATROOT + std::cerr << "sort: after: "; + for (iterator i = list.begin(); i != list.end(); ++i) { + std::cerr << (*i)->idNumber << " "; + } + std::cerr << std::endl; +#endif } // sort() /** Removes the given item from the list.