Yet Another eXchange Tool 0.11.2
Loading...
Searching...
No Matches
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://dkrz-sw.gitlab-pages.dkrz.de/yaxt/
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 "core/ppm_visibility.h"
59#include "xt_arithmetic_util.h"
60
65{
67};
68
69static inline struct Xt_minmax
71{
72 Xt_int min = stripe.start, max = min;
73 Xt_int stride = stripe.stride;
74 int nstrides = stripe.nstrides;
75 Xt_int mask = Xt_isign_mask(stride);
76 stride = (Xt_int)((Xt_int)(nstrides - 1) * stride);
77 min = (Xt_int)(min + (Xt_int)(mask & stride));
78 max = (Xt_int)(max + (Xt_int)((Xt_int)~mask & stride));
79 return (struct Xt_minmax){ .min = min, .max = max};
80}
81
82static inline int
83xt_stripes_eq(struct Xt_stripe a, struct Xt_stripe b) {
84 return a.stride == b.stride
85 && a.start == b.start
86 && a.nstrides == b.nstrides;
87}
88
89static inline int
91 struct Xt_minmax mma = xt_stripe2minmax(a),
92 mmb = xt_stripe2minmax(b);
93 return (mma.max >= mmb.min) & (mma.min <= mmb.max);
94}
95
100xt_indices_count_stripes(size_t num_indices,
101 const Xt_int indices[num_indices]);
102
106PPM_DSO_INTERNAL size_t
107xt_convert_indices_to_stripes_buf(size_t num_indices,
108 const Xt_int *restrict indices,
109 size_t num_stripes_alloc,
110 struct Xt_stripe *stripes);
111
116xt_convert_indices_to_stripes_keep_buf(const Xt_int *restrict indices,
117 int num_indices,
118 struct Xt_stripe **stripes,
119 int * num_stripes);
120
134PPM_DSO_INTERNAL size_t
135xt_stripes_merge_copy(size_t num_stripes,
136 struct Xt_stripe *stripes_dst,
137 const struct Xt_stripe *stripes_src,
138 bool lookback);
139
140enum {
141 sort_dsc, /* sorted descending */
142 sort_uns, /* unsorted */
143 sort_asc, /* sorted ascending */
144 sort_idt, /* all values identical */
146};
147
148#define XT_SORT_FLAGS(ntrans_up, ntrans_dn) \
149 (unsigned)((!(ntrans_dn) && !(ntrans_up)) ? sort_idt \
150 : ((!(ntrans_dn)) ? sort_asc \
151 : ((!(ntrans_up)) ? sort_dsc : sort_uns)))
152
154 long long num_indices;
155 unsigned flags;
156};
157
159xt_summarize_stripes(size_t num_stripes,
160 const struct Xt_stripe stripes[num_stripes]);
161
163xt_stripes_detect_duplicate(size_t num_stripes,
164 const struct Xt_stripe stripes[num_stripes],
165 struct Xt_minmax index_range);
166
167
168#endif
169
170/*
171 * Local Variables:
172 * c-basic-offset: 2
173 * coding: utf-8
174 * indent-tabs-mode: nil
175 * show-trailing-whitespace: t
176 * require-trailing-newline: t
177 * End:
178 */
#define PPM_DSO_INTERNAL
Xt_int stride
Definition xt_stripe.h:56
int nstrides
Definition xt_stripe.h:57
Xt_int start
Definition xt_stripe.h:55
static Xt_int Xt_isign_mask(Xt_int x)
XT_INT Xt_int
Definition xt_core.h:72
struct Xt_stripe_summary xt_summarize_stripes(size_t num_stripes, const struct Xt_stripe stripes[num_stripes])
Definition xt_stripe.c:204
static struct Xt_minmax xt_stripe2minmax(struct Xt_stripe stripe)
@ sort_uns
@ sort_dsc
@ sort_mask
@ sort_asc
@ sort_idt
static int xt_stripes_overlap(struct Xt_stripe a, struct Xt_stripe b)
PPM_DSO_INTERNAL bool xt_stripes_detect_duplicate(size_t num_stripes, const struct Xt_stripe stripes[num_stripes], struct Xt_minmax index_range)
Definition xt_stripe.c:237
static int xt_stripes_eq(struct Xt_stripe a, struct Xt_stripe b)
PPM_DSO_INTERNAL 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:163
PPM_DSO_INTERNAL size_t xt_indices_count_stripes(size_t num_indices, const Xt_int indices[num_indices])
Definition xt_stripe.c:77
PPM_DSO_INTERNAL size_t xt_convert_indices_to_stripes_buf(size_t num_indices, const Xt_int *restrict indices, size_t num_stripes_alloc, struct Xt_stripe *stripes)
Definition xt_stripe.c:126
PPM_DSO_INTERNAL 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:106