]> www.ginac.de Git - ginac.git/blobdiff - ginac/idx.cpp
hash keys of indices must not depend on the index dimension; doing so breaks
[ginac.git] / ginac / idx.cpp
index 4dd4d1afb016690f08fc4724c084dbca52572d3e..5739f80e492faa28999a78cae4fc85efed393065 100644 (file)
@@ -29,7 +29,6 @@
 #include "lst.h"
 #include "relational.h"
 #include "operators.h"
-#include "print.h"
 #include "archive.h"
 #include "utils.h"
 
@@ -164,7 +163,7 @@ void idx::do_print_latex(const print_latex & c, unsigned level) const
 
 void idx::do_print_tree(const print_tree & c, unsigned level) const
 {
-       c.s << std::string(level, ' ') << class_name()
+       c.s << std::string(level, ' ') << class_name() << " @" << this
            << std::hex << ", hash=0x" << hashvalue << ", flags=0x" << flags << std::dec
            << std::endl;
        value.print(c, level +  c.delta_indent);
@@ -182,7 +181,7 @@ void varidx::do_print(const print_context & c, unsigned level) const
 
 void varidx::do_print_tree(const print_tree & c, unsigned level) const
 {
-       c.s << std::string(level, ' ') << class_name()
+       c.s << std::string(level, ' ') << class_name() << " @" << this
            << std::hex << ", hash=0x" << hashvalue << ", flags=0x" << flags << std::dec
            << (covariant ? ", covariant" : ", contravariant")
            << std::endl;
@@ -213,7 +212,7 @@ void spinidx::do_print_latex(const print_latex & c, unsigned level) const
 
 void spinidx::do_print_tree(const print_tree & c, unsigned level) const
 {
-       c.s << std::string(level, ' ') << class_name()
+       c.s << std::string(level, ' ') << class_name() << " @" << this
            << std::hex << ", hash=0x" << hashvalue << ", flags=0x" << flags << std::dec
            << (covariant ? ", covariant" : ", contravariant")
            << (dotted ? ", dotted" : ", undotted")
@@ -326,11 +325,17 @@ bool spinidx::match_same_type(const basic & other) const
 
 unsigned idx::calchash() const
 {
+       // NOTE: The code in simplify_indexed() assumes that canonically
+       // ordered sequences of indices have the two members of dummy index
+       // pairs lying next to each other. The hash values for indices must
+       // be devised accordingly. The easiest (only?) way to guarantee the
+       // desired ordering is to make indices with the same value have equal
+       // hash keys. That is, the hash values must not depend on the index
+       // dimensions or other attributes (variance etc.).
+       // The compare_same_type() methods will take care of the rest.
        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) {