1 | /**************************************** |
---|
2 | * Computer Algebra System SINGULAR * |
---|
3 | ****************************************/ |
---|
4 | /*************************************************************** |
---|
5 | * File: summator.cc |
---|
6 | * Purpose: simple Summator usecase implementation |
---|
7 | * Author: motsak |
---|
8 | * Created: |
---|
9 | * Version: $Id$ |
---|
10 | *******************************************************************/ |
---|
11 | |
---|
12 | |
---|
13 | #define MYTEST 0 |
---|
14 | #define OUTPUT 0 |
---|
15 | |
---|
16 | #if MYTEST |
---|
17 | #define OM_CHECK 4 |
---|
18 | #define OM_TRACK 5 |
---|
19 | #endif |
---|
20 | |
---|
21 | #include "mod2.h" |
---|
22 | #ifdef HAVE_PLURAL |
---|
23 | #include "summator.h" // for CPolynomialSummator class |
---|
24 | #include "ring.h" |
---|
25 | #include "p_polys.h" |
---|
26 | #include "sbuckets.h" |
---|
27 | |
---|
28 | |
---|
29 | CPolynomialSummator::CPolynomialSummator(ring rBaseRing, bool bUsePolynomial): |
---|
30 | m_basering(rBaseRing), m_bUsePolynomial(bUsePolynomial) |
---|
31 | { |
---|
32 | #ifdef RDEBUG |
---|
33 | rTest(rBaseRing); |
---|
34 | #endif |
---|
35 | |
---|
36 | if(bUsePolynomial) |
---|
37 | m_temp.m_poly = NULL; |
---|
38 | else |
---|
39 | { |
---|
40 | assume(!TEST_OPT_NOT_BUCKETS); |
---|
41 | m_temp.m_bucket = sBucketCreate(rBaseRing); |
---|
42 | } |
---|
43 | } |
---|
44 | |
---|
45 | /* |
---|
46 | // no sBucketInit defined :((( |
---|
47 | CPolynomialSummator::CPolynomialSummator(ring rBaseRing, poly pInitialSum, int iLength, bool bUsePolynomial): |
---|
48 | m_basering(rBaseRing), m_bUsePolynomial(bUsePolynomial) |
---|
49 | { |
---|
50 | #ifdef PDEBUG |
---|
51 | p_Test(pInitialSum, rBaseRing); |
---|
52 | #endif |
---|
53 | |
---|
54 | if(bUsePolynomial) |
---|
55 | { |
---|
56 | m_temp.m_poly = pInitialSum; |
---|
57 | } |
---|
58 | else |
---|
59 | { |
---|
60 | assume(!TEST_OPT_NOT_BUCKETS); |
---|
61 | m_temp.m_bucket = sBucketInit(pInitialSum, iLength, rBaseRing); |
---|
62 | } |
---|
63 | } |
---|
64 | */ |
---|
65 | |
---|
66 | CPolynomialSummator::~CPolynomialSummator() |
---|
67 | { |
---|
68 | if(!m_bUsePolynomial) |
---|
69 | { |
---|
70 | poly out; |
---|
71 | int pLength; |
---|
72 | |
---|
73 | sBucketClearAdd(m_temp.m_bucket, &out, &pLength); |
---|
74 | sBucketDestroy(&m_temp.m_bucket); |
---|
75 | |
---|
76 | if(out != NULL) |
---|
77 | p_Delete(&out, m_basering); |
---|
78 | // m_temp.m_bucket = NULL; |
---|
79 | } |
---|
80 | else |
---|
81 | if(m_temp.m_poly!=NULL) |
---|
82 | { |
---|
83 | #ifdef PDEBUG |
---|
84 | p_Test(m_temp.m_poly, m_basering); |
---|
85 | #endif |
---|
86 | p_Delete(&m_temp.m_poly, m_basering); |
---|
87 | // m_temp.m_poly = NULL; |
---|
88 | } |
---|
89 | } |
---|
90 | |
---|
91 | void CPolynomialSummator::AddAndDelete(poly pSummand, int iLength) |
---|
92 | { |
---|
93 | #ifdef PDEBUG |
---|
94 | p_Test(pSummand, m_basering); |
---|
95 | #endif |
---|
96 | |
---|
97 | if(m_bUsePolynomial) |
---|
98 | m_temp.m_poly = p_Add_q(m_temp.m_poly, pSummand, m_basering); |
---|
99 | else |
---|
100 | sBucket_Add_p(m_temp.m_bucket, pSummand, iLength); |
---|
101 | } |
---|
102 | |
---|
103 | void CPolynomialSummator::AddAndDelete(poly pSummand) |
---|
104 | { |
---|
105 | #ifdef PDEBUG |
---|
106 | p_Test(pSummand, m_basering); |
---|
107 | #endif |
---|
108 | |
---|
109 | if(m_bUsePolynomial) |
---|
110 | m_temp.m_poly = p_Add_q(m_temp.m_poly, pSummand, m_basering); |
---|
111 | else |
---|
112 | sBucket_Add_p(m_temp.m_bucket, pSummand, 0); |
---|
113 | } |
---|
114 | |
---|
115 | poly CPolynomialSummator::AddUpAndClear() |
---|
116 | { |
---|
117 | poly out = NULL; |
---|
118 | |
---|
119 | if(m_bUsePolynomial) |
---|
120 | { |
---|
121 | out = m_temp.m_poly; |
---|
122 | m_temp.m_poly = NULL; |
---|
123 | } |
---|
124 | else |
---|
125 | { |
---|
126 | int pLength; |
---|
127 | sBucketClearAdd(m_temp.m_bucket, &out, &pLength); |
---|
128 | } |
---|
129 | |
---|
130 | #ifdef PDEBUG |
---|
131 | p_Test(out, m_basering); |
---|
132 | #endif |
---|
133 | |
---|
134 | return out; |
---|
135 | } |
---|
136 | |
---|
137 | |
---|
138 | poly CPolynomialSummator::AddUpAndClear(int *piLength) |
---|
139 | { |
---|
140 | poly out = NULL; |
---|
141 | |
---|
142 | if(m_bUsePolynomial) |
---|
143 | { |
---|
144 | out = m_temp.m_poly; |
---|
145 | m_temp.m_poly = NULL; |
---|
146 | *piLength = pLength(out); |
---|
147 | } |
---|
148 | else |
---|
149 | { |
---|
150 | *piLength = 0; |
---|
151 | sBucketClearAdd(m_temp.m_bucket, &out, piLength); |
---|
152 | } |
---|
153 | |
---|
154 | #ifdef PDEBUG |
---|
155 | p_Test(out, m_basering); |
---|
156 | assume(pLength(out) == *piLength); |
---|
157 | #endif |
---|
158 | |
---|
159 | return out; |
---|
160 | } |
---|
161 | |
---|
162 | |
---|
163 | |
---|
164 | void CPolynomialSummator::Add(poly pSummand, int iLength) |
---|
165 | { |
---|
166 | AddAndDelete(p_Copy(pSummand, m_basering), iLength); |
---|
167 | } |
---|
168 | |
---|
169 | void CPolynomialSummator::Add(poly pSummand) |
---|
170 | { |
---|
171 | AddAndDelete(p_Copy(pSummand, m_basering)); |
---|
172 | } |
---|
173 | |
---|
174 | |
---|
175 | |
---|
176 | CPolynomialSummator::CPolynomialSummator(const CPolynomialSummator& b): m_bUsePolynomial(b.m_bUsePolynomial), m_basering(b.m_basering) |
---|
177 | { |
---|
178 | // try{ |
---|
179 | if(m_bUsePolynomial) |
---|
180 | m_temp.m_poly = p_Copy( b.m_temp.m_poly, m_basering); |
---|
181 | else |
---|
182 | m_temp.m_bucket = sBucketCopy(b.m_temp.m_bucket); |
---|
183 | // } |
---|
184 | // catch(...) |
---|
185 | // { |
---|
186 | // assume(false); |
---|
187 | // } |
---|
188 | } |
---|
189 | |
---|
190 | |
---|
191 | #endif |
---|