예제 #1
0
파일: sequence.cpp 프로젝트: sten1ee/cpp
bool  Sequencer::adjoin(Seq* newseq)
{
  if (bContradictory) {
    delete newseq;
    return false;
  }
  if (newseq->isEmpty()) {
    delete newseq;
    seq.flush();
    bContradictory = true;
    return false;
  }
  if (newseq->isTrivial()) {
    delete newseq;
    return true;
  }
  int  cur = seq.size();
  seq.push(newseq);
  AtomSet common;
LOOP:
  while (cur < seq.size()) {
    for (size_t i=cur; 0 < i--; ) {
      if (seq[cur]->implies(*seq[i])) {
        delete seq[i];
        seq.erase(seq.begin() + i);
        cur--;
      }
      else if (seq[i]->implies(*seq[cur])) {
        delete seq[cur];
        seq.erase(seq.begin() + cur);
        goto LOOP;
      }
    }
    for (size_t j=cur; 0 < j--; ) {
      Seq res;
      res.conj = seq[cur]->conj | seq[j]->conj;
      res.disj = seq[cur]->disj | seq[j]->disj;
      common   = res.conj & res.disj;
      if (common.size() == 1) {
        res.conj.erase(res.conj.find(common[0]));
        res.disj.erase(res.disj.find(common[0]));
        if (res.isEmpty()) {
          seq.flush();
          seq.push(new Seq(res));
          bContradictory = true;
          return false;
        }
        seq.push(new Seq(res));
      }
    }
    cur++;
  }
  return true;
}
예제 #2
0
int
AtomSet::operator< (const AtomSet& atomset2) const
{
  if (this->size() < atomset2.size()) // <
    {
      return true;
    }
  else if (this->size() > atomset2.size()) // >
    {
      return false;
    }
  else // same size, they can still be < or >=
    {
      // find first mismatch
      std::pair<AtomSet::const_iterator, AtomSet::const_iterator> result;
      result = std::mismatch(this->begin(), this->end(), atomset2.begin());

      // no mismatch: ==, otw. check if the found mismatch is < or >=
      return result.first == this->end() ? false : *result.first < *result.second;
    }
}
예제 #3
0
bool
AtomSet::operator== (const AtomSet& atomset2) const
{
	return ((this->size() == atomset2.size()) 
	  && std::equal(this->begin(), this->end(), atomset2.begin()));
}