bool operator==(const HyperplaneTableEntry& oentry) const {

			if(nbrPoints != oentry.nbrPoints)
				return false;

			if(nbrLines != oentry.nbrLines)
				return false;

			if(!map_compare(pointsOfOrder, oentry.pointsOfOrder))
				return false;

			// Compare subgeometries (order is not important) with those of the other entry
			// check if all subgeometries correspond to a subgeometry of the other entry
			std::set<const std::map<long long int, size_t>*> already_used;
			for(const std::map<long long int, size_t>& subgeometry : subgeometries){

				// Check if the subgeometry corresponds to a subgeometry of the other entry
				const std::vector<std::map<long long int, size_t>>::const_iterator itt = std::find_if(
				  oentry.subgeometries.cbegin(), oentry.subgeometries.cend(),
				  [&already_used, &subgeometry](const std::map<long long int, size_t>& osubgeometry){
                      // if equal and not already used in a correspondence
                      if(subgeometry == osubgeometry && already_used.count(&osubgeometry) == 0){
                          already_used.insert(&osubgeometry);
                          return true;
                      }
                      return false;
                  });
				if(itt == oentry.subgeometries.cend()){
					return false;
				}
			}

			return true;
		}
Esempio n. 2
0
int Mul::compare(const Basic &o) const
{
    SYMENGINE_ASSERT(is_a<Mul>(o))
    const Mul &s = static_cast<const Mul &>(o);
    // # of elements
    if (dict_.size() != s.dict_.size())
        return (dict_.size() < s.dict_.size()) ? -1 : 1;

    // coef
    int cmp = coef_->__cmp__(*s.coef_);
    if (cmp != 0)
        return cmp;

    // Compare dictionaries:
    return map_compare(dict_, s.dict_);
}
Esempio n. 3
0
int Add::compare(const Basic &o) const
{
    SYMENGINE_ASSERT(is_a<Add>(o))
    const Add &s = static_cast<const Add &>(o);
    // # of elements
    if (dict_.size() != s.dict_.size())
        return (dict_.size() < s.dict_.size()) ? -1 : 1;

    // coef
    int cmp = coef_->__cmp__(*s.coef_);
    if (cmp != 0)
        return cmp;

    // Compare dictionaries:
    // NOTE: This is slow. Add should cache this map_basic_num representation
    // once it is computed.
    map_basic_num adict(dict_.begin(), dict_.end());
    map_basic_num bdict(s.dict_.begin(), s.dict_.end());
    return map_compare(adict, bdict);
}
Esempio n. 4
0
/*
 * compare the variable a with the variable b
 * returns
 *   -1      a < b
 *   +1      a > b
 *   0       a = b
 */
int v_compare(var_t *a, var_t *b) {
  var_num_t dt;
  var_int_t di;

  if (a == 0 || b == 0) {
    err_evsyntax();
    return 0;
  }

  if (a->type == V_INT && b->type == V_INT) {
    di = (a->v.i - b->v.i);
    return (di < 0 ? -1 : di > 0 ? 1 : 0);
  } else if ((a->type == V_INT || a->type == V_NUM) &&
             (b->type == V_INT || b->type == V_NUM)) {
    var_num_t left = (a->type == V_NUM) ? a->v.n : a->v.i;
    var_num_t right = (b->type == V_NUM) ? b->v.n : b->v.i;
    dt = (left - right);
    return (dt < 0.0 ? -1 : dt < 0.0000000000000000001f ? 0 : 1);
  }
  if ((a->type == V_STR) && (b->type == V_STR)) {
    return strcmp(a->v.p.ptr, b->v.p.ptr);
  }
  if ((a->type == V_STR) && (b->type == V_NUM)) {
    if (a->v.p.ptr[0] == '\0' || is_number(a->v.p.ptr)) {
      // compare nums
      dt = v_getval(a);
      return (dt < b->v.n) ? -1 : ((dt == b->v.n) ? 0 : 1);
    }
    return 1;
  }
  if ((a->type == V_NUM) && (b->type == V_STR)) {
    if (b->v.p.ptr[0] == '\0' || is_number(b->v.p.ptr)) {
      // compare nums
      dt = v_getval(b);
      return (dt < a->v.n) ? 1 : ((dt == a->v.n) ? 0 : -1);
    }
    return - 1;
  }
  if ((a->type == V_STR) && (b->type == V_INT)) {
    if (a->v.p.ptr[0] == '\0' || is_number(a->v.p.ptr)) {
      // compare nums
      di = v_igetval(a);
      return (di < b->v.i) ? -1 : ((di == b->v.i) ? 0 : 1);
    }
    return 1;
  }
  if ((a->type == V_INT) && (b->type == V_STR)) {
    if (b->v.p.ptr[0] == '\0' || is_number(b->v.p.ptr)) {
      // compare nums
      di = v_igetval(b);
      return (di < a->v.i) ? 1 : ((di == a->v.i) ? 0 : -1);
    }
    return - 1;
  }
  if ((a->type == V_ARRAY) && (b->type == V_ARRAY)) {
    // check size
    if (a->v.a.size != b->v.a.size) {
      if (a->v.a.size < b->v.a.size) {
        return -1;
      }
      return 1;
    }
    // check every element
    int i, ci;
    for (i = 0; i < a->v.a.size; i++) {
      var_t *ea = (var_t *)(a->v.a.ptr + sizeof(var_t) * i);
      var_t *eb = (var_t *)(b->v.a.ptr + sizeof(var_t) * i);
      if ((ci = v_compare(ea, eb)) != 0) {
        return ci;
      }
    }
    // equal
    return 0;
  }

  if (a->type == V_MAP && b->type == V_MAP) {
    return map_compare(a, b);
  }

  err_evtype();
  return 1;
}