]> www.ginac.de Git - ginac.git/commitdiff
hash value computation for indices takes index dimension into account
authorChristian Bauer <Christian.Bauer@uni-mainz.de>
Mon, 21 Jul 2003 19:44:55 +0000 (19:44 +0000)
committerChristian Bauer <Christian.Bauer@uni-mainz.de>
Mon, 21 Jul 2003 19:44:55 +0000 (19:44 +0000)
ginac/idx.cpp
ginac/idx.h

index cc5f52c3fef153a30596efb2980bc8f012ab81f4..01692294041c3335c298fbfc96337bf826edf57c 100644 (file)
@@ -341,6 +341,23 @@ bool spinidx::match_same_type(const basic & other) const
        return inherited::match_same_type(other);
 }
 
+unsigned idx::calchash() const
+{
+       unsigned v = golden_ratio_hash(tinfo());
+       v = rotate_left(v);
+       v ^= value.gethash();
+       v = rotate_left(v);
+       v ^= dim.gethash();
+
+       // Store calculated hash value only if object is already evaluated
+       if (flags & status_flags::evaluated) {
+               setflag(status_flags::hash_calculated);
+               hashvalue = v;
+       }
+
+       return v;
+}
+
 /** By default, basic::evalf would evaluate the index value but we don't want
  *  a.1 to become a.(1.0). */
 ex idx::evalf(int level) const
index b6e63e0717f8538cc9e9c8c25004c043ed775412..985226d72d441b9c604c478ff801b0e642f410f7 100644 (file)
@@ -59,6 +59,7 @@ public:
 protected:
        ex derivative(const symbol & s) const;
        bool match_same_type(const basic & other) const;
+       unsigned calchash() const;
 
        // new virtual functions in this class
 public: