@@ -145,7 +145,6 @@ public FactorMultiplicity(int multiplicity = 1)
145
145
private sealed class PolynomialFactor
146
146
{
147
147
public List < decimal > Coefficients ;
148
- public static decimal [ ] Destination ;
149
148
150
149
private decimal _key ;
151
150
public decimal Key { get { return _key ; } }
@@ -175,20 +174,21 @@ internal PolynomialFactor(decimal key)
175
174
_key = key ;
176
175
}
177
176
178
- public void Multiply ( PolynomialFactor factor )
177
+ public void Multiply ( PolynomialFactor factor , decimal [ ] destination )
179
178
{
180
179
var len = Coefficients . Count ;
181
180
Coefficients . AddRange ( factor . Coefficients ) ;
182
181
183
- PolynomialMultiplication ( 0 , len , len , factor . Coefficients . Count , 0 , 1 , 1 ) ;
182
+ PolynomialMultiplication ( destination , 0 , len , len , factor . Coefficients . Count , 0 , 1 , 1 ) ;
184
183
185
184
for ( var i = 0 ; i < Coefficients . Count ; ++ i )
186
- Coefficients [ i ] = Destination [ i ] ;
185
+ Coefficients [ i ] = destination [ i ] ;
187
186
188
187
SetKey ( ) ;
189
188
}
190
189
191
- private void PolynomialMultiplication ( int uIndex , int uLen , int vIndex , int vLen , int dstIndex , decimal uCoeff , decimal vCoeff )
190
+ private void PolynomialMultiplication ( decimal [ ] destination , int uIndex , int uLen , int vIndex ,
191
+ int vLen , int dstIndex , decimal uCoeff , decimal vCoeff )
192
192
{
193
193
Contracts . Assert ( uIndex >= 0 ) ;
194
194
Contracts . Assert ( uLen >= 1 ) ;
@@ -198,18 +198,19 @@ private void PolynomialMultiplication(int uIndex, int uLen, int vIndex, int vLen
198
198
Contracts . Assert ( vIndex + vLen <= Utils . Size ( Coefficients ) ) ;
199
199
Contracts . Assert ( uIndex + uLen <= vIndex || vIndex + vLen <= uIndex ) ; // makes sure the input ranges are non-overlapping.
200
200
Contracts . Assert ( dstIndex >= 0 ) ;
201
- Contracts . Assert ( dstIndex + uLen + vLen <= Utils . Size ( Destination ) ) ;
201
+ Contracts . Assert ( dstIndex + uLen + vLen <= Utils . Size ( destination ) ) ;
202
202
203
203
if ( uLen == 1 && vLen == 1 )
204
204
{
205
- Destination [ dstIndex ] = Coefficients [ uIndex ] * Coefficients [ vIndex ] ;
206
- Destination [ dstIndex + 1 ] = Coefficients [ uIndex ] + Coefficients [ vIndex ] ;
205
+ destination [ dstIndex ] = Coefficients [ uIndex ] * Coefficients [ vIndex ] ;
206
+ destination [ dstIndex + 1 ] = Coefficients [ uIndex ] + Coefficients [ vIndex ] ;
207
207
}
208
208
else
209
- NaivePolynomialMultiplication ( uIndex , uLen , vIndex , vLen , dstIndex , uCoeff , vCoeff ) ;
209
+ NaivePolynomialMultiplication ( destination , uIndex , uLen , vIndex , vLen , dstIndex , uCoeff , vCoeff ) ;
210
210
}
211
211
212
- private void NaivePolynomialMultiplication ( int uIndex , int uLen , int vIndex , int vLen , int dstIndex , decimal uCoeff , decimal vCoeff )
212
+ private void NaivePolynomialMultiplication ( decimal [ ] destination , int uIndex , int uLen , int vIndex ,
213
+ int vLen , int dstIndex , decimal uCoeff , decimal vCoeff )
213
214
{
214
215
int i ;
215
216
int j ;
@@ -246,7 +247,7 @@ private void NaivePolynomialMultiplication(int uIndex, int uLen, int vIndex, int
246
247
for ( j = 0 ; j < a ; ++ j )
247
248
temp += ( Coefficients [ b - j + uIndex ] * Coefficients [ c + j + vIndex ] ) ;
248
249
249
- Destination [ i + dstIndex ] = temp ;
250
+ destination [ i + dstIndex ] = temp ;
250
251
}
251
252
}
252
253
}
@@ -285,6 +286,7 @@ public static bool FindPolynomialCoefficients(Complex[] roots, ref Double[] coef
285
286
int destinationOffset = 0 ;
286
287
287
288
var factors = new List < PolynomialFactor > ( ) ;
289
+ decimal [ ] destination = new decimal [ n ] ;
288
290
289
291
for ( i = 0 ; i < n ; ++ i )
290
292
{
@@ -336,9 +338,6 @@ public static bool FindPolynomialCoefficients(Complex[] roots, ref Double[] coef
336
338
337
339
if ( destinationOffset < n - 1 )
338
340
{
339
- if ( Utils . Size ( PolynomialFactor . Destination ) < n )
340
- PolynomialFactor . Destination = new decimal [ n ] ;
341
-
342
341
while ( factors . Count > 1 )
343
342
{
344
343
var k1 = Math . Abs ( factors . ElementAt ( 0 ) . Key ) ;
@@ -364,7 +363,7 @@ public static bool FindPolynomialCoefficients(Complex[] roots, ref Double[] coef
364
363
var f2 = factors . ElementAt ( ind ) ;
365
364
factors . RemoveAt ( ind ) ;
366
365
367
- f1 . Multiply ( f2 ) ;
366
+ f1 . Multiply ( f2 , destination ) ;
368
367
369
368
ind = factors . BinarySearch ( f1 , comparer ) ;
370
369
if ( ind >= 0 )
0 commit comments