Exemplo n.º 1
0
 /*  Generate next permutation
  *
  *  If the size of the permutation is smaller than the size of the
  *  pool, we may have to iterate multiple times
  */
 permutations_iterator& operator++()
 {
     if(_size!=pool.size()) {
         // Slow path, the iterator is a "view" of a prefix smaller
         // than the the pool size
         // FIXME a better implementation would be to avoid
         // std::next_permutation, but only in the slow path
         types::list<int> prev_permut(curr_permut.begin(),
                 curr_permut.begin()+_size);
         types::list<int> new_permut;
         while((end = std::next_permutation(curr_permut.begin(),
                         curr_permut.end()))) {
             // Check if the prefix of the new permutation is
             // different of the previous one
             types::list<int> new_permut(curr_permut.begin(),
                     curr_permut.begin()+_size);
             if(!(prev_permut==new_permut)) break;
         }
     } else {
         end = std::next_permutation(curr_permut.begin(),
                 curr_permut.end());
     }
     return *this;
 }
Exemplo n.º 2
0
 types::none_type sort(types::list<T> &seq) {
     std::sort(seq.begin(),seq.end());
     return __builtin__::None;
 }
Exemplo n.º 3
0
 types::none_type reverse(types::list<T> &seq) {
     std::reverse(seq.begin(),seq.end());
     return __builtin__::None;
 }
Exemplo n.º 4
0
 bool operator==(permutations_iterator const& other) const
 {
     if(other.end != end)
         return false;
     return std::equal(curr_permut.begin(), curr_permut.end(), other.curr_permut.begin());
 }