1 /* Frobby: Software for monomial ideal computations.
2    Copyright (C) 2007 Bjarke Hammersholt Roune (www.broune.com)
3 
4    This program is free software; you can redistribute it and/or modify
5    it under the terms of the GNU General Public License as published by
6    the Free Software Foundation; either version 2 of the License, or
7    (at your option) any later version.
8 
9    This program is distributed in the hope that it will be useful,
10    but WITHOUT ANY WARRANTY; without even the implied warranty of
11    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12    GNU General Public License for more details.
13 
14    You should have received a copy of the GNU General Public License
15    along with this program.  If not, see http://www.gnu.org/licenses/.
16 */
17 #include "stdinc.h"
18 #include "IrreducibleIdealSplitter.h"
19 
20 #include "VarNames.h"
21 #include "TermTranslator.h"
22 
IrreducibleIdealSplitter(BigTermConsumer & consumer)23 IrreducibleIdealSplitter::IrreducibleIdealSplitter
24 (BigTermConsumer& consumer):
25   _consumer(consumer),
26   _inList(false) {
27 }
28 
IrreducibleIdealSplitter(auto_ptr<BigTermConsumer> consumer)29 IrreducibleIdealSplitter::IrreducibleIdealSplitter
30 (auto_ptr<BigTermConsumer> consumer):
31   _consumer(*consumer),
32   _consumerDeleter(consumer),
33   _inList(false) {
34 }
35 
consumeRing(const VarNames & names)36 void IrreducibleIdealSplitter::consumeRing(const VarNames& names) {
37   _tmp.reset(names.getVarCount());
38   _bigTmp.resize(names.getVarCount());
39   _consumer.consumeRing(names);
40 
41   ASSERT(_tmp.isIdentity());
42   ASSERT(_bigTmp == vector<mpz_class>(_bigTmp.size()));
43 }
44 
beginConsumingList()45 void IrreducibleIdealSplitter::beginConsumingList() {
46   ASSERT(!_inList);
47   _inList = true;
48   _consumer.beginConsumingList();
49 }
50 
beginConsuming()51 void IrreducibleIdealSplitter::beginConsuming() {
52   if (!_inList)
53     _consumer.beginConsumingList();
54 }
55 
consume(const Term & term)56 void IrreducibleIdealSplitter::consume(const Term& term) {
57   ASSERT(term.getVarCount() == _tmp.getVarCount());
58   ASSERT(_tmp.isIdentity());
59 
60   _consumer.beginConsuming();
61   for (size_t var = 0; var < term.getVarCount(); ++var) {
62     if (term[var] != 0) {
63       _tmp[var] = term[var];
64       _consumer.consume(_tmp);
65       _tmp[var] = 0;
66     }
67   }
68   _consumer.doneConsuming();
69 
70   ASSERT(_tmp.isIdentity());
71 }
72 
consume(const Term & term,const TermTranslator & translator)73 void IrreducibleIdealSplitter::consume
74 (const Term& term, const TermTranslator& translator) {
75   ASSERT(term.getVarCount() == _tmp.getVarCount());
76   ASSERT(_tmp.isIdentity());
77 
78   _consumer.beginConsuming();
79   for (size_t var = 0; var < term.getVarCount(); ++var) {
80     if (translator.getExponent(var, term) != 0) {
81       _tmp[var] = term[var];
82       _consumer.consume(_tmp, translator);
83       _tmp[var] = 0;
84     }
85   }
86   _consumer.doneConsuming();
87 
88   ASSERT(_tmp.isIdentity());
89 }
90 
consume(const vector<mpz_class> & term)91 void IrreducibleIdealSplitter::consume(const vector<mpz_class>& term) {
92   ASSERT(term.size() == _bigTmp.size());
93   ASSERT(_bigTmp == vector<mpz_class>(_bigTmp.size()));
94 
95   _consumer.beginConsuming();
96   for (size_t var = 0; var < term.size(); ++var) {
97     if (term[var] != 0) {
98       _bigTmp[var] = term[var];
99       _consumer.consume(_bigTmp);
100       _bigTmp[var] = 0;
101     }
102   }
103   _consumer.doneConsuming();
104 
105   ASSERT(_bigTmp == vector<mpz_class>(_bigTmp.size()));
106 }
107 
doneConsuming()108 void IrreducibleIdealSplitter::doneConsuming() {
109   if (!_inList)
110     _consumer.doneConsumingList();
111 }
112 
doneConsumingList()113 void IrreducibleIdealSplitter::doneConsumingList() {
114   ASSERT(_inList);
115   _consumer.doneConsumingList();
116 }
117