permlib 0.2.9
Library for permutation computations
Loading...
Searching...
No Matches
group_sorter.h
1// ---------------------------------------------------------------------------
2//
3// This file is part of PermLib.
4//
5// Copyright (c) 2009-2011 Thomas Rehn <thomas@carmen76.de>
6// All rights reserved.
7//
8// Redistribution and use in source and binary forms, with or without
9// modification, are permitted provided that the following conditions
10// are met:
11// 1. Redistributions of source code must retain the above copyright
12// notice, this list of conditions and the following disclaimer.
13// 2. Redistributions in binary form must reproduce the above copyright
14// notice, this list of conditions and the following disclaimer in the
15// documentation and/or other materials provided with the distribution.
16// 3. The name of the author may not be used to endorse or promote products
17// derived from this software without specific prior written permission.
18//
19// THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
20// IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
21// OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22// IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
23// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
24// NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
28// THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29//
30// ---------------------------------------------------------------------------
31
32
33#ifndef GROUPSORTER_H
34#define GROUPSORTER_H
35
36#include <boost/foreach.hpp>
37
38namespace permlib {
39
41template <class PERM>
42class GroupSorter : public std::binary_function<PERM, PERM, bool>{
43public:
45
50 template <class InputIterator>
51 GroupSorter(unsigned int size, InputIterator begin, InputIterator end) :
52 // initialize m_size elements with value m_size
53 m_order(size, size),
54 m_base(begin, end)
55 {
56 InputIterator it;
57 unsigned int i = 0;
58 // base elements first
59 for (it = begin; it != end; ++it) {
60 m_order[*it] = ++i;
61 }
62 }
63
65 bool operator() (PERM a, PERM b) const {
66 BOOST_FOREACH(unsigned long beta, m_base) {
67 if (m_order[a / beta] < m_order[b / beta])
68 return true;
69 }
70 return false;
71 }
72private:
73 std::vector<unsigned long> m_order;
74 std::vector<unsigned long> m_base;
75};
76
77}
78
79#endif // -- GROUPSORTER_H
A sorter that sorts a sequence of permutations with respect to a ordering induced by a base.
Definition group_sorter.h:42
bool operator()(PERM a, PERM b) const
true iff a < b
Definition group_sorter.h:65
GroupSorter(unsigned int size, InputIterator begin, InputIterator end)
constructor
Definition group_sorter.h:51