Orbiter 2022
Combinatorial Objects
int_vector.cpp
Go to the documentation of this file.
1// int_vector.cpp
2//
3// Anton Betten
4//
5// Aug 12, 2014
6
7
8
9
10#include "foundations.h"
11
12
13using namespace std;
14
15
16namespace orbiter {
17namespace layer1_foundations {
18namespace data_structures {
19
20
22{
23 null();
24}
25
27{
28 freeself();
29}
30
32{
33 M = NULL;
34 m = 0;
35 alloc_length = 0;
36}
37
39{
40 if (M) {
41 FREE_lint(M);
42 }
43 null();
44}
45
47{
48 freeself();
49 M = NEW_lint(len);
50 m = 0;
51 alloc_length = len;
52}
53
54void int_vector::allocate_and_init(int len, long int *V)
55{
56 freeself();
57 M = NEW_lint(len);
58 m = len;
59 alloc_length = len;
60 Lint_vec_copy(V, M, len);
61}
62
64{
65 int i;
66
67 freeself();
68 M = NEW_lint(len);
69 m = len;
70 alloc_length = len;
71 for (i = 0; i < len; i++) {
72 M[i] = V[i];
73 }
74}
75
77{
78 int verbose_level = 0;
79 int *perm;
80 int degree;
81 string_tools ST;
82
83 ST.scan_permutation_from_string(s, perm, degree, verbose_level);
84 allocate_and_init_int(degree, perm);
85 FREE_int(perm);
86}
87
88void int_vector::read_ascii_file(std::string &fname)
89{
90 int verbose_level = 0;
91 long int *the_set;
92 int set_size;
94
95 Fio.read_set_from_file(fname, the_set, set_size, verbose_level);
96 allocate_and_init(set_size, the_set);
97 FREE_lint(the_set);
98}
99
100void int_vector::read_binary_file_int4(std::string &fname)
101{
102 int verbose_level = 0;
103 long int *the_set;
104 int set_size;
106
107 Fio.read_set_from_file_int4(fname, the_set, set_size, verbose_level);
108 allocate_and_init(set_size, the_set);
109 FREE_lint(the_set);
110}
111
112long int &int_vector::s_i(int i)
113{
114 return M[i];
115}
116
118{
119 return m;
120}
121
122void int_vector::print(ostream &ost)
123{
124 Lint_vec_print(ost, M, m);
125}
126
128{
130}
131
132int int_vector::search(int a, int &idx)
133{
134 sorting Sorting;
135
136 return Sorting.lint_vec_search(M, m, a, idx, 0);
137}
138
140{
141 sorting Sorting;
142
143 Sorting.lint_vec_heapsort(M, m);
144}
145
147{
148 long int *M1;
149 int new_alloc_length;
150
151 if (alloc_length) {
152 new_alloc_length = alloc_length * 2;
153 }
154 else {
155 new_alloc_length = 1;
156 }
157 M1 = NEW_lint(new_alloc_length);
158 Lint_vec_copy(M, M1, m);
159 if (M) {
160 FREE_lint(M);
161 }
162 M = M1;
163 alloc_length = new_alloc_length;
164}
165
167{
168 if (m == alloc_length) {
169 make_space();
170 }
171 M[m] = a;
172 m++;
173}
174
175void int_vector::insert_at(int a, int idx)
176{
177 int i;
178
179 if (m == alloc_length) {
180 make_space();
181 }
182 for (i = m; i > idx; i--) {
183 M[i] = M[i - 1];
184 }
185 M[idx] = a;
186 m++;
187}
188
190{
191 int idx;
192
193 if (!search(a, idx)) {
194 insert_at(a, idx);
195 }
196}
197
199{
200 sorting Sorting;
201
203}
204
205void int_vector::write_to_ascii_file(std::string &fname)
206{
208
209 Fio.write_set_to_file(fname, M, m, 0 /*verbose_level*/);
210}
211
213{
215
216 Fio.write_set_to_file_as_int4(fname, M, m, 0 /*verbose_level*/);
217}
218
219void int_vector::write_to_csv_file(std::string &fname, const char *label)
220{
222
223 Fio.lint_vec_write_csv(M, m, fname, label);
224}
225
227{
229
230 return D.lint_vec_hash(M, m);
231}
232
234{
236}
237
239{
241}
242
243
244
245
246}}}
247
a catch-all container class for everything related to data structures
void write_to_csv_file(std::string &fname, const char *label)
Definition: int_vector.cpp:219
a collection of functions related to sorted vectors
void lint_vec_sort_and_remove_duplicates(long int *v, int &len)
Definition: sorting.cpp:195
int lint_vec_search(long int *v, int len, long int a, int &idx, int verbose_level)
Definition: sorting.cpp:1157
functions related to strings and character arrays
void scan_permutation_from_string(const char *s, int *&perm, int &degree, int verbose_level)
void read_set_from_file_int4(std::string &fname, long int *&the_set, int &set_size, int verbose_level)
Definition: file_io.cpp:2544
void lint_vec_write_csv(long int *v, int len, std::string &fname, const char *label)
Definition: file_io.cpp:1191
void write_set_to_file_as_int4(std::string &fname, long int *the_set, int set_size, int verbose_level)
Definition: file_io.cpp:2629
void read_set_from_file(std::string &fname, long int *&the_set, int &set_size, int verbose_level)
Definition: file_io.cpp:2374
void write_set_to_file(std::string &fname, long int *the_set, int set_size, int verbose_level)
Definition: file_io.cpp:2434
#define Lint_vec_copy(A, B, C)
Definition: foundations.h:694
#define FREE_int(p)
Definition: foundations.h:640
#define Lint_vec_print(A, B, C)
Definition: foundations.h:686
#define FREE_lint(p)
Definition: foundations.h:642
#define NEW_lint(n)
Definition: foundations.h:628
orbiter_kernel_system::orbiter_session * Orbiter
global Orbiter session
the orbiter library for the classification of combinatorial objects