Yet Another eXchange Tool  0.9.0
xt_stripe_util.h
Go to the documentation of this file.
1 
12 /*
13  * Keywords:
14  * Maintainer: Jörg Behrens <behrens@dkrz.de>
15  * Moritz Hanke <hanke@dkrz.de>
16  * Thomas Jahns <jahns@dkrz.de>
17  * URL: https://doc.redmine.dkrz.de/yaxt/html/
18  *
19  * Redistribution and use in source and binary forms, with or without
20  * modification, are permitted provided that the following conditions are
21  * met:
22  *
23  * Redistributions of source code must retain the above copyright notice,
24  * this list of conditions and the following disclaimer.
25  *
26  * Redistributions in binary form must reproduce the above copyright
27  * notice, this list of conditions and the following disclaimer in the
28  * documentation and/or other materials provided with the distribution.
29  *
30  * Neither the name of the DKRZ GmbH nor the names of its contributors
31  * may be used to endorse or promote products derived from this software
32  * without specific prior written permission.
33  *
34  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
35  * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
36  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
37  * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
38  * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
39  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
40  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
41  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
42  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
43  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
44  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
45  */
46 #ifndef XT_STRIPE_UTIL_H
47 #define XT_STRIPE_UTIL_H
48 
49 #ifdef HAVE_CONFIG_H
50 #include <config.h>
51 #endif
52 
53 #include <stdbool.h>
54 #include <stdlib.h>
55 
56 #include "xt/xt_stripe.h"
57 
58 #include "xt_arithmetic_util.h"
59 
62 };
63 
64 static inline struct Xt_stripe_minmax
65 xt_stripe2minmax(struct Xt_stripe stripe)
66 {
67  Xt_int min = stripe.start, max = min;
68  Xt_int stride = stripe.stride;
69  int nstrides = stripe.nstrides;
70  Xt_int mask = Xt_isign_mask(stride);
71  stride = (Xt_int)((Xt_int)(nstrides - 1) * stride);
72  min = (Xt_int)(min + (Xt_int)(mask & stride));
73  max = (Xt_int)(max + (Xt_int)((Xt_int)~mask & stride));
74  return (struct Xt_stripe_minmax){ .min = min, .max = max};
75 }
76 
77 
78 static inline int
79 xt_stripes_overlap(struct Xt_stripe a, struct Xt_stripe b) {
80  struct Xt_stripe_minmax mma = xt_stripe2minmax(a),
81  mmb = xt_stripe2minmax(b);
82  return (mma.max >= mmb.min) & (mma.min <= mmb.max);
83 }
84 
85 void
86 xt_convert_indices_to_stripes_keep_buf(const Xt_int *restrict indices,
87  int num_indices,
88  struct Xt_stripe **stripes,
89  int * num_stripes);
90 
104 size_t
105 xt_stripes_merge_copy(size_t num_stripes,
106  struct Xt_stripe *stripes_dst,
107  const struct Xt_stripe *stripes_src,
108  bool lookback);
109 
110 
111 #endif
112 
113 /*
114  * Local Variables:
115  * c-basic-offset: 2
116  * coding: utf-8
117  * indent-tabs-mode: nil
118  * show-trailing-whitespace: t
119  * require-trailing-newline: t
120  * End:
121  */
static Xt_int Xt_isign_mask(Xt_int x)
XT_INT Xt_int
Definition: xt_core.h:68
size_t xt_stripes_merge_copy(size_t num_stripes, struct Xt_stripe *stripes_dst, const struct Xt_stripe *stripes_src, bool lookback)
Definition: xt_stripe.c:122
static int xt_stripes_overlap(struct Xt_stripe a, struct Xt_stripe b)
static struct Xt_stripe_minmax xt_stripe2minmax(struct Xt_stripe stripe)
void xt_convert_indices_to_stripes_keep_buf(const Xt_int *restrict indices, int num_indices, struct Xt_stripe **stripes, int *num_stripes)
Definition: xt_stripe.c:74