Feature #967
PtrVector sort
Start date:
02/12/2011
Due date:
% Done:
0%
Estimated time:
Scope:
Internal
Experiment:
-
SSI Package:
Description
It would be nice to be able to pass a comparison function to the PtrVector::sort function to allow for more general sorts of the data. For example:
static bool sort_by_time(const art::Ptr<Hit>& p1, const art::Ptr<Hit>& p2)
{
return (p1->t)<(p2->t);
}
// Sort hits by time
PtrVector<Hit> hitlist;
hitlist.sort(sort_by_time);
My pseudo code it not likely completely correct, but I hope it communicates the idea.
History
#1 Updated by Marc Paterno almost 10 years ago
- Status changed from New to Resolved
- Assignee set to Marc Paterno
The PtrVector<T> template has a sort member that takes a predicate that compares two T objects, rather than two Ptr<T> objects.
For the example in the issue, the function sort_by_type should be replaced by a class SortByTime, which should have a function call operator that compares two Hit objects' "t" values:
struct SortByTime { bool operator()(Hit const& a, Hit const& b) const { return a.t < b.t; } }
should do the job.
#2 Updated by Christopher Green almost 10 years ago
- Category set to Navigation
- Target version set to 0.4.3
#3 Updated by Christopher Green almost 10 years ago
- Status changed from Resolved to Closed