barvinok 0.41.8
[barvinok.git] / zsolve / indexarray.c
blob70696c101a05753bd1c42e4f3460e59ea7808c97
1 /*
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.
23 #include "indexarray.h"
25 #include <stdlib.h>
26 #include <stdio.h>
27 #include <assert.h>
29 // //
31 IndexArray createIndexArray()
33 IndexArray array = (IndexArray)malloc(sizeof(indexarray_t));
35 if (array==NULL)
37 fprintf(stderr, "Fatal Error: Could not allocate memory for IndexArray!\n");
38 exit(1);
41 array->Size = 0;
42 array->Data = NULL;
44 return array;
47 // //
49 void deleteIndexArray(IndexArray array)
51 if (array)
53 if (array->Data)
54 free(array->Data);
55 free(array);
59 // //
61 void appendToIndexArray(IndexArray array, int index)
63 #ifndef NDEBUG
64 int i;
65 assert(array);
66 for (i=0; i<array->Size; i++)
67 assert(array->Data[i]!=index);
68 #endif
70 assert(array);
72 array->Size++;
73 array->Data = (int *)realloc(array->Data, array->Size*sizeof(int));
74 array->Data[array->Size-1] = index;
77 // //
79 void fprintIndexArray(FILE *stream, IndexArray array)
81 int i;
83 assert(array);
84 assert(stream);
86 for (i=0; i<array->Size; i++)
87 fprintf(stream, i>0 ? " %d" : "%d", array->Data[i]);
90 // //