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.
* 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();
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);
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) {
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();
// 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();
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
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();
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;
}
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);
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;
}