Debian Codegraph @

packages/seacas/applications/nem_slice/elb_util.h

raw
1 /*
2 * Copyright(C) 1999-2022 National Technology & Engineering Solutions
3 * of Sandia, LLC (NTESS). Under the terms of Contract DE-NA0003525 with
4 * NTESS, the U.S. Government retains certain rights in this software.
5 *
6 * See packages/seacas/LICENSE for details
7 */
8 #pragma once
9
10 #include <cstddef> // for size_t
11 #include <cstdint>
12 #include <vector>
13
14 #if defined(WIN32) || defined(__WIN32__) || defined(_WIN32) || defined(_MSC_VER) || \
15 defined(__MINGW32__) || defined(_WIN64) || defined(__MINGW64__)
16 #if !defined(__MINGW32__)
17 #define strcasecmp stricmp
18 #define strncasecmp strnicmp
19 #endif
20 #endif
21
22 /* Function prototypes */
23 extern int token_compare(char *token, /* The input character string */
24 const char *key /* The key to compare with token */
25 );
26
27 extern void strip_string(char inp_str[], /* The string to strip */
28 const char *tokens /* The tokens to strip from the beginning and
29 * end of the input string */
30 );
31
32 extern void clean_string(char inp_str[], /* The string to clean */
33 const char *tokens /* The tokens to strip multiple copies of */
34 );
35
36 extern void string_to_lower(char in_string[], /* The string to convert to lower case */
37 char cval /* Character where to stop */
38 );
39
40 template <typename INT> void gds_qsort(INT v[], size_t N);
41
42 template <typename INT> void qsort4(INT *v1, INT *v2, INT *v3, INT *v4, size_t N);
43
44 template <typename INT> void qsort2(INT *v1, INT *v2, size_t N);
45
46 template <typename INT> inline void SWAP(INT &r, INT &s)
47 {
48 INT t = r;
49 r = s;
50 s = t;
51 }
52
53 template <typename INT> void siftDown(INT *a, INT *b, size_t start, size_t end)
54 {
55 size_t root = start;
56
57 while (root * 2 + 1 < end) {
58 size_t child = 2 * root + 1;
59 if ((child + 1 < end) && (a[child] < a[child + 1])) {
60 child += 1;
61 }
62 if (a[root] < a[child]) {
63 SWAP(a[child], a[root]);
64 SWAP(b[child], b[root]);
65 root = child;
66 }
67 else {
68 return;
69 }
70 }
71 }
72
73 template <typename INT> void sort2(int64_t count, INT ra[], INT rb[])
74 {
75 if (count <= 1) {
76 return;
77 }
78 /* heapify */
79 for (int64_t start = (count - 2) / 2; start >= 0; start--) {
80 siftDown(ra, rb, start, count);
81 }
82
83 for (size_t end = count - 1; end > 0; end--) {
84 SWAP(ra[end], ra[0]);
85 SWAP(rb[end], rb[0]);
86 siftDown(ra, rb, 0, end);
87 }
88 }
89
90 template <typename INT> void sort3(int64_t count, INT ra[], INT rb[], INT rc[]);
91
92 template <typename INT>
93 void find_first_last(INT val, size_t vecsize, INT *vector, INT *first, INT *last);
94
95 template <typename INT>
96 int64_t find_int(INT value1, INT value2, size_t start, size_t stop, INT *vector1, INT *vector2);
97
98 template <typename INT, typename INT2> int64_t in_list(INT value, size_t count, const INT2 *vector);
99
100 template <typename INT, typename INT2> int64_t in_list(INT value, const std::vector<INT2> &vector);
101
102 extern int roundfloat(float value /* the value to be rounded */
103 );
104
105 template <typename INT>
106 size_t find_inter(const INT set1[], /* the first set of integers */
107 const INT set2[], /* the second set of integers */
108 size_t length1, /* the length of the first set */
109 size_t length2, /* the length of the second set */
110 INT inter_ptr[] /* the values in the intersection */
111 );
112
113 template <typename INT> int64_t bin_search2(INT value, size_t num, INT List[]);