1
#ifndef _RHEO_MSG_RIGHT_PERMUTATION_APPLY_H
2
#define _RHEO_MSG_RIGHT_PERMUTATION_APPLY_H
4
/// This file is part of Rheolef.
6
/// Copyright (C) 2000-2009 Pierre Saramito <Pierre.Saramito@imag.fr>
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.
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.
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
22
/// =========================================================================
25
NAME: msg_right_permutation_apply -- sequentail apply (@PACKAGE@ @VERSION@)
27
Applies a permutation to an array.
29
msg_right_permutation_apply
31
"input": the length array
32
| perm(0:n-1), x(0:nx-1)
33
"output": the pointer array and the total size
36
| for i := 0 to n-1 do
41
Time and memory complexity is O(n).
42
METHODS: @msg_right_permutation_apply
44
LMC-IMAG, 38041 Grenoble cedex 9, France
45
| Pierre.Saramito@imag.fr
50
//<msg_right_permutation_apply:
53
class InputRandomIterator,
57
msg_right_permutation_apply (
59
InputIterator last_perm,
60
const InputRandomIterator& x,
64
for (; perm != last_perm; y++, perm++) {
65
// something like: (*y++) = x[(*perm++)];
70
//>msg_right_permutation_apply:
72
// set(rhs,lhs,i) <==> *rhs = lhs[i] or *rhs = pair(i,rhs[i])
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) {
83
class InputRandomIterator,
87
msg_right_permutation_apply (
89
InputIterator last_perm,
90
const InputRandomIterator& x,
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);
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]);
107
} // namespace rheolef
108
#endif // _RHEO_MSG_RIGHT_PERMUTATION_APPLY_H