+spmapkey::spmapkey(const ex & v1_, const ex & v2_, const ex & dim_) : dim(dim_)
+{
+ // If indexed, extract base objects
+ ex s1 = is_a<indexed>(v1_) ? v1_.op(0) : v1_;
+ ex s2 = is_a<indexed>(v2_) ? v2_.op(0) : v2_;
+
+ // Enforce canonical order in pair
+ if (s1.compare(s2) > 0) {
+ v1 = s2;
+ v2 = s1;
+ } else {
+ v1 = s1;
+ v2 = s2;
+ }
+}
+
+bool spmapkey::operator==(const spmapkey &other) const
+{
+ if (!v1.is_equal(other.v1))
+ return false;
+ if (!v2.is_equal(other.v2))
+ return false;
+ if (is_a<wildcard>(dim) || is_a<wildcard>(other.dim))
+ return true;
+ else
+ return dim.is_equal(other.dim);
+}
+
+bool spmapkey::operator<(const spmapkey &other) const
+{
+ int cmp = v1.compare(other.v1);
+ if (cmp)
+ return cmp < 0;
+ cmp = v2.compare(other.v2);
+ if (cmp)
+ return cmp < 0;
+
+ // Objects are equal, now check dimensions
+ if (is_a<wildcard>(dim) || is_a<wildcard>(other.dim))
+ return false;
+ else
+ return dim.compare(other.dim) < 0;
+}
+
+void spmapkey::debugprint() const
+{
+ std::cerr << "(" << v1 << "," << v2 << "," << dim << ")";
+}
+