]> www.ginac.de Git - ginac.git/commitdiff
* numeric::calchash(): Apply golden_ratio_hash() to the value returned
authorRichard Kreckel <Richard.Kreckel@uni-mainz.de>
Wed, 10 Apr 2002 18:57:06 +0000 (18:57 +0000)
committerRichard Kreckel <Richard.Kreckel@uni-mainz.de>
Wed, 10 Apr 2002 18:57:06 +0000 (18:57 +0000)
  by CLN.  (Rationale: this populates more bits for the frequent small
  integers resulting in much less opportunity for funny cancellations in
  hash-values of monomials.)

ginac/numeric.cpp

index 1643eebd835536ac432c7c6ef72389f3f61d86ae..1d9c78ba2687190f2e6cdf26c22ff4619ba7a1eb 100644 (file)
@@ -579,11 +579,13 @@ bool numeric::is_equal_same_type(const basic &other) const
 
 unsigned numeric::calchash(void) const
 {
-       // Use CLN's hashcode.  Warning: It depends only on the number's value, not
-       // its type or precision (i.e. a true equivalence relation on numbers).  As
-       // a consequence, 3 and 3.0 share the same hashvalue.
+       // Base computation of hashvalue on CLN's hashcode.  Note: That depends
+       // only on the number's value, not its type or precision (i.e. a true
+       // equivalence relation on numbers).  As a consequence, 3 and 3.0 share
+       // the same hashvalue.  That shouldn't really matter, though.
        setflag(status_flags::hash_calculated);
-       return (hashvalue = cln::equal_hashcode(cln::the<cln::cl_N>(value)) | 0x80000000U);
+       hashvalue = golden_ratio_hash(cln::equal_hashcode(cln::the<cln::cl_N>(value))) | 0x80000000U;
+       return hashvalue;
 }