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: summator.cc,v 1.2 2008-07-08 08:18:27 Singular Exp $ |
---|
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 | sBucketDestroy(&m_temp.m_bucket); |
---|
71 | // m_temp.m_bucket = NULL; |
---|
72 | } |
---|
73 | else |
---|
74 | if(m_temp.m_poly!=NULL) |
---|
75 | { |
---|
76 | #ifdef PDEBUG |
---|
77 | p_Test(m_temp.m_poly, m_basering); |
---|
78 | #endif |
---|
79 | p_Delete(&m_temp.m_poly, m_basering); |
---|
80 | // m_temp.m_poly = NULL; |
---|
81 | } |
---|
82 | } |
---|
83 | |
---|
84 | void CPolynomialSummator::AddAndDelete(poly pSummand, int iLength) |
---|
85 | { |
---|
86 | #ifdef PDEBUG |
---|
87 | p_Test(pSummand, m_basering); |
---|
88 | #endif |
---|
89 | |
---|
90 | if(m_bUsePolynomial) |
---|
91 | m_temp.m_poly = p_Add_q(m_temp.m_poly, pSummand, m_basering); |
---|
92 | else |
---|
93 | sBucket_Add_p(m_temp.m_bucket, pSummand, iLength); |
---|
94 | } |
---|
95 | |
---|
96 | void CPolynomialSummator::AddAndDelete(poly pSummand) |
---|
97 | { |
---|
98 | #ifdef PDEBUG |
---|
99 | p_Test(pSummand, m_basering); |
---|
100 | #endif |
---|
101 | |
---|
102 | if(m_bUsePolynomial) |
---|
103 | m_temp.m_poly = p_Add_q(m_temp.m_poly, pSummand, m_basering); |
---|
104 | else |
---|
105 | sBucket_Add_p(m_temp.m_bucket, pSummand, 0); |
---|
106 | } |
---|
107 | |
---|
108 | poly CPolynomialSummator::AddUpAndClear() |
---|
109 | { |
---|
110 | poly out = NULL; |
---|
111 | |
---|
112 | if(m_bUsePolynomial) |
---|
113 | { |
---|
114 | out = m_temp.m_poly; |
---|
115 | m_temp.m_poly = NULL; |
---|
116 | } |
---|
117 | else |
---|
118 | { |
---|
119 | int pLength; |
---|
120 | sBucketClearAdd(m_temp.m_bucket, &out, &pLength); |
---|
121 | } |
---|
122 | |
---|
123 | #ifdef PDEBUG |
---|
124 | p_Test(out, m_basering); |
---|
125 | #endif |
---|
126 | |
---|
127 | return out; |
---|
128 | } |
---|
129 | |
---|
130 | |
---|
131 | poly CPolynomialSummator::AddUpAndClear(int *piLength) |
---|
132 | { |
---|
133 | poly out = NULL; |
---|
134 | |
---|
135 | if(m_bUsePolynomial) |
---|
136 | { |
---|
137 | out = m_temp.m_poly; |
---|
138 | m_temp.m_poly = NULL; |
---|
139 | *piLength = pLength(out); |
---|
140 | } |
---|
141 | else |
---|
142 | { |
---|
143 | *piLength = 0; |
---|
144 | sBucketClearAdd(m_temp.m_bucket, &out, piLength); |
---|
145 | } |
---|
146 | |
---|
147 | #ifdef PDEBUG |
---|
148 | p_Test(out, m_basering); |
---|
149 | assume(pLength(out) == *piLength); |
---|
150 | #endif |
---|
151 | |
---|
152 | return out; |
---|
153 | } |
---|
154 | |
---|
155 | |
---|
156 | |
---|
157 | void CPolynomialSummator::Add(poly pSummand, int iLength) |
---|
158 | { |
---|
159 | AddAndDelete(p_Copy(pSummand, m_basering), iLength); |
---|
160 | } |
---|
161 | |
---|
162 | void CPolynomialSummator::Add(poly pSummand) |
---|
163 | { |
---|
164 | AddAndDelete(p_Copy(pSummand, m_basering)); |
---|
165 | } |
---|
166 | |
---|
167 | #endif |
---|