19 #ifndef SNARK_PERCEPTION_ALGORITHMS_ALGORITHMS_VOTEDTRACKING_HEADER_GUARD_
20 #define SNARK_PERCEPTION_ALGORITHMS_ALGORITHMS_VOTEDTRACKING_HEADER_GUARD_
25 #include <boost/optional.hpp>
48 template <
typename It,
typename Id,
typename F >
49 Id
voted_tracking( It begin, It end, F GetPreviousId, Id vacantId );
53 template <
typename P >
inline bool comparePairs(
const P& i,
const P& j ) {
return i.second < j.second; }
57 template <
typename It,
typename Id,
typename F >
60 typedef std::map< Id, std::size_t > Map;
61 typedef std::pair< Id, std::size_t > Pair;
63 for( It it = begin; it != end; ++it )
65 boost::optional< Id > previous = getPreviousId( it );
66 if( !previous ) {
continue; }
67 std::pair< typename Map::iterator, bool > p = ids.insert( Pair( *previous, 0 ) );
68 if( !p.second ) { ++p.first->second; }
70 return ids.empty() ? vacantId
71 : std::max_element( ids.begin(), ids.end(), impl::comparePairs< Pair > )->first;
76 #endif // #ifndef SNARK_PERCEPTION_ALGORITHMS_ALGORITHMS_VOTEDTRACKING_HEADER_GUARD_