File:  [CENS] / python / pyGiNaC / patches / relational.cpp.diff-1.0.0
Revision 1.1: download - view: text, annotated - select for diffs - revision graph
Thu Nov 22 14:50:04 2001 UTC (16 years ago) by pearu
Branches: MAIN
CVS tags: HEAD
See NEWS.txt for changes. There too many changes to list them here

--- relational.cpp.orig	Wed Nov 21 14:29:35 2001
+++ relational.cpp	Wed Nov 21 18:09:23 2001
@@ -229,6 +229,70 @@
 	return rh;    
 }
 
+unsigned relational::calchash(void) const
+{
+	unsigned v = golden_ratio_hash(tinfo());
+	unsigned lhash = lh.gethash();
+	unsigned rhash = rh.gethash();
+
+	v = rotate_left_31(v);
+	switch(o) {
+	case equal: ;
+	case not_equal:
+		if (lhash>rhash) { v ^= lhash; lhash = rhash; }
+		else v ^= rhash;
+		break;
+	case less: ;
+	case less_or_equal:
+		v ^= rhash;
+		break;
+	case greater: ;
+	case greater_or_equal:
+		v ^= lhash; lhash = rhash;
+		break;
+	}
+	v = rotate_left_31(v);
+	v ^= lhash;
+
+	// mask out numeric hashes:
+	v &= 0x7FFFFFFFU;
+        
+        // store calculated hash value only if object is already evaluated
+	if (flags & status_flags::evaluated) {
+		setflag(status_flags::hash_calculated);
+		hashvalue = v;
+	}
+
+	return v;
+}
+
+bool relational::is_equal_same_type(const basic & other) const
+{
+	GINAC_ASSERT(is_a<relational>(other));
+	relational const &oth = static_cast<const relational &>(other);
+	if (o == oth.o && lh.is_equal(oth.lh) && rh.is_equal(oth.rh))
+		return true;
+	switch (o) {
+	case equal: ;
+	case not_equal:
+		if (oth.o!=o) return false;
+		break;
+	case less:
+		if (oth.o!=greater) return false;
+		break;
+	case less_or_equal:
+		if (oth.o!=greater_or_equal) return false;
+		break;
+	case greater:
+		if (oth.o!=less) return false;
+		break;
+	case greater_or_equal:
+		if (oth.o!=less_or_equal) return false;
+		break;
+	}
+	return lh.is_equal(oth.rh) && rh.is_equal(oth.lh);
+}
+
 //////////
 // non-virtual functions in this class
 //////////

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>