~ubuntu-branches/ubuntu/saucy/rheolef/saucy

« back to all changes in this revision

Viewing changes to skit/plib2/msg_right_permutation_apply.h

  • Committer: Bazaar Package Importer
  • Author(s): Pierre Saramito
  • Date: 2011-02-08 10:00:06 UTC
  • mfrom: (1.1.3 upstream)
  • Revision ID: james.westby@ubuntu.com-20110208100006-jg8rarizvhdm8e82
Tags: 5.92-1
* New upstream release:
  - "rheolef" suffix added to all unix manuals (Closes: #607117)
  - minor source code fixes for g++-4.5 (Closes: #607184)
  - minor reference manual fix (Closes: #607038)
* debian/control: libboost-iostreams-dev dependency added, as required
  by the new upstream version.
 

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#ifndef _RHEO_MSG_RIGHT_PERMUTATION_APPLY_H
 
2
#define _RHEO_MSG_RIGHT_PERMUTATION_APPLY_H
 
3
///
 
4
/// This file is part of Rheolef.
 
5
///
 
6
/// Copyright (C) 2000-2009 Pierre Saramito <Pierre.Saramito@imag.fr>
 
7
///
 
8
/// Rheolef is free software; you can redistribute it and/or modify
 
9
/// it under the terms of the GNU General Public License as published by
 
10
/// the Free Software Foundation; either version 2 of the License, or
 
11
/// (at your option) any later version.
 
12
///
 
13
/// Rheolef is distributed in the hope that it will be useful,
 
14
/// but WITHOUT ANY WARRANTY; without even the implied warranty of
 
15
/// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
16
/// GNU General Public License for more details.
 
17
///
 
18
/// You should have received a copy of the GNU General Public License
 
19
/// along with Rheolef; if not, write to the Free Software
 
20
/// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
21
/// 
 
22
/// =========================================================================
 
23
namespace rheolef {
 
24
/*F:
 
25
NAME: msg_right_permutation_apply -- sequentail apply (@PACKAGE@ @VERSION@)
 
26
DESCRIPTION:
 
27
  Applies a permutation to an array.
 
28
ALGORITHM:
 
29
  msg_right_permutation_apply
 
30
 
 
31
  "input": the length array
 
32
  |   perm(0:n-1), x(0:nx-1)
 
33
  "output": the pointer array and the total size
 
34
  |   y(0:n)
 
35
  begin
 
36
  |   for i := 0 to n-1 do
 
37
  |     y(i) := x(perm(i))
 
38
  |   endfor
 
39
  end
 
40
COMPLEXITY:
 
41
  Time and memory complexity is O(n).
 
42
METHODS: @msg_right_permutation_apply 
 
43
AUTHORS:
 
44
    LMC-IMAG, 38041 Grenoble cedex 9, France
 
45
    | Pierre.Saramito@imag.fr
 
46
DATE:   6 january 1999
 
47
END:
 
48
*/
 
49
 
 
50
//<msg_right_permutation_apply:
 
51
template <
 
52
    class InputIterator,
 
53
    class InputRandomIterator,
 
54
    class OutputIterator,
 
55
    class SetOp>
 
56
OutputIterator
 
57
msg_right_permutation_apply (
 
58
    InputIterator               perm,
 
59
    InputIterator               last_perm,
 
60
    const InputRandomIterator&  x,
 
61
    OutputIterator              y,
 
62
    SetOp                       set_op)
 
63
{
 
64
    for (; perm != last_perm; y++, perm++) {
 
65
        // something like: (*y++) = x[(*perm++)];
 
66
        set_op (y, x, *perm);
 
67
    }
 
68
    return y;
 
69
}
 
70
//>msg_right_permutation_apply:
 
71
 
 
72
// set(rhs,lhs,i) <==> *rhs = lhs[i] or *rhs = pair(i,rhs[i])
 
73
 
 
74
// 1) used by csr<Float>:
 
75
template<class OutputIterator, class InputRandomIterator, class Size>
 
76
struct msg_right_permutation_set_default {
 
77
  void operator() (OutputIterator rhs, const InputRandomIterator& lhs, Size i) {
 
78
        *rhs = lhs [i];
 
79
  }
 
80
};
 
81
template <
 
82
    class InputIterator,
 
83
    class InputRandomIterator,
 
84
    class OutputIterator>
 
85
inline
 
86
OutputIterator
 
87
msg_right_permutation_apply (
 
88
    InputIterator               perm,
 
89
    InputIterator               last_perm,
 
90
    const InputRandomIterator&  x,
 
91
    OutputIterator              y)
 
92
{
 
93
    typedef typename std::iterator_traits<InputIterator>::value_type size_type;
 
94
    msg_right_permutation_set_default<OutputIterator, InputRandomIterator, size_type> set_op;
 
95
    return msg_right_permutation_apply (perm, last_perm, x, y, set_op);
 
96
}
 
97
// used by polymorphic_array<geo_element> in geo<Float>:
 
98
template<class OutputIterator, class InputRandomIterator, class Size>
 
99
struct msg_right_permutation_set_pair {
 
100
  typedef typename std::iterator_traits<OutputIterator>::value_type T;
 
101
  void operator() (OutputIterator rhs, const InputRandomIterator& lhs, Size i) {
 
102
        *rhs = std::pair<Size,T>(i,lhs [i]);
 
103
  }
 
104
};
 
105
 
 
106
 
 
107
} // namespace rheolef
 
108
#endif // _RHEO_MSG_RIGHT_PERMUTATION_APPLY_H