Orbiter 2022
Combinatorial Objects
set_builder.cpp
Go to the documentation of this file.
1/*
2 * set_builder.cpp
3 *
4 * Created on: Nov 7, 2020
5 * Author: betten
6 */
7
8
9
10
11#include "foundations.h"
12
13using namespace std;
14
15
16
17namespace orbiter {
18namespace layer1_foundations {
19namespace data_structures {
20
21
23{
24 Descr = NULL;
25 set = NULL;
26 sz = 0;
27}
28
30{
31 if (set) {
33 set = NULL;
34 }
35}
36
38 int verbose_level)
39{
40 int f_v = (verbose_level >= 1);
41
42 if (f_v) {
43 cout << "set_builder::init" << endl;
44 }
45
47
49 if (f_v) {
50 cout << "set_builder::init using index set through loop, low="
52 << " upper_bound=" << Descr->index_set_loop_upper_bound
53 << " increment=" << Descr->index_set_loop_increment << endl;
54 }
55 int i, cnt;
56 long int x, y;
57 int index_set_size;
58
59 index_set_size = 0;
60 for (i = Descr->index_set_loop_low; i < Descr->index_set_loop_upper_bound;
62 index_set_size++;
63 }
64 set = NEW_lint(2 * index_set_size);
65 cnt = 0;
66 for (i = Descr->index_set_loop_low; i < Descr->index_set_loop_upper_bound;
68
69 x = i;
71
72 set[cnt] = y;
73 cnt++;
74
75
77
79
80 set[cnt] = y;
81 cnt++;
82 }
83
84 }
85 sz = cnt;
86 }
87 else if (Descr->f_set_builder) {
88 if (f_v) {
89 cout << "set_builder::init using recursive set builder" << endl;
90 }
91 set_builder *S;
92
94 S->init(Descr->Descr, verbose_level);
95
96 int i, cnt;
97 long int x, y;
98
99 set = NEW_lint(2 * S->sz);
100 cnt = 0;
101 for (i = 0; i < S->sz; i++) {
102
103 x = S->set[i];
105
106 set[cnt] = y;
107 cnt++;
108
110
112
113 set[cnt] = y;
114 cnt++;
115 }
116
117 }
118 sz = cnt;
119
120 FREE_OBJECT(S);
121 }
122 else if (Descr->f_here) {
123 if (f_v) {
124 cout << "set_builder::init -here" << endl;
125 }
126 long int *Index_set;
127 int Index_set_sz;
128
129 Lint_vec_scan(Descr->here_text, Index_set, Index_set_sz);
130
131 int i, cnt;
132 long int x, y;
133
134 set = NEW_lint(2 * Index_set_sz);
135 cnt = 0;
136 for (i = 0; i < Index_set_sz; i++) {
137
138 x = Index_set[i];
140
141 set[cnt] = y;
142 cnt++;
143
145
147
148 set[cnt] = y;
149 cnt++;
150 }
151 }
152 FREE_lint(Index_set);
153 sz = cnt;
154
155 }
156 else if (Descr->f_file) {
157 if (f_v) {
158 cout << "set_builder::init -file " << Descr->file_name << endl;
159 }
161 int m, n;
162
163 Fio.lint_matrix_read_csv(Descr->file_name, set, m, n, verbose_level);
164 if (f_v) {
165 cout << "set_builder::init read a csv file of size " << m << " x " << n << endl;
166 }
167 sz = m * n;
168
169 }
170 else {
171 cout << "set_builder::init unrecognized command to create the set" << endl;
172 exit(1);
173 }
174 if (f_v) {
175 cout << "set_builder::init created set of size " << sz << endl;
176 Lint_vec_print(cout, set, sz);
177 cout << endl;
178 }
179
180
181 if (f_v) {
182 cout << "set_builder::init done" << endl;
183 }
184}
185
186
188{
189 long int y;
190
193 }
194 else {
195 y = x;
196 }
197 return y;
198}
199
201{
202 long int y;
203
205 return y;
206}
207
208
209}}}
210
211
to define a set of integers for class set_builder
to create a set of integers from class set_builder_description
void init(set_builder_description *Descr, int verbose_level)
Definition: set_builder.cpp:37
void lint_matrix_read_csv(std::string &fname, long int *&M, int &m, int &n, int verbose_level)
Definition: file_io.cpp:1558
#define Lint_vec_scan(A, B, C)
Definition: foundations.h:717
#define NEW_OBJECT(type)
Definition: foundations.h:638
#define Lint_vec_print(A, B, C)
Definition: foundations.h:686
#define FREE_OBJECT(p)
Definition: foundations.h:651
#define FREE_lint(p)
Definition: foundations.h:642
#define NEW_lint(n)
Definition: foundations.h:628
the orbiter library for the classification of combinatorial objects