das2C
das core C utilities (v3)
Loading...
Searching...
No Matches
iterator.h
Go to the documentation of this file.
1/* Copyright (C) 2024 Chris Piker <chris-piker@uiowa.edu>
2 *
3 * This file is part of das2C, the Core Das2 C Library.
4 *
5 * Das2C is free software; you can redistribute it and/or modify it under
6 * the terms of the GNU Lesser General Public License version 2.1 as published
7 * by the Free Software Foundation.
8 *
9 * Das2C is distributed in the hope that it will be useful, but WITHOUT ANY
10 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for
12 * more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public License
15 * version 2.1 along with das2C; if not, see <http://www.gnu.org/licenses/>.
16 */
17
20#ifndef _das_iterator_h_
21#define _das_iterator_h_
22
23#include <das3/dataset.h>
24
25#ifdef __cplusplus
26extern "C" {
27#endif
28
67typedef struct dasds_iterator_t{
68
70 bool done;
71
74 ptrdiff_t index[VARIDX_MAX];
75
76 int rank;
77 ptrdiff_t shape[VARIDX_MAX]; /* Used for CUBIC datasets */
78 ptrdiff_t nLenIn; /* Used for ragged datasets */
79 bool ragged;
80 const DasDs* pDs;
81} DasDsIter;
82
83#define dasds_iterator DasDsIter
84
101DAS_API void DasDsIter_init(DasDsIter* pThis, const DasDs* pDs);
102#define dasds_iter_init DasDsIter_init
103
120DAS_API bool DasDsIter_next(DasDsIter* pThis);
121#define dasds_iter_next DasDsIter_next
122
123/* ************************************************************************* */
124
127typedef struct das_uniq_iter_t{
129 bool done;
130
133 ptrdiff_t index[VARIDX_MAX];
134
136 bool lock[VARIDX_MAX];
137
139 int first;
140 int last;
141
142 int rank;
143 ptrdiff_t shape[VARIDX_MAX]; /* Used for CUBIC datasets */
144 ptrdiff_t nLenIn; /* Used for ragged datasets */
145 bool ragged;
146 const DasDs* pDs;
148
167 DasDsUniqIter* pThis, const DasDs* pDs, const DasVar* pVar
168);
169
187
188/* ************************************************************************* */
189
192typedef struct das_cube_iter_t{
193
195 bool done;
196
199 ptrdiff_t index[VARIDX_MAX];
200
201 int rank;
202 ptrdiff_t idxmin[VARIDX_MAX];
203 ptrdiff_t idxmax[VARIDX_MAX];
204
206
207#define das_cube_iter DasDsCubeIter
208#define das_cube_iter_init DasDsCubeIter_init
209#define das_cube_iter_next DasDsCubeIter_next
210
214DAS_API void DasDsCubeIter_init(
215 das_cube_iter* pThis, int nRank, ptrdiff_t* pMin, ptrdiff_t* pMax
216);
217
228DAS_API bool DasDsCubeIter_next(das_cube_iter* pThis);
229
231typedef struct das_array_iter_t{
232 const DasAry* pAry;
233 bool done;
234 bool ragged; /* flag for no end_idx */
235 bool bNaturalEnd;
236 int rank;
237 ptrdiff_t index[VARIDX_MAX]; /* current index */
238 ptrdiff_t end_idx[VARIDX_MAX]; /* 1 after last valid index */
239 int dim_min;
240 int dim_max;
241
242 ptrdiff_t shape[VARIDX_MAX]; /* Used for CUBIC arrays */
243 ptrdiff_t nLenLast; /* Used for ragged arrays */
244} DasAryIter;
245
246
273DAS_API void DasAryIter_init(
274 DasAryIter* pThis, const DasAry* pAry, int iDimMin, int iDimMax, ptrdiff_t* pBeg,
275 ptrdiff_t* pEnd
276);
277
278
288DAS_API bool DasAryIter_next(DasAryIter* pThis);
289
290
291#ifdef __cplusplus
292}
293#endif
294
295#endif /* _das_dataset_h */
Objects which correlate arrays in index space.
#define VARIDX_MAX
Max index count for the model.
Definition generator.h:55
DAS_API bool DasAryIter_next(DasAryIter *pThis)
Increment an array iterated to the next expected index.
Iterate over a sub-set of the index space of a DasAry.
Definition iterator.h:231
DAS_API void DasAryIter_init(DasAryIter *pThis, const DasAry *pAry, int iDimMin, int iDimMax, ptrdiff_t *pBeg, ptrdiff_t *pEnd)
Initialize an array iterator.
Dynamic recursive ragged arrays.
Definition array.h:271
Simple cubic iterator.
Definition iterator.h:192
bool done
If true the value in index is valid, false otherwise.
Definition iterator.h:195
Dataset iterator structure.
Definition iterator.h:67
bool done
If true the value in index is valid, false otherwise.
Definition iterator.h:70
DAS_API bool DasDsIter_next(DasDsIter *pThis)
Increment the iterator's index by one position, rolling as needed at data boundaries.
DAS_API void DasDsIter_init(DasDsIter *pThis, const DasDs *pDs)
Initialize a const dataset iterator.
A non-degenerate iterator.
Definition iterator.h:127
bool done
If true the current value in the index is valid, false otherwise.
Definition iterator.h:129
DAS_API void DasDsUniqIter_init(DasDsUniqIter *pThis, const DasDs *pDs, const DasVar *pVar)
Initialize a non-degenerate iterator for a variable.
int first
Shortcut iteration by saving off the indexes that matter.
Definition iterator.h:139
DAS_API bool DasDsUniqIter_next(DasDsUniqIter *pThis)
Increment the iterator's index by one position, rolling as needed at data boundaries.
Das Datasets.
Definition dataset.h:156