aboutsummaryrefslogtreecommitdiff
path: root/Miscellaneous/util.cpp
blob: d903c1ebf66189cfb3306347c55b5243cde15396 (plain)
1
2
3
4
5
6
7
template <class BidirectionalIterator> // Coordinate compression
void compress(BidirectionalIterator first, BidirectionalIterator last) {
	vector<auto> tmp(first, last);
	sort(tmp.begin(), tmp.end());
	tmp.resize(unique(tmp.begin(), tmp.end()) - tmp.begin());
	for (auto it = first; it != last; it++) *it = lower_bound(tmp.begin(), tmp.end(), *it) - tmp.begin();
}