2 4ti2 -- A software package for algebraic, geometric and combinatorial
3 problems on linear spaces.
5 Copyright (C) 2006 4ti2 team.
6 Main author(s): Matthias Walter.
8 This program is free software; you can redistribute it and/or
9 modify it under the terms of the GNU General Public License
10 as published by the Free Software Foundation; either version 2
11 of the License, or (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
31 Vector
createVector(int size
)
33 Vector vector
= (Vector
)malloc(size
*sizeof(vector_t
));
37 fprintf(stderr
, "Fatal Error (%s/%d): Could not allocate memory for Vector!\n", __FILE__
, __LINE__
);
45 Vector
createZeroVector(int size
)
47 Vector vector
= (Vector
)calloc(size
, sizeof(vector_t
));
51 fprintf(stderr
, "Fatal Error (%s/%d): Could not allocate memory for Vector!\n", __FILE__
, __LINE__
);
60 inline void deleteVector(Vector vector
)
67 Vector
copyVector(Vector old
, int size
)
69 Vector
new = (Vector
)malloc(size
*sizeof(vector_t
));
73 fprintf(stderr
, "Fatal Error (%s/%d): Could not allocate memory for Vector!\n", __FILE__
, __LINE__
);
78 new[size
] = old
[size
];
85 void fprintVector(FILE *stream
, Vector vector
, int size
)
92 fprintf(stream
, "%2d", vector
[0]);
93 for (i
=1; i
<size
; i
++)
94 fprintf(stream
, " %2d", vector
[i
]);
99 inline void printVector(Vector vector
, int size
)
103 fprintVector(stdout
, vector
, size
);
108 Vector
readVector(FILE *stream
, int size
)
115 vector
= createVector(size
);
118 for (i
=0; i
<size
; i
++)
120 if (fscanf(stream
, "%d", &(vector
[i
]))<1)
122 deleteVector(vector
);
132 int normVector(Vector vector
, int size
)
140 norm
+= abs(vector
[size
]);
147 void swapVector(Vector vector
, int a
, int b
)
154 vector
[a
] = vector
[b
];
160 int gcdVector(Vector vector
, int size
)
168 for (i
=1; i
<size
; i
++)
169 result
= gcd(result
, vector
[i
]);
176 int lexCompareInverseVector(Vector vector
, int size
) {
178 while (i
<size
&& vector
[i
]==0)
180 return i
==size
? 0 : vector
[i
];