LA_library/permutation.h

10 lines
236 B
C
Raw Normal View History

2005-09-08 12:23:45 +02:00
template<typename T>
const NRVec<T> inversepermutation(const NRVec<T> &p, const T offset=0)
{
int n=p.size();
NRVec<T> q(n);
if(!offset) for(int i=0; i<n; ++i) q[p[i]]=i;
else for(int i=0; i<n; ++i) q[p[i]-offset]=i+offset;
return q;
}