Yet Another eXchange Tool 0.11.2
Loading...
Searching...
No Matches
xt_idxlist_intersection.c
Go to the documentation of this file.
1
12/*
13 * Maintainer: Jörg Behrens <behrens@dkrz.de>
14 * Moritz Hanke <hanke@dkrz.de>
15 * Thomas Jahns <jahns@dkrz.de>
16 * URL: https://dkrz-sw.gitlab-pages.dkrz.de/yaxt/
17 *
18 * Redistribution and use in source and binary forms, with or without
19 * modification, are permitted provided that the following conditions are
20 * met:
21 *
22 * Redistributions of source code must retain the above copyright notice,
23 * this list of conditions and the following disclaimer.
24 *
25 * Redistributions in binary form must reproduce the above copyright
26 * notice, this list of conditions and the following disclaimer in the
27 * documentation and/or other materials provided with the distribution.
28 *
29 * Neither the name of the DKRZ GmbH nor the names of its contributors
30 * may be used to endorse or promote products derived from this software
31 * without specific prior written permission.
32 *
33 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
34 * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
35 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
36 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
37 * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
38 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
39 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
40 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
41 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
42 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
43 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
44 */
45#ifdef HAVE_CONFIG_H
46#include <config.h>
47#endif
48
49#include <stdlib.h>
50
51#include "instr.h"
52#include "core/ppm_xfuncs.h"
53#include "xt/xt_core.h"
54#include "xt/xt_idxlist.h"
55#include "xt_idxlist_internal.h"
56#include "xt_idxlist_unpack.h"
57#include "xt/xt_idxempty.h"
60#include "xt/xt_idxvec.h"
61#include "xt_config_internal.h"
62#include "xt_idxvec_internal.h"
65
66typedef Xt_idxlist (*intersection_get)(Xt_idxlist idxlist_src,
67 Xt_idxlist idxlist_dst,
68 Xt_config config);
69
70#define empty_isect ((intersection_get)(void (*)(void))xt_idxempty_new)
71
72/* table of intersection function to use, entry is chosen
73 * by type of source index list and type of destination index list
74 */
75static const intersection_get
90
94
97 Xt_idxlist idxlist_dst)
98{
99 return xt_idxlist_get_intersection_custom(idxlist_src, idxlist_dst,
101}
102
105 Xt_idxlist idxlist_dst, Xt_config config)
106{
108 [idxlist_dst->vtable->idxlist_pack_code](idxlist_src, idxlist_dst, config);
109}
110
113 Xt_idxlist idxlist_dst,
114 Xt_config config)
115{
116
117 INSTR_DEF(instr_fallback,"xt_idxlist_get_intersection.fallback")
118
119 // if the get_intersection routine was not able to compute the intersection
120 INSTR_START(instr_fallback);
121
122 int num_indices_src = xt_idxlist_get_num_indices(idxlist_src),
123 num_indices_dst = xt_idxlist_get_num_indices(idxlist_dst);
124
125 if (num_indices_src == 0 || num_indices_dst == 0)
126 return xt_idxempty_new();
127
128 Xt_idxlist intersection;
129 if (num_indices_src <= config->idxv_cnv_size
130 && num_indices_dst <= config->idxv_cnv_size) {
131 Xt_int *indices_src
132 = xmalloc(((size_t)num_indices_src + (size_t)num_indices_dst)
133 * sizeof (indices_src[0])),
134 *indices_dst = indices_src + num_indices_src;
135
136 xt_idxlist_get_indices(idxlist_src, indices_src);
137 xt_idxlist_get_indices(idxlist_dst, indices_dst);
138
139 Xt_idxlist idxvec_src = xt_idxvec_prealloc_new(indices_src, num_indices_src),
140 idxvec_dst = xt_idxvec_prealloc_new(indices_dst, num_indices_dst);
141
142 intersection
143 = xt_idxvec_get_intersection(idxvec_src, idxvec_dst, config);
144
145 xt_idxlist_delete(idxvec_src);
146 xt_idxlist_delete(idxvec_dst);
147 free(indices_src);
148 } else {
149 int num_stripes_src, num_stripes_dst;
150 struct Xt_stripe *stripes_src, *stripes_dst;
151 xt_idxlist_get_index_stripes(idxlist_src, &stripes_src, &num_stripes_src);
152 xt_idxlist_get_index_stripes(idxlist_dst, &stripes_dst, &num_stripes_dst);
153 Xt_idxlist idxstripes_src = xt_idxstripes_prealloc_new(stripes_src,
154 num_stripes_src),
155 idxstripes_dst = xt_idxstripes_prealloc_new(stripes_dst,
156 num_stripes_dst);
157 intersection
158 = xt_idxstripes_get_intersection(idxstripes_src, idxstripes_dst, config);
159 xt_idxlist_delete(idxstripes_dst);
160 xt_idxlist_delete(idxstripes_src);
161 free(stripes_dst);
162 free(stripes_src);
163 }
164
165 INSTR_STOP(instr_fallback);
166 return intersection;
167}
168
169/*
170 * Local Variables:
171 * c-basic-offset: 2
172 * coding: utf-8
173 * indent-tabs-mode: nil
174 * show-trailing-whitespace: t
175 * require-trailing-newline: t
176 * End:
177 */
178
#define INSTR_STOP(T)
Definition instr.h:69
#define INSTR_DEF(T, S)
Definition instr.h:66
#define INSTR_START(T)
Definition instr.h:68
add versions of standard API functions not returning on error
#define xmalloc(size)
Definition ppm_xfuncs.h:70
const struct xt_idxlist_vtable * vtable
struct Xt_config_ xt_default_config
Definition xt_config.c:204
struct Xt_config_ * Xt_config
Definition xt_config.h:58
implementation of configuration object
base definitions header file
XT_INT Xt_int
Definition xt_core.h:72
struct Xt_idxlist_ * Xt_idxlist
Definition xt_core.h:84
Xt_idxlist xt_idxempty_new(void)
index list declaration
void xt_idxlist_get_indices(Xt_idxlist idxlist, Xt_int *indices)
Definition xt_idxlist.c:113
void xt_idxlist_get_index_stripes(Xt_idxlist idxlist, struct Xt_stripe **stripes, int *num_stripes)
Definition xt_idxlist.c:135
void xt_idxlist_delete(Xt_idxlist idxlist)
Definition xt_idxlist.c:75
Provide non-public declarations common to all index lists.
PPM_DSO_INTERNAL Xt_idxlist xt_default_isect(Xt_idxlist idxlist_src, Xt_idxlist idxlist_dst, Xt_config config)
#define xt_idxlist_get_num_indices(idxlist)
static const intersection_get intersection_get_matrix[num_idxlist_classes][num_idxlist_classes]
Xt_idxlist xt_default_isect(Xt_idxlist idxlist_src, Xt_idxlist idxlist_dst, Xt_config config)
Xt_idxlist(* intersection_get)(Xt_idxlist idxlist_src, Xt_idxlist idxlist_dst, Xt_config config)
void xt_idxlist_intersection_init(void)
#define empty_isect
Xt_idxlist xt_idxlist_get_intersection_custom(Xt_idxlist idxlist_src, Xt_idxlist idxlist_dst, Xt_config config)
Xt_idxlist xt_idxlist_get_intersection(Xt_idxlist idxlist_src, Xt_idxlist idxlist_dst)
@ num_idxlist_classes
Xt_idxlist xt_idxsection_get_idxstripes_r_intersection(Xt_idxlist src_idxlist, Xt_idxlist dst_idxlist, Xt_config config)
Xt_idxlist xt_idxsection_get_intersection_with_other_idxlist(Xt_idxlist src_idxsection, Xt_idxlist dst_idxlist, Xt_config config)
Xt_idxlist xt_idxsection_get_idxstripes_intersection(Xt_idxlist src_idxlist, Xt_idxlist dst_idxlist, Xt_config config)
Xt_idxlist xt_idxsection_get_intersection(Xt_idxlist idxlist_src, Xt_idxlist idxlist_dst, Xt_config config)
Xt_idxlist xt_idxstripes_prealloc_new(const struct Xt_stripe *stripes, int num_stripes)
PPM_DSO_INTERNAL Xt_idxlist xt_idxstripes_get_idxvec_intersection(Xt_idxlist idxlist_src, Xt_idxlist idxlist_dst, Xt_config XT_UNUSED(config))
Xt_idxlist xt_idxstripes_get_intersection(Xt_idxlist idxlist_src, Xt_idxlist idxlist_dst, Xt_config config)
Xt_idxlist xt_idxvec_prealloc_new(const Xt_int *idxvec, int num_indices)
Definition xt_idxvec.c:308
Xt_idxlist xt_idxvec_get_intersection(Xt_idxlist idxlist_src, Xt_idxlist idxlist_dst, Xt_config config)
Definition xt_idxvec.c:605
PPM_DSO_INTERNAL Xt_idxlist xt_idxvec_get_idxstripes_intersection(Xt_idxlist idxlist_src, Xt_idxlist idxlist_dst, Xt_config config)
Definition xt_idxvec.c:683