1 /* cone.cpp -- Linked list of cones
2
3 Copyright 2002-2004 Jesus A. De Loera, David Haws, Raymond
4 Hemmecke, Peter Huggins, Jeremy Tauzer, Ruriko Yoshida
5 Copyright 2006 Matthias Koeppe
6
7 This file is part of LattE.
8
9 LattE is free software; you can redistribute it and/or modify it
10 under the terms of the version 2 of the GNU General Public License
11 as published by the Free Software Foundation.
12
13 LattE is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with LattE; if not, write to the Free Software Foundation,
20 Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
21 */
22
23 #include <stdlib.h>
24 #include "ramon.h"
25
listCone()26 listCone::listCone(): vertex(NULL), rays(NULL), subspace_generators(NULL),
27 facets(NULL), equalities(NULL), latticePoints(NULL), rest(NULL)
28 {
29 }
30
31 /* ----------------------------------------------------------------- */
lengthListVector(const listVector * LIST)32 int lengthListVector(const listVector* LIST) {
33 int len=0;
34
35 while (LIST) {len++; LIST = LIST->rest;}
36 return (len);
37 }
38
39 /* ----------------------------------------------------------------- */
appendVectorToListVector(const vec_ZZ & v,listVector * REST)40 listVector* appendVectorToListVector(const vec_ZZ &v, listVector *REST) {
41 // listVector *LIST;
42 listVector * LIST = new listVector(v);
43 LIST->rest = REST;
44 return (LIST);
45 }
46
47 /* ----------------------------------------------------------------- */
copyListVector(listVector * l)48 listVector *copyListVector(listVector *l)
49 {
50 listVector *result = NULL;
51 listVector **rest_p = &result;
52 while (l != NULL) {
53 *rest_p = new listVector(l->first, 0, l->index_hint);
54 rest_p = &(*rest_p)->rest;
55 l = l->rest;
56 }
57 return result;
58 }
59
60 /* ----------------------------------------------------------------- */
freeListVector(listVector * p)61 void freeListVector( listVector* p )
62 {
63 while (p != NULL) {
64 listVector *rest = p->rest;
65 delete p;
66 p = rest;
67 }
68 }
69
70 /* ----------------------------------------------------------------- */
createListCone()71 listCone* createListCone() {
72 listCone* z;
73
74 z = new listCone;
75 if (z==0) {
76 cerr << "Memory exhausted" << endl;
77 exit(1);
78 }
79
80 z->coefficient=1;
81 z->vertex=0;
82 z->rays=0;
83 z->facets=0;
84 z->determinant = 0;
85 z->dual_determinant = 0;
86 z->latticePoints=0;
87 z->subspace_generators = 0;
88 z->equalities = 0;
89 z->rest=0;
90
91 z->index_hint = -1;
92
93 return (z);
94 }
95 /* ----------------------------------------------------------------- */
lengthListCone(listCone * LIST)96 int lengthListCone(listCone* LIST) {
97 int len=0;
98
99 while (LIST) {len++; LIST = LIST->rest;}
100 return (len);
101 }
102 /* ----------------------------------------------------------------- */
freeCone(listCone * cone)103 void freeCone(listCone *cone)
104 {
105 delete cone->vertex;
106 freeListVector(cone->rays);
107 freeListVector(cone->facets);
108 freeListVector(cone->latticePoints);
109 freeListVector(cone->subspace_generators);
110 freeListVector(cone->equalities);
111 delete cone;
112 }
113
freeListCone(listCone * list)114 void freeListCone(listCone *list)
115 {
116 while (list != NULL) {
117 listCone *rest = list->rest;
118 freeCone(list);
119 list = rest;
120 }
121 }
122
appendListCones(listCone * A,listCone * B)123 listCone *appendListCones(listCone *A, listCone *B)
124 {
125 if (A == NULL) return B;
126 else {
127 listCone *C;
128 for (C = A; C->rest!=NULL; C = C->rest);
129 C->rest = B;
130 return A;
131 }
132 }
133
copyCone(const listCone * cone)134 listCone *copyCone(const listCone *cone)
135 {
136 listCone *copy = createListCone();
137 copy->coefficient = cone->coefficient;
138 copy->vertex = new Vertex(*cone->vertex);
139 copy->determinant = cone->determinant;
140 copy->rays = copyListVector(cone->rays);
141 copy->dual_determinant = cone->dual_determinant;
142 copy->facets = copyListVector(cone->facets);
143 copy->facet_divisors = cone->facet_divisors;
144 copy->latticePoints = copyListVector(cone->latticePoints);
145 copy->lattice_points_scalar_products = cone->lattice_points_scalar_products;
146 copy->subspace_generators = copyListVector(cone->subspace_generators);
147 copy->equalities = copyListVector(cone->equalities);
148 copy->rest = NULL;
149 copy->index_hint = cone->index_hint;
150 return copy;
151 }
152
153
154 //Copy a list of cones.
copyListCone(const listCone * cone)155 listCone *copyListCone(const listCone *cone)
156 {
157 if ( !cone)
158 return NULL;
159 listCone *copyList = copyCone(cone); //copy one cone.
160 copyList->rest = copyListCone(cone->rest); //copy the rest.
161 return copyList;
162 }
163
ambient_cone_dimension(const listCone * cone)164 int ambient_cone_dimension(const listCone *cone)
165 {
166 if (cone == NULL) return 0;
167 return cone->vertex->vertex->numerators().length();
168 }
169