Commit 5f9c881f authored by Davis King's avatar Davis King

Made remove_duplicates() take any type rather than just being limited to

rectangle.
parent 64fb2312
...@@ -595,22 +595,22 @@ namespace dlib ...@@ -595,22 +595,22 @@ namespace dlib
// ---------------------------------------------------------------------------------------- // ----------------------------------------------------------------------------------------
template <typename alloc> template <typename T, typename alloc>
void remove_duplicates ( void remove_duplicates (
std::vector<rectangle,alloc>& rects std::vector<T,alloc>& items
) )
{ {
std::sort(rects.begin(), rects.end(), std::less<rectangle>()); std::sort(items.begin(), items.end(), std::less<T>());
unsigned long num_unique = 1; unsigned long num_unique = 1;
for (unsigned long i = 1; i < rects.size(); ++i) for (unsigned long i = 1; i < items.size(); ++i)
{ {
if (rects[i] != rects[i-1]) if (items[i] != items[i-1])
{ {
rects[num_unique++] = rects[i]; items[num_unique++] = items[i];
} }
} }
if (rects.size() != 0) if (items.size() != 0)
rects.resize(num_unique); items.resize(num_unique);
} }
// ---------------------------------------------------------------------------------------- // ----------------------------------------------------------------------------------------
......
...@@ -105,16 +105,20 @@ namespace dlib ...@@ -105,16 +105,20 @@ namespace dlib
// ---------------------------------------------------------------------------------------- // ----------------------------------------------------------------------------------------
template < template <
template T,
typename alloc typename alloc
> >
void remove_duplicates ( void remove_duplicates (
std::vector<rectangle,alloc>& rects std::vector<T,alloc>& items
); );
/*! /*!
requires
- T is comparable via operator != and std::less.
ensures ensures
- This function finds any duplicate rectangles in rects and removes the extra - This function finds any duplicate objects in items and removes the extra
instances. This way, the result is that rects contains only unique rectangle instances. This way, the result is that items contains only unique
instances. instances. It does this by sorting items and removing neighboring elements
unless they compare != according to operator !=.
!*/ !*/
// ---------------------------------------------------------------------------------------- // ----------------------------------------------------------------------------------------
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment