Here is a summary of my question:
I have a particular class
there is a function which generates objects of this class:Code:class Combination;
there is a function which evaluates Combination objects acc. to some criteria:Code:Combination makeCombination();
it is possible that makeCombination() is going to generate same Combination objects and get into a loop. So I want to make a 'history' of previously created Combo objects and check if an object is in history before i pass it to score function. History should store the last max_size objects generated.Code:int scoreCombination(Combination combo);
now I could do it like this:
and then search for it something like this:Code:std::list<Combination> history; void add_to_history(Combination c) { if(history.size() == max_size) { history.pop_front(); } history.push_back(c); }
this is ok, but find() can work a bit slow with lists and it could become a problem if max_size gets large. If i declare history as std::set<Combination> searching through it will be a bit faster but I have no idea how to track which elements have been inserted into the set first. Any ideas for a more efficient way of implementing what I want to do would be much appreciated.Code:Combination c; std::list<Combination>::iterator it; it = find(history.begin(), history.end(), c); if(it != history.end()) int score = scoreCombination(c);
Thanks



LinkBack URL
About LinkBacks


