Macaulay2 Engine
Loading...
Searching...
No Matches
qset.hpp
Go to the documentation of this file.
1/*****************************************************************************
2 * Copyright (C) 2006-2011 by Mikhail V. Zinin *
3 * mzinin@gmail.com *
4 * *
5 * You may redistribute this file under the terms of the GNU General *
6 * Public License as published by the Free Software Foundation, either *
7 * version 2 of the License, or any later version. *
8 *****************************************************************************/
9
10#ifndef BIBASIS_QSET_HPP
11#define BIBASIS_QSET_HPP
12
45
46#include <list>
47#include <algorithm>
48#include "triple.hpp"
49
50namespace BIBasis
51{
52 template <typename MonomType>
53 class QSet
54 {
55 private:
56 std::list<Triple<MonomType>*> TripleList;
57
58 public:
59 QSet();
60 QSet(const std::list<Polynom<MonomType>*>& basis);
61 ~QSet();
62
63 void Insert(std::list<Polynom<MonomType>*>& addList);
64 void Insert(std::list<Triple<MonomType>*>& addList);
65
67
68 void Clear();
69 bool Empty() const;
70 std::size_t Size() const;
71 void DeleteDescendants(const Triple<MonomType>* ancestor);
72 };
73
74 template <typename MonomType>
79
80 template <typename MonomType>
81 QSet<MonomType>::QSet(const std::list<Polynom<MonomType>*>& basis)
82 : TripleList()
83 {
84 typename std::list<Polynom<MonomType>*>::const_iterator itBasis(basis.begin());
85 while (itBasis != basis.end())
86 {
87 if (*itBasis)
88 {
89 TripleList.push_back(new Triple<MonomType>(*itBasis));
90 }
91 ++itBasis;
92 }
94 }
95
96 template <typename MonomType>
98 {
99 Clear();
100 }
101
102 template <typename MonomType>
104 {
105 typename std::list<Polynom<MonomType>*>::const_iterator itBasis(addList.begin());
106 while ( itBasis != addList.end() )
107 {
108 if (*itBasis)
109 {
110 TripleList.push_back(new Triple<MonomType>(*itBasis));
111 }
112 ++itBasis;
113 }
115 }
116
117 template <typename MonomType>
119 {
120 addList.sort(Triple<MonomType>::Compare);
122 }
123
124 template <typename MonomType>
126 {
128 TripleList.pop_back();
129 return result;
130 }
131
132 template <typename MonomType>
134 {
135 typename std::list<Triple<MonomType>*>::iterator it(TripleList.begin());
136 while (it != TripleList.end())
137 {
138 delete *it;
139 ++it;
140 }
141 TripleList.clear();
142 }
143
144 template <typename MonomType>
145 inline bool QSet<MonomType>::Empty() const
146 {
147 return TripleList.empty();
148 }
149
150 template <typename MonomType>
151 inline std::size_t QSet<MonomType>::Size() const
152 {
153 return TripleList.size();
154 }
155
156 template <typename MonomType>
158 {
159 if (!ancestor)
160 {
161 return;
162 }
163
164 typename std::list<Triple<MonomType>*>::iterator it(TripleList.begin());
165 while ( it != TripleList.end() )
166 {
167 if ((**it).GetAncestor() == ancestor || (**it).GetWeakAncestor() == ancestor)
168 {
169 delete *it;
170 it = TripleList.erase(it);
171 }
172 else
173 {
174 ++it;
175 }
176 }
177 }
178}
179
180#endif // BIBASIS_QSET_HPP
std::size_t Size() const
Definition qset.hpp:151
void Clear()
Definition qset.hpp:133
bool Empty() const
Definition qset.hpp:145
void DeleteDescendants(const Triple< MonomType > *ancestor)
Definition qset.hpp:157
Triple< MonomType > * Get()
Definition qset.hpp:125
std::list< Triple< MonomType > * > TripleList
Definition qset.hpp:56
void Insert(std::list< Polynom< MonomType > * > &addList)
Definition qset.hpp:103
const Triple * GetWeakAncestor() const
Definition triple.hpp:173
static bool Compare(const Triple *tripleA, const Triple *tripleB)
Definition triple.hpp:209
VALGRIND_MAKE_MEM_DEFINED & result(result)
BIBasis::Triple<MonomType> — (polynomial, ancestors, non-multiplicative variables) record driving Jan...