NVBIO
Main Page
Modules
Classes
Examples
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Groups
Pages
nvbio
basic
index_transform_iterator.h
Go to the documentation of this file.
1
/*
2
* nvbio
3
* Copyright (c) 2011-2014, NVIDIA CORPORATION. All rights reserved.
4
*
5
* Redistribution and use in source and binary forms, with or without
6
* modification, are permitted provided that the following conditions are met:
7
* * Redistributions of source code must retain the above copyright
8
* notice, this list of conditions and the following disclaimer.
9
* * Redistributions in binary form must reproduce the above copyright
10
* notice, this list of conditions and the following disclaimer in the
11
* documentation and/or other materials provided with the distribution.
12
* * Neither the name of the NVIDIA CORPORATION nor the
13
* names of its contributors may be used to endorse or promote products
14
* derived from this software without specific prior written permission.
15
*
16
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
17
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19
* DISCLAIMED. IN NO EVENT SHALL NVIDIA CORPORATION BE LIABLE FOR ANY
20
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26
*/
27
28
#pragma once
29
30
#include <
nvbio/basic/types.h
>
31
#include <
nvbio/basic/iterator.h
>
32
#include <
nvbio/basic/iterator_reference.h
>
33
34
namespace
nvbio {
35
38
41
46
template
<
typename
T,
typename
Transform>
47
struct
index_transform_iterator
48
{
49
typedef
index_transform_iterator<T,Transform>
this_type
;
50
typedef
typename
Transform::result_type
value_type
;
51
typedef
iterator_reference<this_type>
reference
;
52
typedef
value_type
const_reference
;
53
typedef
value_type
*
pointer
;
54
typedef
typename
std::iterator_traits<T>::difference_type
difference_type
;
55
//typedef typename std::iterator_traits<T>::distance_type distance_type;
56
typedef
std::random_access_iterator_tag
iterator_category
;
57
60
NVBIO_FORCEINLINE
NVBIO_HOST_DEVICE
61
index_transform_iterator
() {}
62
65
NVBIO_FORCEINLINE
NVBIO_HOST_DEVICE
66
index_transform_iterator
(
const
T base,
const
Transform f,
const
difference_type
i = 0) :
m_base
( base ),
m_f
( f ),
m_index
( i ) {}
67
70
NVBIO_FORCEINLINE
NVBIO_HOST_DEVICE
71
index_transform_iterator
(
const
index_transform_iterator
& it) :
m_base
( it.
m_base
),
m_f
( it.
m_f
),
m_index
( it.
m_index
) {}
72
75
NVBIO_FORCEINLINE
NVBIO_HOST_DEVICE
76
void
set
(
const
value_type
v) {
m_base
[
m_f
(
m_index
) ] = v; }
77
80
NVBIO_FORCEINLINE
NVBIO_HOST_DEVICE
81
const_reference
operator[]
(
const
uint32
i)
const
{
return
m_base
[
m_f
(
m_index
+ i ) ]; }
82
85
NVBIO_FORCEINLINE
NVBIO_HOST_DEVICE
86
reference
operator[]
(
const
uint32
i) {
return
reference
( *
this
+ i ); }
87
90
NVBIO_FORCEINLINE
NVBIO_HOST_DEVICE
91
value_type
operator*
()
const
{
return
m_base
[
m_f
(
m_index
) ]; }
92
95
NVBIO_FORCEINLINE
NVBIO_HOST_DEVICE
96
reference
operator*
() {
return
reference
( *
this
); }
97
100
NVBIO_FORCEINLINE
NVBIO_HOST_DEVICE
101
index_transform_iterator<T,Transform>
&
operator++
()
102
{
103
++
m_index
;
104
return
*
this
;
105
}
106
109
NVBIO_FORCEINLINE
NVBIO_HOST_DEVICE
110
index_transform_iterator<T,Transform>
operator++
(
int
i)
111
{
112
index_transform_iterator<T,Transform>
r(
m_base
,
m_f
,
m_index
);
113
++
m_index
;
114
return
r;
115
}
116
119
NVBIO_FORCEINLINE
NVBIO_HOST_DEVICE
120
index_transform_iterator<T,Transform>
&
operator--
()
121
{
122
--
m_index
;
123
return
*
this
;
124
}
125
128
NVBIO_FORCEINLINE
NVBIO_HOST_DEVICE
129
index_transform_iterator<T,Transform>
operator--
(
int
i)
130
{
131
index_transform_iterator<T,Transform>
r(
m_base
,
m_f
,
m_index
);
132
--
m_index
;
133
return
r;
134
}
135
138
NVBIO_FORCEINLINE
NVBIO_HOST_DEVICE
139
index_transform_iterator<T,Transform>
operator+
(
const
difference_type
i)
const
140
{
141
return
index_transform_iterator
(
m_base
,
m_f
,
m_index
+ i );
142
}
143
146
NVBIO_FORCEINLINE
NVBIO_HOST_DEVICE
147
index_transform_iterator<T,Transform>
operator-
(
const
difference_type
i)
const
148
{
149
return
index_transform_iterator
(
m_base
,
m_f
,
m_index
- i );
150
}
151
154
NVBIO_FORCEINLINE
NVBIO_HOST_DEVICE
155
index_transform_iterator<T,Transform>
&
operator+=
(
const
difference_type
i)
156
{
157
m_index
+= i;
158
return
*
this
;
159
}
160
163
NVBIO_FORCEINLINE
NVBIO_HOST_DEVICE
164
index_transform_iterator<T,Transform>
&
operator-=
(
const
difference_type
i)
165
{
166
m_index
-= i;
167
return
*
this
;
168
}
169
172
NVBIO_FORCEINLINE
NVBIO_HOST_DEVICE
173
difference_type
operator-
(
const
index_transform_iterator<T,Transform>
it)
const
174
{
175
return
m_index
- it.
m_index
;
176
}
177
180
NVBIO_FORCEINLINE
NVBIO_HOST_DEVICE
181
index_transform_iterator
&
operator=
(
const
index_transform_iterator<T,Transform>
& it)
182
{
183
m_base
= it.
m_base
;
184
m_f
= it.
m_f
;
185
m_index
= it.
m_index
;
186
return
*
this
;
187
}
188
189
T
m_base
;
190
Transform
m_f
;
191
difference_type
m_index
;
192
};
193
196
template
<
typename
T,
typename
Transform>
197
NVBIO_FORCEINLINE
NVBIO_HOST_DEVICE
198
index_transform_iterator<T,Transform>
make_index_transform_iterator
(
const
T it,
const
Transform f)
199
{
200
return
index_transform_iterator<T,Transform>
( it, f );
201
}
202
203
206
template
<
typename
T,
typename
Transform>
207
NVBIO_FORCEINLINE
NVBIO_HOST_DEVICE
208
bool
operator==
(
const
index_transform_iterator<T,Transform>
it1,
const
index_transform_iterator<T,Transform>
it2)
209
{
210
return
(it1.
m_base
== it2.
m_base
) && (it1.
m_f
== it2.
m_f
) && (it1.
m_index
== it2.
m_index
);
211
}
214
template
<
typename
T,
typename
Transform>
215
NVBIO_FORCEINLINE
NVBIO_HOST_DEVICE
216
bool
operator!=
(
const
index_transform_iterator<T,Transform>
it1,
const
index_transform_iterator<T,Transform>
it2)
217
{
218
return
(it1.
m_base
!= it2.
m_base
) || (it1.
m_f
!= it2.
m_f
) || (it1.
m_index
!= it2.
m_index
);
219
}
222
template
<
typename
T,
typename
Transform>
223
NVBIO_FORCEINLINE
NVBIO_HOST_DEVICE
224
bool
operator<(const index_transform_iterator<T,Transform> it1,
const
index_transform_iterator<T,Transform>
it2) {
return
(it1.m_index < it2.m_index); }
227
template
<
typename
T,
typename
Transform>
228
NVBIO_FORCEINLINE
NVBIO_HOST_DEVICE
229
bool
operator<=(const index_transform_iterator<T,Transform> it1,
const
index_transform_iterator<T,Transform>
it2) {
return
(it1.m_index <= it2.m_index); }
232
template
<
typename
T,
typename
Transform>
233
NVBIO_FORCEINLINE
NVBIO_HOST_DEVICE
234
bool
operator>
(
const
index_transform_iterator<T,Transform>
it1,
const
index_transform_iterator<T,Transform>
it2) {
return
(it1.
m_index
> it2.
m_index
); }
237
template
<
typename
T,
typename
Transform>
238
NVBIO_FORCEINLINE
NVBIO_HOST_DEVICE
239
bool
operator>=
(
const
index_transform_iterator<T,Transform>
it1,
const
index_transform_iterator<T,Transform>
it2) {
return
(it1.
m_index
>= it2.
m_index
); }
240
243
244
}
// namespace nvbio
Generated on Wed Feb 25 2015 08:32:55 for NVBIO by
1.8.4