YAC 3.17.0
Yet Another Coupler
Loading...
Searching...
No Matches
utils_common.h
Go to the documentation of this file.
1// Copyright (c) 2024 The YAC Authors
2//
3// SPDX-License-Identifier: BSD-3-Clause
4
5#ifndef UTILS_COMMON_H
6#define UTILS_COMMON_H
7
8#include "yac_config.h"
9
10#ifdef YAC_OPENMP_ENABLED
11#include <omp.h>
12#endif
13
14#include <stdlib.h>
15#include "ppm/ppm_xfuncs.h"
16#include "ppm/core.h"
17#include "yac_types.h"
18#include "yac_assert.h"
19
25static inline void yac_remove_duplicates_int(int * array, size_t * n) {
26
27 size_t const N = *n;
28 size_t pos = 0;
29
30 if (N == 0) return;
31
32 int prev = array[0];
33
34 for (size_t i = 1; i < N; ++i) {
35
36 if (array[i] == prev) continue;
37
38 prev = array[i];
39 ++pos;
40
41 if (pos != i) array[pos] = array[i];
42 }
43
44 *n = pos + 1;
45}
46
84 const char * name;
85 int type;
86};
87
100char const * yac_name_type_pair_get_name(
101 struct yac_name_type_pair const * pairs, size_t count, int type);
102
111 struct yac_name_type_pair const * pairs, size_t count, char const * name);
112
118#define DEF_NAME_TYPE_PAIR(NAME, TYPE) {.name = #NAME, .type = (int)(TYPE)}
119#define DEF_NAME_TYPE_PAIRS(NAME, ...) \
120 static const struct yac_name_type_pair NAME [] = {__VA_ARGS__}; \
121 enum { NAME ## _size = sizeof(NAME) / sizeof(NAME[0]) };
122
127void yac_qsort_index(
128 void * a, size_t count, size_t size,
129 int (*compare)(void const *, void const *), size_t * idx);
130
131/* =======================================================================
132 Macros
133 ======================================================================= */
134
135#ifndef MAX
136#define MAX(a,b) ((a) > (b) ? (a) : (b))
137#endif
138
139#ifndef MIN
140#define MIN(a,b) ((a) < (b) ? (a) : (b))
141#endif
142
143#ifdef YAC_OPENMP_ENABLED
144#define YAC_OMP_PARALLEL _Pragma("omp parallel")
145#define YAC_OMP_FOR _Pragma("omp for")
146#else
147#define YAC_OMP_PARALLEL
148#define YAC_OMP_FOR
149#endif
150
151#endif // UTILS_H
152
int yac_name_type_pair_get_type(struct yac_name_type_pair const *pairs, size_t count, char const *name)
Definition utils_core.c:26
char const * yac_name_type_pair_get_name(struct yac_name_type_pair const *pairs, size_t count, int type)
Definition utils_core.c:17
enum callback_type type
add versions of standard API functions not returning on error
const char * name
String name (e.g., "true")
int type
Integer type value (e.g., 1)
#define N
char const * name
Definition toy_scrip.c:114
static void yac_remove_duplicates_int(int *array, size_t *n)
void yac_qsort_index(void *a, size_t count, size_t size, int(*compare)(void const *, void const *), size_t *idx)
Definition quicksort.c:185