当前位置: 首页>>代码示例>>C++>>正文


C++ Relation::begin方法代码示例

本文整理汇总了C++中Relation::begin方法的典型用法代码示例。如果您正苦于以下问题:C++ Relation::begin方法的具体用法?C++ Relation::begin怎么用?C++ Relation::begin使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Relation的用法示例。


在下文中一共展示了Relation::begin方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: join

void join(Relation &lhs, Relation &rhs, vector<size_t> &vars, Relation &result) {
  DEBUG("Joining", "");
  DEBUG("  LHS size = ", lhs.size());
  DEBUG("  RHS size = ", rhs.size());
  Relation temp;
  Order order(vars);
  lhs.sort(order);
  rhs.sort(order);
  Relation::iterator lit = lhs.begin();
  Relation::iterator rit = rhs.begin();
  while (lit != lhs.end() && rit != rhs.end()) {
    Tuple joined;
    if (join(*lit, *rit, joined)) {
      Relation::iterator it;
      do {
        temp.push_back(joined);
        it = rit;
        for (++it; it != rhs.end() && join(*lit, *it, joined); ++it) {
          temp.push_back(joined);
        }
        ++lit;
      } while (lit != lhs.end() && join(*lit, *rit, joined));
      rit = it;
    } else if (order(*rit, *lit)) {
      ++rit;
    } else {
      ++lit;
    }
  }
  result.swap(temp);
  DEBUG("  Result size = ", result.size());
}
开发者ID:jrweave,项目名称:phd,代码行数:32,代码来源:infer-rules.cpp

示例2: print_relations

void print_relations(const Relation& relations)
{
    for (Relation::const_iterator rela_iter = relations.begin();
            rela_iter != relations.end(); rela_iter++) {
        copy(rela_iter->begin(), rela_iter->end(), ostream_iterator<int>(cout, " "));
        cout << endl;
    }
}
开发者ID:spockwangs,项目名称:snippets,代码行数:8,代码来源:micro.cpp

示例3: update

//! recreate html page if something changes
void MetadataItemPropertiesPanel::update()
{
    Database* db = dynamic_cast<Database*>(objectM);
    if (db && !db->isConnected())
    {
        objectM = 0;
        if (MetadataItemPropertiesFrame* f = getParentFrame())
            f->Close();

        // MB: This code used to use:
        //f->removePanel(this);
        // which would allow us to mix property pages from different
        // databases in the same Frame, but there are some mysterious
        // reasons why it causes heap corruption with MSVC

        return;
    }

    // if table or view columns change, we need to reattach
    if (objectM->getType() == ntTable || objectM->getType() == ntView)  // also observe columns
    {
        Relation* r = dynamic_cast<Relation*>(objectM);
        if (!r)
            return;

        SubjectLocker locker(r);
        r->ensureChildrenLoaded();
        for (ColumnPtrs::iterator it = r->begin(); it != r->end(); ++it)
            (*it)->attachObserver(this, false);
    }

    // if description of procedure params change, we need to reattach
    if (objectM->getType() == ntProcedure)
    {
        Procedure* p = dynamic_cast<Procedure*>(objectM);
        if (!p)
            return;

        SubjectLocker locker(p);
        p->ensureChildrenLoaded();
        for (ParameterPtrs::iterator it = p->begin(); it != p->end(); ++it)
            (*it)->attachObserver(this, false);
    }

    // with this set to false updates to the same page do not show the
    // "Please wait while the data is being loaded..." temporary page
    // this results in less flicker, but may also seem less responsive
    if (!htmlReloadRequestedM)
        requestLoadPage(false);
}
开发者ID:cyborgve,项目名称:FlameRobin,代码行数:51,代码来源:MetadataItemPropertiesFrame.cpp

示例4: act

