DAWorkbench 0.0.1
DAWorkbench API
载入中...
搜索中...
未找到
da_algorithm.hpp
1#ifndef DA_ALGORITHM_H
2#define DA_ALGORITHM_H
3
4#include <algorithm>
5
6namespace DA
7{
20template< typename _IT, typename _IT_Index, typename _IT_RES >
21void copy_out_of_indexs(_IT input_begin, _IT input_end, _IT_Index index_begin, _IT_Index index_end, _IT_RES output_begin, size_t inputIndexStart = 0)
22{
23 if (index_begin == index_end) {
24 std::copy(input_begin, input_end, output_begin);
25 return;
26 }
27 while (input_begin != input_end) {
28 if (inputIndexStart == (size_t)(*index_begin)) {
29 ++input_begin;
30 ++index_begin;
31 ++inputIndexStart;
32 if (index_begin == index_end) {
33 break;
34 }
35 continue;
36 }
37 *output_begin = *input_begin;
38 ++output_begin;
39 ++inputIndexStart;
40 ++input_begin;
41 }
42 std::copy(input_begin, input_end, output_begin);
43}
44
58template< typename _IT, typename _IT_Index, typename _IT_RES >
59void copy_inner_indexs(_IT input_begin, _IT input_end, _IT_Index index_begin, _IT_Index index_end, _IT_RES output_begin, size_t inputIndexStart = 0)
60{
61 if (index_begin == index_end) {
62 return;
63 }
64 while (input_begin != input_end) {
65 if (inputIndexStart == *index_begin) {
66 *output_begin = *input_begin;
67 ++output_begin;
68 ++index_begin;
69 if (index_begin == index_end) {
70 return;
71 }
72 }
73 ++inputIndexStart;
74 ++input_begin;
75 }
76}
77
89template< typename _IT, typename _IT_Index, typename _IT_RES >
90void copy_inner_indexs(_IT input_begin, _IT_Index index_begin, _IT_Index index_end, _IT_RES output_begin)
91{
92 if (index_begin == index_end) {
93 return;
94 }
95 while (index_begin != index_end) {
96 *output_begin = *(input_begin + *index_begin);
97 ++output_begin;
98 ++index_begin;
99 }
100}
101
114template< typename _IT_Index, typename _IT_Data, typename _IT_OldDataArr, typename _IT_NewDataArr >
115void insert_inner_indexs(_IT_Index index_be_insert_begin,
116 _IT_Index index_be_insert_end,
117 _IT_Data data_be_insert_begin,
118 _IT_OldDataArr old_data_begin,
119 _IT_OldDataArr old_data_end,
120 _IT_NewDataArr new_data_begin)
121{
122 size_t i = 0;
123
124 while (old_data_begin != old_data_end) {
125 if (i == (size_t)(*index_be_insert_begin)) {
126 //说明遇到要插入的索引
127 *new_data_begin = *data_be_insert_begin;
128 ++i;
129 ++index_be_insert_begin;
130 ++data_be_insert_begin;
131 ++new_data_begin;
132 } else {
133 *new_data_begin = *old_data_begin;
134 ++i;
135 ++old_data_begin;
136 ++new_data_begin;
137 }
138 }
139 while (index_be_insert_begin != index_be_insert_end) {
140 *new_data_begin = *data_be_insert_begin;
141 ++index_be_insert_begin;
142 ++data_be_insert_begin;
143 ++new_data_begin;
144 }
145}
146
162template< typename _IT, typename _IT_Index, typename _IT_RES >
163void split_with_indexs(_IT input_begin,
164 _IT input_end,
165 _IT_Index index_begin,
166 _IT_Index index_end,
167 _IT_RES outputInnerIndex_begin,
168 _IT_RES outputOutOfIndex_begin,
169 size_t inputIndexStart = 0)
170{
171 if (index_begin == index_end) {
172 std::copy(input_begin, input_end, outputOutOfIndex_begin);
173 return;
174 }
175 while (input_begin != input_end) {
176 if (inputIndexStart == (size_t)(*index_begin)) {
177 *outputInnerIndex_begin = *input_begin;
178 ++outputInnerIndex_begin;
179 ++index_begin;
180 if (index_begin == index_end) {
181 ++input_begin;
182 break;
183 }
184 } else {
185 *outputOutOfIndex_begin = *input_begin;
186 ++outputOutOfIndex_begin;
187 }
188 ++inputIndexStart;
189 ++input_begin;
190 }
191 std::copy(input_begin, input_end, outputOutOfIndex_begin);
192}
193
204template< class InputIterator1, class InputIterator2, class InputIterator3, class OutputIterator, class ThreeOperation >
205OutputIterator transform(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, InputIterator3 first3, OutputIterator result_first, ThreeOperation three_op)
206{
207 while (first1 != last1) {
208 *result_first = three_op(*first1, *first2, *first3); // or: *result=binary_op(*first1,*first2++);
209 ++result_first;
210 ++first1;
211 ++first2;
212 ++first3;
213 }
214 return (result_first);
215}
216
228template< class InputIterator1, class InputIterator2, class InputIterator3, class InputIterator4, class OutputIterator, class FourOperation >
229OutputIterator transform(InputIterator1 first1,
230 InputIterator1 last1,
231 InputIterator2 first2,
232 InputIterator3 first3,
233 InputIterator4 first4,
234 OutputIterator result_first,
235 FourOperation four_op)
236{
237 while (first1 != last1) {
238 *result_first = four_op(*first1, *first2, *first3, *first4); // or: *result=binary_op(*first1,*first2++);
239 ++result_first;
240 ++first1;
241 ++first2;
242 ++first3;
243 ++first4;
244 }
245 return (result_first);
246}
247
260template< class InputIterator1, class InputIterator2, class InputIterator3, class InputIterator4, class InputIterator5, class OutputIterator, class FiveOperation >
261OutputIterator transform(InputIterator1 first1,
262 InputIterator1 last1,
263 InputIterator2 first2,
264 InputIterator3 first3,
265 InputIterator4 first4,
266 InputIterator5 first5,
267 OutputIterator result_first,
268 FiveOperation five_op)
269{
270 while (first1 != last1) {
271 *result_first = five_op(*first1, *first2, *first3, *first4, *first5); // or: *result=binary_op(*first1,*first2++);
272 ++result_first;
273 ++first1;
274 ++first2;
275 ++first3;
276 ++first4;
277 ++first5;
278 }
279 return (result_first);
280}
281
295template< class InputIterator1, class InputIterator2, class InputIterator3, class InputIterator4, class InputIterator5, class InputIterator6, class OutputIterator, class SixOperation >
296OutputIterator transform(InputIterator1 first1,
297 InputIterator1 last1,
298 InputIterator2 first2,
299 InputIterator3 first3,
300 InputIterator4 first4,
301 InputIterator5 first5,
302 InputIterator6 first6,
303 OutputIterator result_first,
304 SixOperation six_op)
305{
306 while (first1 != last1) {
307 *result_first = six_op(*first1, *first2, *first3, *first4, *first5, *first6); // or: *result=binary_op(*first1,*first2++);
308 ++result_first;
309 ++first1;
310 ++first2;
311 ++first3;
312 ++first4;
313 ++first5;
314 ++first6;
315 }
316 return (result_first);
317}
318}
319
320#endif // DA_ALGORITHM_H
序列化类都是带异常的,使用中需要处理异常
Definition AppMainWindow.cpp:44
void copy_inner_indexs(_IT input_begin, _IT input_end, _IT_Index index_begin, _IT_Index index_end, _IT_RES output_begin, size_t inputIndexStart=0)
把索引范围之内的内容拷贝
Definition da_algorithm.hpp:59
void insert_inner_indexs(_IT_Index index_be_insert_begin, _IT_Index index_be_insert_end, _IT_Data data_be_insert_begin, _IT_OldDataArr old_data_begin, _IT_OldDataArr old_data_end, _IT_NewDataArr new_data_begin)
此函数作用是根据提供的待插入数组insert_data和待插入索引index_be_insert(这两者长度需要一致) ,以及需要插入的数组old_data,程序根据insert_data和index_...
Definition da_algorithm.hpp:115
void split_with_indexs(_IT input_begin, _IT input_end, _IT_Index index_begin, _IT_Index index_end, _IT_RES outputInnerIndex_begin, _IT_RES outputOutOfIndex_begin, size_t inputIndexStart=0)
根据提供的索引把一个序列分解为两个结集 ,其中 outputInnerIndex_begin存放在提供范围内的结果 outputOutOfIndex_begin存放提供的索引范围外的结果
Definition da_algorithm.hpp:163
OutputIterator transform(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, InputIterator3 first3, OutputIterator result_first, ThreeOperation three_op)
transform 3参数的transform,对std::transform的扩展,适用于3参数
Definition da_algorithm.hpp:205
void copy_out_of_indexs(_IT input_begin, _IT input_end, _IT_Index index_begin, _IT_Index index_end, _IT_RES output_begin, size_t inputIndexStart=0)
把索引范围之外的内容拷贝
Definition da_algorithm.hpp:21