NVBIO
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
cached_iterator_inl.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 
33 #include <nvbio/basic/types.h>
34 
35 namespace nvbio {
36 
37 // less than
38 //
39 template <typename Stream>
43 {
44  return it1.stream() < it2.stream();
45 }
46 
47 // less than
48 //
49 template <typename Stream>
53 {
54  return it1.stream() <= it2.stream();
55 }
56 
57 // greater than
58 //
59 template <typename Stream>
63 {
64  return it1.stream() > it2.stream();
65 }
66 
67 // greater than
68 //
69 template <typename Stream>
73 {
74  return it1.stream() >= it2.stream();
75 }
76 
77 // equality test
78 //
79 template <typename Stream>
83 {
84  return it1.stream() == it2.stream();
85 }
86 
87 // inequality test
88 //
89 template <typename Stream>
93 {
94  return it1.stream() != it2.stream();
95 }
96 
97 // pre-increment operator
98 //
99 template <typename Stream>
102 {
103  ++it.m_stream;
104  it.m_cached_idx = uint32(-1);
105  return it;
106 }
107 
108 // post-increment operator
109 //
110 template <typename Stream>
113 {
115  ++it.m_stream;
116  it.m_cached_idx = uint32(-1);
117  return r;
118 }
119 
120 // pre-decrement operator
121 //
122 template <typename Stream>
125 {
126  --it.m_stream;
127  it.m_cached_idx = uint32(-1);
128  return it;
129 }
130 
131 // post-decrement operator
132 //
133 template <typename Stream>
136 {
138  --it.m_stream;
139  it.m_cached_idx = uint32(-1);
140  return r;
141 }
142 
143 // add offset
144 //
145 template <typename Stream>
148 {
149  it.m_stream += distance;
150  it.m_cached_idx = uint32(-1);
151  return it;
152 }
153 
154 // subtract offset
155 //
156 template <typename Stream>
159 {
160  it.m_stream -= distance;
161  it.m_cached_idx = uint32(-1);
162  return it;
163 }
164 
165 // add offset
166 //
167 template <typename Stream>
170 {
171  return const_cached_iterator<Stream>( it.stream() + distance );
172 }
173 
174 // subtract offset
175 //
176 template <typename Stream>
179 {
180  return const_cached_iterator<Stream>( it.stream() - distance );
181 }
182 
183 // difference
184 //
185 template <typename Stream>
188 {
189  return it1.stream() - it2.stream();
190 }
191 
192 } // namespace nvbio