#include <algorithm>
+#include <set>
#include "buildinfo.h"
using namespace std;
namespace {
/** Removes any duplicate entries from a list, leaving only the first one. The
-order of other elements is preserved. O(n²) efficiency. */
-void unique(StringList &l)
+order of other elements is preserved. O(nlogn) efficiency. */
+template<typename T>
+void unique(list<T> &l)
{
- for(StringList::iterator i=l.begin(); i!=l.end(); ++i)
- for(StringList::iterator j=i; j!=l.end();)
- {
- if(j!=i && *j==*i)
- j = l.erase(j);
- else
- ++j;
- }
+ set<T> seen;
+ for(typename list<T>::iterator i=l.begin(); i!=l.end(); )
+ {
+ if(seen.count(*i))
+ l.erase(i++);
+ else
+ seen.insert(*i++);
+ }
}
}