Skip to content
Snippets Groups Projects
Commit 461827ec authored by Wenzel Jakob's avatar Wenzel Jakob
Browse files

preserve order in ref_vector::ensureUnique

parent 5a6be59f
No related branches found
No related tags found
No related merge requests found
......@@ -21,6 +21,7 @@
#define __MITSUBA_CORE_REF_H_
#include "util.h"
#include <set>
MTS_NAMESPACE_BEGIN
......@@ -148,10 +149,21 @@ public:
ref_vector(size_t size) : parent_type(size) {}
ref_vector(const ref_vector &vec) : parent_type(vec) {}
/// Remove all duplicates (may change the order)
/// Remove all duplicates without changing the order
inline void ensureUnique() {
std::sort(this->begin(), this->end(), ref_comparator<T>());
this->erase(std::unique(this->begin(), this->end()), this->end());
std::set<T *> seen;
typename parent_type::iterator it1 = this->begin(), it2 = this->begin();
for (; it1 < this->end(); ++it1) {
if (seen.find(it1->get()) != seen.end())
continue;
seen.insert(it1->get());
if (it1 != it2)
*it2++ = *it1;
else
it2++;
}
this->erase(it2, this->end());
}
/// Check if a certain pointer is contained in the vector
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment