OpenRadioss 2025.1.11
OpenRadioss project
Loading...
Searching...
No Matches
set_tools.cpp
Go to the documentation of this file.
1//Copyright> OpenRadioss
2//Copyright> Copyright (C) 1986-2025 Altair Engineering Inc.
3//Copyright>
4//Copyright> This program is free software: you can redistribute it and/or modify
5//Copyright> it under the terms of the GNU Affero General Public License as published by
6//Copyright> the Free Software Foundation, either version 3 of the License, or
7//Copyright> (at your option) any later version.
8//Copyright>
9//Copyright> This program is distributed in the hope that it will be useful,
10//Copyright> but WITHOUT ANY WARRANTY; without even the implied warranty of
11//Copyright> MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12//Copyright> GNU Affero General Public License for more details.
13//Copyright>
14//Copyright> You should have received a copy of the GNU Affero General Public License
15//Copyright> along with this program. If not, see <https://www.gnu.org/licenses/>.
16//Copyright>
17//Copyright>
18//Copyright> Commercial Alternative: Altair Radioss Software
19//Copyright>
20//Copyright> As an alternative to this open-source version, Altair also offers Altair Radioss
21//Copyright> software under a commercial license. Contact Altair to discuss further if the
22//Copyright> commercial version may interest you: https://www.altair.com/radioss/.
23#include <iostream>
24#include <algorithm>
25
26using namespace std;
27
28#define _FCALL
29
30#ifdef _WIN64
31
32#define remove_duplicates_ REMOVE_DUPLICATES
33#define union_2_sorted_sets_ UNION_2_SORTED_SETS
34#define intersect_2_sorted_sets_ INTERSECT_2_SORTED_SETS
35#define difference_2_sorted_sets_ DIFFERENCE_2_SORTED_SETS
36#define count_member_list_ COUNT_MEMBER_LIST
37
38
39#endif
40
41extern "C" {
42
43
44/* -----------------------------------------------------------------------------------------------------
45 remove_duplicates : removes duplicates in a sorted array
46 -----------------------------------------------------------------------------------------------------
47 int * array1 : input/output - array
48 int * size : input - size of array
49 int * new_size : output - new_size after duplicate removal
50 ------------------------------------------------------------------------------------------------ */
51 void remove_duplicates_ ( int * array, int * size, int *new_size)
52 {
53 if ( * size == 0){
54 *new_size=0;
55 return;
56 }
57 int sz=1 ;
58 int i=1;
59
60 while (i< *size) {
61 if ( array[i-1] != array[i]) {
62 array[sz] = array[i];
63 sz++;
64 }
65 i++;
66 }
67
68 *new_size = sz;
69 return;
70 }
71
72/* -----------------------------------------------------------------------------------------------------
73 union_2_sorted_sets : union 2 sets of sorted arrays.
74 The Arrays shall not contain 2 time same entity
75 The result arrays must be already allocated & big enough, result_size is the size of the nex set.
76 -----------------------------------------------------------------------------------------------------
77 int * array1 : input - array1
78 int * array1_size : input - size of array1
79 int * array2 : input - array2
80 int * array2_size : input - size of array2
81 int * result : output - result
82 int * result_size : output - number of members in result
83 ------------------------------------------------------------------------------------------------ */
84 void _FCALL union_2_sorted_sets_(int * array1, int * array1_size,
85 int * array2, int * array2_size,
86 int * result, int * result_size )
87 {
88
89 int *fin = set_union(array1, array1+*array1_size,
90 array2, array2+*array2_size,
91 result);
92
93 *result_size = fin-result;
94 }
95
96
97/* -----------------------------------------------------------------------------------------------------
98 intersect_2_sorted_sets : intersections of 2 sets of sorted arrays.
99 The Arrays shall not contain 2 time same entity
100 The result arrays must be already allocated & big enough, result_size is the size of the nex set.
101 -----------------------------------------------------------------------------------------------------
102 int * array1 : input - array1
103 int * array1_size : input - size of array1
104 int * array2 : input - array2
105 int * array2_size : input - size of array2
106 int * result : output - result
107 int * result_size : output - number of members in result
108 ------------------------------------------------------------------------------------------------ */
109 void _FCALL intersect_2_sorted_sets_(int * array1, int * array1_size,
110 int * array2, int * array2_size,
111 int * result, int * result_size )
112 {
113
114 int *fin = set_intersection(array1, array1+*array1_size,
115 array2, array2+*array2_size,
116 result);
117
118 *result_size = fin-result;
119 }
120
121/* -----------------------------------------------------------------------------------------------------
122 difference_2_sorted_sets : difference of 2 sets of sorted arrays.
123 Does array1-array2 : Removes all members of array2 in array1
124 The Arrays shall not contain 2 time same entity
125 The result arrays must be already allocated & big enough, result_size is the size of the nex set.
126 -----------------------------------------------------------------------------------------------------
127 int * array1 : input - array1
128 int * array1_size : input - size of array1
129 int * array2 : input - array2
130 int * array2_size : input - size of array2
131 int * result : output - result
132 int * result_size : output - number of members in result
133 ------------------------------------------------------------------------------------------------ */
134 void _FCALL difference_2_sorted_sets_(int * array1, int * array1_size,
135 int * array2, int * array2_size,
136 int * result, int * result_size )
137 {
138
139 int *fin = set_difference(array1, array1+*array1_size,
140 array2, array2+*array2_size,
141 result);
142
143 *result_size = fin-result;
144 }
145/* -----------------------------------------------------------------------------------------------------
146 count_member_list : count the number of appearances of union_list's members in the merged_list
147 -----------------------------------------------------------------------------------------------------
148 int * union_list : input - size=size_union_list
149 int * size_union_list : input - size of union_list
150 int * merged_list : input - size=size_merged_list
151 int * size_merged_list : input - size of merged_list
152 int * number_appearance : output - number of appearance of the union_list's members in the merged_list
153 int * proc_id : output - processor id of the segment
154 ------------------------------------------------------------------------------------------------ */
155 void _FCALL count_member_list_(int * union_list, int * size_union_list,
156 int * merged_list, int * size_merged_list,
157 int * number_appearance, int * proc_id )
158 {
159 int max_number_appearance = 0 ;
160 for(int i=0; i<*size_union_list ; i++)
161 {
162 int my_value = union_list[i] ;
163 int mycount = std::count ( merged_list, merged_list+ *size_merged_list, my_value);
164 number_appearance[i] = mycount ;
165 if(max_number_appearance<mycount)
166 {
167 *proc_id = i+1 ;
168 max_number_appearance = mycount;
169 }
170 }
171 }
172
173
174
175}
176
177
178
#define _FCALL
static int proc_id
Definition rad2rad_c.c:126
void _FCALL intersect_2_sorted_sets_(int *array1, int *array1_size, int *array2, int *array2_size, int *result, int *result_size)
void _FCALL count_member_list_(int *union_list, int *size_union_list, int *merged_list, int *size_merged_list, int *number_appearance, int *proc_id)
void remove_duplicates_(int *array, int *size, int *new_size)
Definition set_tools.cpp:51
void _FCALL union_2_sorted_sets_(int *array1, int *array1_size, int *array2, int *array2_size, int *result, int *result_size)
Definition set_tools.cpp:84
void _FCALL difference_2_sorted_sets_(int *array1, int *array1_size, int *array2, int *array2_size, int *result, int *result_size)