//////////////////////////////////////////////////////////////////////////////
// $Id: Permutation_tmpl.h,v 1.1.1.2 2005/01/26 13:42:20 nthiery Exp $
// Name:	Permutation_tmpl.h
// Purpose:	Class Permutation for efficient small permutations
//		(Templates implementation)
// Author:	Nicolas M. Thiéry <nthiery@mines.edu>
// Created:	2000/04
// Copyright:	LGPL
//////////////////////////////////////////////////////////////////////////////

#ifndef GLIP_PERMUTATION_TMPL_H
#define GLIP_PERMUTATION_TMPL_H

#include <GLIP/Permutation.h>

template<class L>
L GLIP::Permutation::operator () (const L &l) const {
  L result(size());
  typename L::const_iterator il(l   . begin());
  const_iterator ip(this->begin());
  for(; ip!=this->end(); ip++, il++) {
    result[*ip]=*il;
  }
  return result;
}

template<class L>
bool
GLIP::Permutation::stabilize (const L &l) const {
  typename L::const_iterator il  (l.begin());
  const_iterator ip(this->begin());
  for(; ip!=this->end(); ip++, il++) {
    if(l[*ip]!=*il) return false;
  }
  return true;
}
  
template<class L>
bool
GLIP::Permutation::decrease (const L &l) const {
  typename L::const_iterator il  (l.begin());
  const_iterator ip(this->begin());
  for(; ip!=this->end(); ip++, il++) {
    if(l[*ip]>*il) return true;
    if(l[*ip]<*il) return false;
  }
  return false;
}

template<class T>
bool
GLIP::Permutation::decrease (const SmallList<T> &l) const {
  typename SmallList<T>::const_iterator data(l.begin());
  typename SmallList<T>::const_iterator il  (l.begin());
  const_iterator ip(this->begin());
  for(; ip!=this->end(); ip++, il++) {
    if(data[*ip]>*il) return true;
    if(data[*ip]<*il) return false;
  }
  return false;
}

#endif	/* GLIP_PERMUTATION_TMPL_H */

// Local Variables: 
// mode: c++
// End:
