rasdaman client API  10.6.3
The Array Analytics Engine: Datacubes at Your Fingertips
miterf.hh
Go to the documentation of this file.
1 /*
2 * This file is part of rasdaman community.
3 *
4 * Rasdaman community is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
8 *
9 * Rasdaman community is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with rasdaman community. If not, see <http://www.gnu.org/licenses/>.
16 *
17 * Copyright 2003, 2004, 2005, 2006, 2007, 2008, 2009 Peter Baumann /
18 rasdaman GmbH.
19 *
20 * For more information please see <http://www.rasdaman.org>
21 * or contact Peter Baumann via <baumann@rasdaman.com>.
22 */
23 
24 #ifndef D_MITERF_HH
25 #define D_MITERF_HH
26 
27 #include "raslib/mddtypes.hh"
28 #include <math.h>
29 
30 class r_Minterval;
31 class Tile;
32 
35 #if !defined(unlikely)
36 #define unlikely(x) __builtin_expect(!!(x), 0)
37 #endif
40 #if !defined(likely)
41 #define likely(x) __builtin_expect(!!(x), 1)
42 #endif
43 
53 {
54 public:
55  r_FixedPointNumber() = default;
56  explicit r_FixedPointNumber(const double &);
57 
60  r_FixedPointNumber &operator=(const double &);
61 
64  inline bool stepForwardFlag(const r_FixedPointNumber &);
65 
67  inline r_Range getIntPart() const;
68 
69  std::string toString() const;
70 private:
72  void init(const double &);
73 
74  r_Range intPart{};
75  r_Range fracPart{};
76 
77  static const int FIXPREC;
78  static const r_Range carryPos;
79  static const r_Range fracMask;
80  static const double fixOne;
81 
82  friend std::ostream &operator<<(std::ostream &, r_FixedPointNumber &);
83 };
84 
86 {
87  intPart += f.intPart;
88  fracPart += f.fracPart;
89  if (fracPart & carryPos)
90  {
91  ++intPart;
92  fracPart &= fracMask;
93  return true;
94  }
95  return false;
96 }
98 {
99  return intPart;
100 }
101 
102 // -------------------------------------------------------------------------- //
103 
104 //@ManMemo: Module: {\bf raslib}
117 {
118 public:
121  r_MiterFloat(r_Bytes srcCellSize,
122  const char *srcTile,
123  const r_Minterval &fullTileDomain,
124  const r_Minterval &srcDomain,
125  const r_Minterval &dstDomain);
126 
127  r_MiterFloat(const r_MiterFloat&) = delete;
131 
133 
135  void reset();
137  inline char *nextCell();
139  inline bool isDone() const;
140 
141 protected:
143  struct iter_desc
144  {
145  r_FixedPointNumber min; // source axis lower bound
146  r_FixedPointNumber pos; // source axis current position, initially = min
147  r_FixedPointNumber step; // source / destination axis extents ratio
148 
149  r_Range countSteps; // initially = maxSteps, decreased on every nextCell()
150  r_Range maxSteps; // dest axis extent
151 
152  r_Range dimStep; // step one index over the full source data
153  r_Range scaleStep; // step one scaled index over the full source data
154 
155  char *cell; // the current cell returned by nextCell(), initially = firstCell
156  };
157 
158  char *currentCell;
160  const char *firstCell;
167  bool done;
168 };
169 
171 {
172  if (likely(!done))
173  {
174  iter_desc *id = iterDescEnd;
175  currentCell = id->cell;
176 
177  r_Dimension i = dim;
178  while (likely(i > 0))
179  {
180  --id->countSteps;
181  if (likely(id->countSteps))
182  {
183  // one more step in this dimension
184  if (id->pos.stepForwardFlag(id->step))
185  {
186  id->cell += id->dimStep;
187  }
188  id->cell += id->scaleStep;
189  break;
190  }
191  // else we are finished with this dimension
192  id->pos = id->min;
193  id->countSteps = id->maxSteps;
194  --id;
195  --i;
196  }
197 
198  if (unlikely(i < dim))
199  {
200  if (i == 0)
201  {
202  done = true;
203  }
204  else
205  {
206  for (r_Dimension j = i; j < dim; j++)
207  iterDesc[j].cell = iterDesc[i - 1].cell;
208  }
209  }
210  }
211 
212  return currentCell;
213 }
214 
215 inline bool r_MiterFloat::isDone() const
216 {
217  return done;
218 }
219 
220 #endif
A fixed-point representation of a double, with 30 digit fractional part precision.
Definition: miterf.hh:53
r_FixedPointNumber(const r_FixedPointNumber &)=default
r_FixedPointNumber & operator=(const double &)
std::string toString() const
r_FixedPointNumber(const double &)
friend std::ostream & operator<<(std::ostream &, r_FixedPointNumber &)
bool stepForwardFlag(const r_FixedPointNumber &)
Add the given value to this value.
Definition: miterf.hh:85
r_FixedPointNumber & operator=(const r_FixedPointNumber &)=default
r_FixedPointNumber()=default
r_Range getIntPart() const
Definition: miterf.hh:97
The spatial domain of an MDD is represented by an object of class r_Minterval.
Definition: minterval.hh:226
r_MiterFloat is used for iterating through parts of multidimensional intervals with arbitrary steppin...
Definition: miterf.hh:117
char * currentCell
Definition: miterf.hh:158
bool isDone() const
true if done
Definition: miterf.hh:215
bool done
true when the iteration over dstDomain is finished
Definition: miterf.hh:167
r_MiterFloat & operator=(const r_MiterFloat &)=delete
void reset()
iterator reset
r_Dimension dim
source tile dimension
Definition: miterf.hh:165
char * nextCell()
get the next cell
Definition: miterf.hh:170
r_MiterFloat & operator=(r_MiterFloat &&)=delete
r_MiterFloat(r_Bytes srcCellSize, const char *srcTile, const r_Minterval &fullTileDomain, const r_Minterval &srcDomain, const r_Minterval &dstDomain)
Constructor getting the source tile, the source domain in that tile, and the destination domain.
iter_desc * iterDescEnd
Definition: miterf.hh:163
iter_desc * iterDesc
Iteration information for each axis.
Definition: miterf.hh:162
r_MiterFloat(r_MiterFloat &&)=delete
r_MiterFloat(const r_MiterFloat &)=delete
const char * firstCell
start of the source tile cell data at the origin of srcDomain
Definition: miterf.hh:160
std::int64_t r_Range
for axis indexing, e.g.
Definition: mddtypes.hh:53
std::uint32_t r_Dimension
number of dimensions in r_Point and r_Minterval.
Definition: mddtypes.hh:56
size_t r_Bytes
number of bytes in an tile or mdd or type.
Definition: mddtypes.hh:43
#define likely(x)
Use in conditionals to signal that the condition is very likely https://gcc.gnu.org/onlinedocs/gcc/Ot...
Definition: miterf.hh:41
#define unlikely(x)
Use in conditionals to signal that the condition is very unlikely https://gcc.gnu....
Definition: miterf.hh:36
Iteration information for each axis.
Definition: miterf.hh:144
r_Range scaleStep
Definition: miterf.hh:153
r_FixedPointNumber min
Definition: miterf.hh:145
r_Range maxSteps
Definition: miterf.hh:150
r_Range countSteps
Definition: miterf.hh:149
r_Range dimStep
Definition: miterf.hh:152
r_FixedPointNumber pos
Definition: miterf.hh:146
r_FixedPointNumber step
Definition: miterf.hh:147
char * cell
Definition: miterf.hh:155