Project

General

Profile

Feature #967

PtrVector sort

Added by Mark Messier over 8 years ago. Updated over 8 years ago.

Status:
Closed
Priority:
Normal
Assignee:
Category:
Navigation
Target version:
Start date:
02/12/2011
Due date:
% Done:

0%

Estimated time:
Scope:
Internal
Experiment:
-
SSI Package:
Duration:

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 over 8 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 over 8 years ago

  • Category set to Navigation
  • Target version set to 0.4.3

#3 Updated by Christopher Green over 8 years ago

  • Status changed from Resolved to Closed


Also available in: Atom PDF