]> www.ginac.de Git - ginac.git/commitdiff
calchash(): use type_info::name() instead of tinfo().
authorAlexei Sheplyakov <varg@theor.jinr.ru>
Wed, 15 Oct 2008 11:32:11 +0000 (15:32 +0400)
committerAlexei Sheplyakov <varg@theor.jinr.ru>
Sun, 19 Oct 2008 17:29:11 +0000 (21:29 +0400)
Custom RTTI considered harmful, part 4.

The hash value of the object of different types should be different whenever
possible. Hence calcash() needs a unique per type number. Previously we used
tinfo_key for this. typeinfo::name() (a *pointer* to implementation dependent
string) is also unique for each class, so it's just as good as tinfo() is.

ginac/basic.cpp
ginac/constant.cpp
ginac/expairseq.cpp
ginac/function.pl
ginac/idx.cpp
ginac/relational.cpp
ginac/symbol.cpp
ginac/symmetry.cpp
ginac/wildcard.cpp

index 1f9ccbac19af540f8b3a94702ed24f405e6e58ed..fa6e1d9679be426b90bd75acfee56c8babb4835b 100644 (file)
@@ -787,7 +787,8 @@ tinfo_t basic::return_type_tinfo() const
  *  would all end up with the same hashvalue. */
 unsigned basic::calchash() const
 {
-       unsigned v = golden_ratio_hash((p_int)tinfo());
+       const void* this_tinfo = (const void*)typeid(*this).name();
+       unsigned v = golden_ratio_hash((p_int)this_tinfo);
        for (size_t i=0; i<nops(); i++) {
                v = rotate_left(v);
                v ^= this->op(i).gethash();
index 13acc363f54db0f0dd3f3908ae6ab5e1d987a86b..b63427fce9eb76914b34bb25ab58aa449503b5fd 100644 (file)
@@ -216,7 +216,8 @@ bool constant::is_equal_same_type(const basic & other) const
 
 unsigned constant::calchash() const
 {
-       hashvalue = golden_ratio_hash((p_int)tinfo() ^ serial);
+       const void* typeid_this = (const void*)typeid(*this).name();
+       hashvalue = golden_ratio_hash((p_int)typeid_this ^ serial);
 
        setflag(status_flags::hash_calculated);
 
index 120672f74498f3d44915ee77d71e91e48af6f1a6..39f7931f585b3e9c43a3d3d407b7664aa0a2e4bc 100644 (file)
@@ -615,7 +615,8 @@ unsigned expairseq::return_type() const
 
 unsigned expairseq::calchash() const
 {
-       unsigned v = golden_ratio_hash((p_int)this->tinfo());
+       const void* this_tinfo = (const void*)typeid(*this).name();
+       unsigned v = golden_ratio_hash((p_int)this_tinfo);
        epvector::const_iterator i = seq.begin();
        const epvector::const_iterator end = seq.end();
        while (i != end) {
index 7a4d5e78cbc25fb4431f7807f9b424cd9bb6edd0..b478023f50dc2d56852e3ebceac374af178aeaea 100644 (file)
@@ -1066,7 +1066,8 @@ ex function::eval_ncmul(const exvector & v) const
 
 unsigned function::calchash() const
 {
-       unsigned v = golden_ratio_hash(golden_ratio_hash((p_int)tinfo()) ^ serial);
+       const void* this_tinfo = (const void*)typeid(*this).name();
+       unsigned v = golden_ratio_hash(golden_ratio_hash((p_int)this_tinfo) ^ serial);
        for (size_t i=0; i<nops(); i++) {
                v = rotate_left(v);
                v ^= this->op(i).gethash();
index c1412b9de73ff8bcfe5c43e7d679e7c4d3757935..174f95f0f311af7e096bba61402d0083016c7b0e 100644 (file)
@@ -352,7 +352,8 @@ unsigned idx::calchash() const
        // 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((p_int)tinfo());
+       const void* this_tinfo = (const void*)(typeid(*this).name());
+       unsigned v = golden_ratio_hash((p_int)this_tinfo);
        v = rotate_left(v);
        v ^= value.gethash();
 
@@ -504,7 +505,7 @@ ex spinidx::toggle_variance_dot() const
 bool is_dummy_pair(const idx & i1, const idx & i2)
 {
        // The indices must be of exactly the same type
-       if (i1.tinfo() != i2.tinfo())
+       if (typeid(i1) != typeid(i2))
                return false;
 
        // Same type, let the indices decide whether they are paired
index 434b620a59cf25f890d1f87d7a0c977b2e70132a..2f19d21337622159ecd65ad9fcbd91715b61d632 100644 (file)
@@ -258,7 +258,8 @@ tinfo_t relational::return_type_tinfo() const
 
 unsigned relational::calchash() const
 {
-       unsigned v = golden_ratio_hash((p_int)tinfo());
+       const void* this_tinfo = (const void*)typeid(*this).name();
+       unsigned v = golden_ratio_hash((p_int)this_tinfo);
        unsigned lhash = lh.gethash();
        unsigned rhash = rh.gethash();
 
index 6eedfef3b6142b0fd4e53107ced16ccac916d830..f233d84e791322f7d618348c45f211b4d6ce1c11 100644 (file)
@@ -287,7 +287,8 @@ bool symbol::is_equal_same_type(const basic & other) const
 
 unsigned symbol::calchash() const
 {
-       hashvalue = golden_ratio_hash((p_int)tinfo() ^ serial);
+       const void* this_tinfo = (const void*)typeid(*this).name();
+       hashvalue = golden_ratio_hash((p_int)this_tinfo ^ serial);
        setflag(status_flags::hash_calculated);
        return hashvalue;
 }
index 215a48a08d78ae88ea8cee7052490eb2a72f85b3..9a1589267a09e467ccf313c0aa85b7d2e42a8bd8 100644 (file)
@@ -185,7 +185,8 @@ int symmetry::compare_same_type(const basic & other) const
 
 unsigned symmetry::calchash() const
 {
-       unsigned v = golden_ratio_hash((p_int)tinfo());
+       const void* this_tinfo = (const void*)typeid(*this).name();
+       unsigned v = golden_ratio_hash((p_int)this_tinfo);
 
        if (type == none) {
                v = rotate_left(v);
index b5abfa1463a18c8bef5bf4696ea1e8bc650fb3fe..4a89957bcaaf4cb90b30f6e9acf19b7f42971a92 100644 (file)
@@ -104,9 +104,10 @@ void wildcard::do_print_python_repr(const print_python_repr & c, unsigned level)
 unsigned wildcard::calchash() const
 {
        // this is where the schoolbook method
-       // (golden_ratio_hash(tinfo()) ^ label)
+       // (golden_ratio_hash(typeid(*this).name()) ^ label)
        // is not good enough yet...
-       hashvalue = golden_ratio_hash(golden_ratio_hash((p_int)tinfo()) ^ label);
+       const void* this_tinfo = (const void*)typeid(*this).name();
+       hashvalue = golden_ratio_hash(golden_ratio_hash((p_int)this_tinfo) ^ label);
        setflag(status_flags::hash_calculated);
        return hashvalue;
 }