comparison AgentList.h @ 16:33d0b18b2509

Allocate Agents separately on the heap and make AgentList contain pointers only (much quicker)
author Chris Cannam
date Wed, 12 Oct 2011 17:01:57 +0100
parents 887c629502a9
children 03927f6acee2
comparison
equal deleted inserted replaced
15:887c629502a9 16:33d0b18b2509
29 /** Class for maintaining the set of all Agents involved in beat tracking a piece of music. 29 /** Class for maintaining the set of all Agents involved in beat tracking a piece of music.
30 */ 30 */
31 class AgentList 31 class AgentList
32 { 32 {
33 public: 33 public:
34 typedef std::vector<Agent> Container; 34 typedef std::vector<Agent *> Container;
35 typedef Container::iterator iterator; 35 typedef Container::iterator iterator;
36 36
37 protected: 37 protected:
38 Container list; 38 Container list;
39 39
42 //!!! can we remove these again once the rest of AgentList is implemented? 42 //!!! can we remove these again once the rest of AgentList is implemented?
43 bool empty() const { return list.empty(); } 43 bool empty() const { return list.empty(); }
44 Container::iterator begin() { return list.begin(); } 44 Container::iterator begin() { return list.begin(); }
45 Container::iterator end() { return list.end(); } 45 Container::iterator end() { return list.end(); }
46 size_t size() { return list.size(); } 46 size_t size() { return list.size(); }
47 void push_back(const Agent &a) { 47 void push_back(Agent *a) {
48 list.push_back(a); 48 list.push_back(a);
49 #ifdef DEBUG_BEATROOT 49 #ifdef DEBUG_BEATROOT
50 std::cerr << " Added Ag#" << a.idNumber << ", have " << list.size() << " agent(s)" << std::endl; 50 std::cerr << " Added Ag#" << a->idNumber << ", have " << list.size() << " agent(s)" << std::endl;
51 #endif 51 #endif
52 } 52 }
53 53
54 /** Flag for choice between sum and average beat salience values for Agent scores. 54 /** Flag for choice between sum and average beat salience values for Agent scores.
55 * The use of summed saliences favours faster tempi or lower metrical levels. */ 55 * The use of summed saliences favours faster tempi or lower metrical levels. */
60 60
61 /** For the purpose of removing duplicate agents, the default JND of phase */ 61 /** For the purpose of removing duplicate agents, the default JND of phase */
62 static const double DEFAULT_BT; 62 static const double DEFAULT_BT;
63 63
64 /** Inserts newAgent into the list in ascending order of beatInterval */ 64 /** Inserts newAgent into the list in ascending order of beatInterval */
65 void add(Agent a) { 65 void add(Agent *a) {
66 add(a, true); 66 add(a, true);
67 } // add()/1 67 } // add()/1
68 68
69 /** Appends newAgent to list (sort==false), or inserts newAgent into the list 69 /** Appends newAgent to list (sort==false), or inserts newAgent into the list
70 * in ascending order of beatInterval 70 * in ascending order of beatInterval
71 * @param newAgent The agent to be added to the list 71 * @param newAgent The agent to be added to the list
72 * @param sort Flag indicating whether the list is sorted or not 72 * @param sort Flag indicating whether the list is sorted or not
73 */ 73 */
74 void add(Agent newAgent, bool sort){ 74 void add(Agent *newAgent, bool sort){
75 push_back(newAgent); 75 push_back(newAgent);
76 if (sort) this->sort(); 76 if (sort) this->sort();
77 } // add()/2 77 } // add()/2
78 78
79 /** Sorts the AgentList by increasing beatInterval. */ 79 /** Sorts the AgentList by increasing beatInterval. */