Frobby  0.9.5
SquareFreeIdeal.cpp
Go to the documentation of this file.
1 /* Frobby: Software for monomial ideal computations.
2  Copyright (C) 2011 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 "SquareFreeIdeal.h"
19 
20 #include "RawSquareFreeIdeal.h"
21 #include "Ideal.h"
22 #include "BigIdeal.h"
23 
24 SquareFreeIdeal::SquareFreeIdeal(): _ideal(0), _capacity(0) {}
25 
27 (const SquareFreeIdeal& ideal, size_t capacity):
28  _names(ideal.getNames()) {
29  _capacity = capacity;
30  if (_capacity < ideal.getGeneratorCount())
31  _capacity = ideal.getGeneratorCount();
33  _ideal->insert(*ideal._ideal);
34 }
35 
37  _names(ideal.getNames()) {
38  _capacity = ideal.getGeneratorCount();
40  _ideal->insert(ideal);
41 }
42 
44  clear();
45 }
46 
48  SquareFreeIdeal copy(ideal);
49  swap(copy);
50  return *this;
51 }
52 
54  ASSERT(_ideal != 0);
55  _ideal->minimize();
56 }
57 
59  ASSERT(_ideal != 0);
60  ASSERT(_names.getVarCount() == names.getVarCount());
61  _names = names;
62 }
63 
65  if (getGeneratorCount() == getCapacity())
66  reserve(getCapacity() == 0 ? 16 : getCapacity() * 2);
68 }
69 
71  ASSERT(term != 0);
73  if (getGeneratorCount() == getCapacity())
74  reserve(getCapacity() == 0 ? 16 : getCapacity() * 2);
76  _ideal->insert(term);
77 }
78 
79 bool SquareFreeIdeal::insert(const std::vector<std::string>& term) {
80  ASSERT(term.size() == getVarCount());
82  if (getGeneratorCount() == getCapacity())
83  reserve(getCapacity() == 0 ? 16 : getCapacity() * 2);
85  return _ideal->insert(term);
86 }
87 
89  _names.clear();
91  _ideal = 0;
92  _capacity = 0;
93 }
94 
96  std::swap(_names, ideal._names);
97  std::swap(_ideal, ideal._ideal);
99 }
100 
101 void SquareFreeIdeal::reserve(size_t capacity) {
102  if (getCapacity() < capacity)
103  SquareFreeIdeal(*this, capacity).swap(*this);
104 }
RSFIdeal * newRawSquareFreeIdeal(size_t varCount, size_t capacity)
Allocates object with enough memory for capacity generators in varCount variables.
void deleteRawSquareFreeIdeal(RSFIdeal *ideal)
size_t getGeneratorCount() const
Definition: BigIdeal.h:144
size_t insert(const Ideal &ideal)
Inserts the generators of ideal from index 0 onward until reaching a non-squarefree generator or all ...
void reserve(size_t capacity)
SquareFreeIdeal & operator=(const BigIdeal &ideal)
RawSquareFreeIdeal * _ideal
size_t getVarCount() const
void insert(Word *term)
void renameVars(const VarNames &names)
size_t getCapacity() const
void swap(SquareFreeIdeal &ideal)
size_t getGeneratorCount() const
Defines the variables of a polynomial ring and facilities IO involving them.
Definition: VarNames.h:40
size_t getVarCount() const
Returns the current number of variables.
Definition: VarNames.h:113
void clear()
Resets the number of variables to zero.
Definition: VarNames.cpp:106
void swap(hashtable< _Val, _Key, _HF, _Extract, _EqKey, _All > &__ht1, hashtable< _Val, _Key, _HF, _Extract, _EqKey, _All > &__ht2)
Definition: hashtable.h:740
unsigned long Word
The native unsigned type for the CPU.
Definition: stdinc.h:93
#define ASSERT(X)
Definition: stdinc.h:86