void act(Atom &atom, Relation &results) {
  DEBUG("Act: atom = ", atom);
  Index &index = atoms[atom.predicate];
  Relation::iterator result = results.begin();
  size_t max = atom.arguments.end - atom.arguments.begin;
  for (; result != results.end(); ++result) {
    Tuple tuple(max);
    size_t i;
    for (i = 0; i < max; ++i) {
      if (atom.arguments.begin[i].type == CONSTANT) {
        tuple[i] = atom.arguments.begin[i].get.constant;
        DEBUG("part ", tuple[i]);
      } else if (atom.arguments.begin[i].type == VARIABLE) {
        tuple[i] = result->at(atom.arguments.begin[i].get.variable);
        DEBUG("part ", tuple[i]);
      } else {
        cerr << "[ERROR] Lists and/or function in target atom are not currently supported." << endl;
        return;
      }
    }
    DEBUG("inserting (ignore this ->", max);
    index.insert(tuple);
  }
}
开发者ID:jrweave,项目名称:phd,代码行数:24,代码来源:infer-rules.cpp

示例5: special

bool special(Condition &condition, Relation &intermediate, Relation &filtered) {
  if (condition.type != ATOMIC) {
    return false;
  }
  switch (condition.get.atom.type) {
    case ATOM:
    case MEMBERSHIP:
    case SUBCLASS:
    case FRAME:
      return false;
    case EQUALITY: {
      Term *lhs = &(condition.get.atom.get.sides[0]);
      Term *rhs = &(condition.get.atom.get.sides[1]);
      if (lhs->type == VARIABLE && rhs->type == CONSTANT) {
        swap(lhs, rhs);
      }
      if (rhs->type == CONSTANT) {
        if (lhs->get.constant != rhs->get.constant) {
          Relation empty;
          filtered.swap(empty);
        } else {
          filtered = intermediate;
        }
      } else if (lhs->type == CONSTANT) {
        Relation result;
        Relation::iterator it = intermediate.begin();
        for (; it != intermediate.end(); ++it) {
          if (it->size() <= rhs->get.variable) {
            it->resize(rhs->get.variable + 1);
          }
          if (it->at(rhs->get.variable) == 0) {
            result.push_back(*it);
            Tuple &t = result.back();
            t[rhs->get.variable] = lhs->get.constant;
          } else if (it->at(rhs->get.variable) == lhs->get.constant) {
            result.push_back(*it);
          }
        }
        filtered.swap(result);
      } else {
        varint_t maxvar = max(lhs->get.variable, rhs->get.variable);
        Relation result;
        Relation::iterator it = intermediate.begin();
        for (; it != intermediate.end(); ++it) {
          if (it->size() <= maxvar) {
            it->resize(maxvar + 1);
          }
          constint_t c1 = it->at(lhs->get.variable);
          constint_t c2 = it->at(rhs->get.variable);
          if (c1 == 0 && c2 == 0) {
            cerr << "[ERROR] Please make sure equality statements occur to the right of atomic formulas that bind a variable." << endl;
            return true;
          }
          if (c1 == 0) {
            result.push_back(*it);
            Tuple &t = result.back();
            t[lhs->get.variable] = c2;
          } else if (c2 == 0) {
            result.push_back(*it);
            Tuple &t = result.back();
            t[rhs->get.variable] = c1;
          } else if (c1 == c2) {
            result.push_back(*it);
          }
        }
        filtered.swap(result);
      }
      return true;
    }
    case EXTERNAL: {
      break; // just handle outside the messy switch statement
    }
    default: {
      cerr << "[ERROR] Unhandled case " << (int)condition.get.atom.type << " at line " << __LINE__ << endl;
      return false;
    }
  }

  ///// HANDLE BUILTIN (EXTERNAL) /////
  Builtin &builtin = condition.get.atom.get.builtin;
  switch (builtin.predicate) {
    case BUILTIN_PRED_LIST_CONTAINS: {
      if (builtin.arguments.end - builtin.arguments.begin != 2) {
        cerr << "[ERROR] Invalid use of list contains builtin, which should have exactly two arguments, but instead found " << builtin << endl;
        return false;
      }
      Term *arg1 = builtin.arguments.begin;
      Term *arg2 = arg1 + 1;
      if (arg1->type != LIST) {
        cerr << "[ERROR] First argument of list contains builtin must be a list, but instead found " << *arg1 << endl;
        return false;
      }
      switch (arg2->type) {
        case FUNCTION:
          cerr << "[ERROR] Functions not supported." << endl;
          return false;
        case LIST:
          cerr << "[ERROR] Currently not supporting nested lists." << endl;
          return false;
        case CONSTANT: {
//.........这里部分代码省略.........
开发者ID:jrweave,项目名称:phd,代码行数:101,代码来源:infer-rules.cpp

示例6: query

void query(Condition &condition, set<varint_t> &allvars, Relation &results) {
  deque<void*> negated;
  Relation intermediate;
  switch (condition.type) {
    case ATOMIC: {
      query(condition.get.atom, allvars, results);
      return;
    }
    case CONJUNCTION: {
      Condition *subformula = condition.get.subformulas.begin;
      for (; subformula != condition.get.subformulas.end; ++subformula) {
        if (subformula->type == NEGATION) {
          negated.push_back((void*)subformula->get.subformulas.begin);
          continue;
        }
        Relation subresult;
        set<varint_t> newvars;
        // TODO vvv this won't work right if a non-special query
        // has not been performed first
        if (special(*subformula, intermediate, subresult)) {
          if (subformula == condition.get.subformulas.begin) {
            cerr << "[ERROR] Must have non-special query at beginning of conjunction." << endl;
          }
          intermediate.swap(subresult);
          continue;
        }
        query(*subformula, newvars, subresult);
        if (subformula == condition.get.subformulas.begin) {
          intermediate.swap(subresult);
        } else {
          vector<size_t> joinvars(allvars.size() + newvars.size());
          vector<size_t>::iterator jit = set_intersection(allvars.begin(),
              allvars.end(), newvars.begin(), newvars.end(), joinvars.begin());
          joinvars.resize(jit - joinvars.begin());
          join(intermediate, subresult, joinvars, intermediate);
        }
        allvars.insert(newvars.begin(), newvars.end());
      }
      break;
    }
    case DISJUNCTION: {
      cerr << "[ERROR] Disjunction is not supported." << endl;
      return;
    }
    case EXISTENTIAL: {
      // assuming all quantified variables are uniquely named in the scope of the rule
      Condition *subformula = condition.get.subformulas.begin;
      for (; subformula != condition.get.subformulas.end; ++subformula) {
        if (subformula->type == NEGATION) {
          negated.push_back((void*)subformula->get.subformulas.begin);
        }
        Relation subresult;
        query(*subformula, allvars, subresult);
        intermediate.splice(intermediate.end(), subresult);
      }
      break;
    }
    case NEGATION: {
      cerr << "[ERROR] This should never happen.  query should not be called directly on negated formulas." << endl;
      return;
    }
    default: {
      cerr << "[ERROR] Unhandled case " << (int)condition.type << " on line " << __LINE__ << endl;
      return;
    }
  }
// TODO deal with negation later, if at all
#if 1
  deque<void*>::iterator it = negated.begin();
  for (; !intermediate.empty() && it != negated.end(); ++it) {
    Relation negresult;
    Condition *cond = (Condition*) *it;
    if (special(*cond, intermediate, negresult)) {
      intermediate.sort();
      negresult.sort();
      Relation leftover(intermediate.size());
      Relation::iterator iit = set_difference(intermediate.begin(),
          intermediate.end(), negresult.begin(), negresult.end(),
          leftover.begin());
      Relation newinter;
      newinter.splice(newinter.end(), leftover,
                      leftover.begin(), iit);
      intermediate.swap(newinter);
      continue;
    }
    query(*((Condition*)(*it)), allvars, negresult);
    minusrel(intermediate, negresult, intermediate);
  }
#endif
  results.swap(intermediate);
}
开发者ID:jrweave,项目名称:phd,代码行数:91,代码来源:infer-rules.cpp


注:本文中的Relation::begin方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。