From 1b48bfdf43c8d104cb8b06147f27cb9efe42cb16 Mon Sep 17 00:00:00 2001 From: Christian Bauer Date: Mon, 21 Jul 2003 19:44:55 +0000 Subject: [PATCH] hash value computation for indices takes index dimension into account --- ginac/idx.cpp | 17 +++++++++++++++++ ginac/idx.h | 1 + 2 files changed, 18 insertions(+) diff --git a/ginac/idx.cpp b/ginac/idx.cpp index cc5f52c3..01692294 100644 --- a/ginac/idx.cpp +++ b/ginac/idx.cpp @@ -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 diff --git a/ginac/idx.h b/ginac/idx.h index b6e63e07..985226d7 100644 --- a/ginac/idx.h +++ b/ginac/idx.h @@ -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: -- 2.44.0