Macaulay2 Engine
Loading...
Searching...
No Matches
geobucket.hpp
Go to the documentation of this file.
1// Copyright 1996 Michael E. Stillman
2
34
35// This should probably be done by:
36// (a) making a type FREEMODULETYPE, that FreeModule, and res_poly
37// both can inherit from: but this is a bit of a kludge...
38// (b) making a vector type with a next and coeff field, that
39// is then inherited by vecterm, resterm.
40// Redefine:
41// FREEMODULETYPE
42// routines that should be implemented in this class:
43// add_to, compare, get_ring, remove
44// VECTYPE
45// fields of this structure type should include:
46// next, coeff
47
48// GEOHEAP_SIZE: defined in style.hpp
49// heap_size: defined in object.cpp
50
51template <class FREEMODULETYPE, class VECTYPE>
53{
54 FREEMODULETYPE *F; // Our elements will be vectors in here
55 const Ring *K; // The coefficient ring
58 int mLead; // set after a call to get_lead_term.
59 // set negative after each call to add,
60 // or remove_lead_term
61public:
62 geobucket(FREEMODULETYPE *F);
64
65 void add(VECTYPE p);
66 const VECTYPE get_lead_term(); // Returns NULL if none.
67 VECTYPE remove_lead_term(); // Returns NULL if none.
68
69 FREEMODULETYPE *get_target() const { return F; }
70 VECTYPE value(); // Returns the linearized value, and resets the geobucket.
71
72 VECTYPE debug_list(int i) { return heap[i]; } // DO NOT USE, except for debugging purposes!
73 VECTYPE current_value() const; // Adds up all the elements and returns this value
74 // Mainly used for debugging.
75};
76
77template <class FREEMODULETYPE, class VECTYPE>
79: F(FF),
80 K(FF->get_ring()->getCoefficientRing()),
81 top_of_heap(-1),
82 mLead(-1)
83{
84 // set K
85 int i;
86 for (i=0; i<GEOHEAP_SIZE; i++)
87 heap[i] = NULL;
88}
89
90template <class FREEMODULETYPE, class VECTYPE>
92{
93 // The user of this class must insure that all 'vecterm's
94 // have been removed first. Thus, we don't need to
95 // do anything here.
96}
97
98template <class FREEMODULETYPE, class VECTYPE>
100{
101 mLead = -1;
102 int len = F->n_terms(p);
103 int i= 0;
104 while (len >= heap_size[i]) i++;
105 F->add_to(heap[i], p);
106 len = F->n_terms(heap[i]);
107 p = NULL;
108 while (len >= heap_size[i])
109 {
110 i++;
111 F->add_to(heap[i], heap[i-1]);
112 len = F->n_terms(heap[i]);
113 heap[i-1] = NULL;
114 }
115 if (i > top_of_heap)
116 top_of_heap = i;
117}
118
119template <class FREEMODULETYPE, class VECTYPE>
121{
122 int lead_so_far = -1;
123 for (int i=0; i <= top_of_heap; i++)
124 {
125 if (heap[i] == NULL) continue;
126 if (lead_so_far < 0)
127 {
128 lead_so_far = i;
129 continue;
130 }
131 int cmp = F->compare(heap[lead_so_far], heap[i]);
132 if (cmp == GT) continue;
133 if (cmp == LT)
134 {
135 lead_so_far = i;
136 continue;
137 }
138 // At this point we have equality
139 K->add_to(heap[lead_so_far]->coeff, heap[i]->coeff);
140 VECTYPE tmp = heap[i];
141 heap[i] = tmp->next;
142 tmp->next = NULL;
143 F->remove(tmp);
144
145 if (K->is_zero(heap[lead_so_far]->coeff))
146 {
147 // Remove, and start over
148 tmp = heap[lead_so_far];
149 heap[lead_so_far] = tmp->next;
150 tmp->next = NULL;
151 F->remove(tmp);
152 lead_so_far = -1;
153 i = -1;
154 }
155 }
156 mLead = lead_so_far;
157 if (lead_so_far < 0) return NULL;
158 VECTYPE result = heap[lead_so_far];
159 return result;
160}
161
162template <class FREEMODULETYPE, class VECTYPE>
164{
165 if (mLead < 0) get_lead_term();
166 if (mLead < 0) return NULL;
167 VECTYPE result = heap[mLead];
168 heap[mLead] = result->next;
169 result->next = NULL;
170 mLead = -1;
171 return result;
172}
173
174template <class FREEMODULETYPE, class VECTYPE>
176{
177 VECTYPE result = NULL;
178 for (int i=0; i<=top_of_heap; i++)
179 {
180 if (heap[i] == NULL) continue;
181 F->add_to(result, heap[i]);
182 heap[i] = NULL;
183 }
184 top_of_heap = -1;
185 return result;
186}
187
188template <class FREEMODULETYPE, class VECTYPE>
190{
191 VECTYPE result = NULL;
192 for (int i=0; i<=top_of_heap; i++)
193 {
194 if (heap[i] == NULL) continue;
195 VECTYPE tmp = F->copy(heap[i]);
196 F->add_to(result, tmp);
197 }
198 return result;
199}
200
201// Local Variables:
202// compile-command: "make -C $M2BUILDDIR/Macaulay2/e "
203// End:
xxx xxx xxx
Definition ring.hpp:102
void add(VECTYPE p)
Definition geobucket.hpp:99
geobucket(FREEMODULETYPE *F)
Definition geobucket.hpp:78
VECTYPE remove_lead_term()
FREEMODULETYPE * get_target() const
Definition geobucket.hpp:69
VECTYPE value()
VECTYPE debug_list(int i)
Definition geobucket.hpp:72
const VECTYPE get_lead_term()
VECTYPE current_value() const
const int heap_size[GEOHEAP_SIZE]
Definition engine.cpp:53
int p
VALGRIND_MAKE_MEM_DEFINED & result(result)
const int GT
Definition style.hpp:41
#define GEOHEAP_SIZE
Definition style.hpp:46
const int LT
Definition style.hpp:39