@@ -147,6 +147,22 @@ public String longToString()
147
147
result .append ( "x^" + xExp + "y^" + yExp + "z^" + zExp );
148
148
return result .toString ();
149
149
}
150
+
151
+ public boolean equals ( Term t )
152
+ {
153
+ return this .coeff == t .coeff &&
154
+ this .xExp == t .xExp &&
155
+ this .yExp == t .yExp &&
156
+ this .zExp == t .zExp ;
157
+ }
158
+
159
+ public int hashCode ()
160
+ {
161
+ return ( ( int ) ( Double .doubleToRawLongBits ( this .coeff ) % 0x00000000FFFFFFFFL ) ) &
162
+ ( ( int ) this .xExp ) &
163
+ ( ( int ) this .xExp ) << 8 &
164
+ ( ( int ) this .xExp ) << 16 ;
165
+ }
150
166
}
151
167
152
168
private Term [] terms ; // ordered list of terms, such that terms[ i ].lexCompare( terms[ i + 1 ] ) < 0
@@ -158,6 +174,8 @@ public String longToString()
158
174
private byte degree ;
159
175
private int numXyTerms ; // number of terms in result of evaluateZ
160
176
private boolean isCompact = false ;
177
+
178
+ private static final Term [] dummyTermArray = new Term [ 0 ];
161
179
162
180
public XYZPolynomial ()
163
181
{
@@ -270,7 +288,7 @@ else if( lexCompare > 0 )
270
288
while ( i2 < terms2 .length )
271
289
resultTerms .add ( new Term ( terms2 [ i2 ++ ] ) );
272
290
273
- return new XYZPolynomial ( resultTerms .toArray ( this . terms ) );
291
+ return new XYZPolynomial ( resultTerms .toArray ( XYZPolynomial . dummyTermArray ) );
274
292
}
275
293
276
294
public XYZPolynomial mult ( XYZPolynomial p )
@@ -300,7 +318,7 @@ private static XYZPolynomial mult( XYZPolynomial p1, XYZPolynomial p2 )
300
318
for ( int i = 0 ; i < p2 .terms .length ; i ++ )
301
319
resultTerms .add ( t1 .mult ( p2 .terms [ i ] ) );
302
320
}
303
- return new XYZPolynomial ( collect ( resultTerms .toArray ( new Term [ 0 ] ), true ) );
321
+ return new XYZPolynomial ( collect ( resultTerms .toArray ( XYZPolynomial . dummyTermArray ), true ) );
304
322
}
305
323
306
324
// // standard polynomial multiplication (faster, but less numerically stable)
@@ -693,7 +711,7 @@ public XYZPolynomial substitute( XYZPolynomial xPoly, XYZPolynomial yPoly, XYZPo
693
711
for( Term e : expandedTerm.terms )
694
712
terms.add( e );
695
713
}
696
- XYZPolynomial result = new XYZPolynomial( collect( terms.toArray( new Term[ 0 ] ), true ) );
714
+ XYZPolynomial result = new XYZPolynomial( collect( terms.toArray( XYZPolynomial.dummyTermArray ), true ) );
697
715
return result;
698
716
}
699
717
*/
@@ -724,7 +742,7 @@ private static Term[] collect( Term[] terms, boolean sort )
724
742
725
743
if ( resultTerms .size () == 0 )
726
744
resultTerms .add ( new Term ( 0.0 , (byte ) 0 , (byte ) 0 , (byte ) 0 ) );
727
- return resultTerms .toArray ( new Term [ 0 ] );
745
+ return resultTerms .toArray ( XYZPolynomial . dummyTermArray );
728
746
}
729
747
else
730
748
{
@@ -776,4 +794,22 @@ public double[][][] recursiveView()
776
794
a [ t .zExp ][ t .yExp ][ t .xExp ] = t .coeff ;
777
795
return a ;
778
796
}
797
+
798
+ public boolean equals ( XYZPolynomial p )
799
+ {
800
+ if ( this .terms .length != p .terms .length )
801
+ return false ;
802
+ for ( int i = 0 ; i < this .terms .length ; ++i )
803
+ if ( !this .terms [ i ].equals ( p .terms [ i ] ) )
804
+ return false ;
805
+ return true ;
806
+ }
807
+
808
+ public int hashCode ()
809
+ {
810
+ int c = 0 ;
811
+ for ( int i = 0 ; i < this .terms .length ; ++i )
812
+ c += this .terms [ i ].hashCode ();
813
+ return c ;
814
+ }
779
815
}
0 commit comments