示例#1
0
 bool operator()(const Tuple &t1, const Tuple &t2) const {
   vector<size_t>::const_iterator it = this->order.begin();
   for (; it != this->order.end(); ++it) {
     if (*it >= t1.size()) {
       if (*it < t2.size()) {
         return false;
       }
     } else if (*it >= t2.size()) {
       return true;
     } else if (t1[*it] != t2[*it]) {
       return t1[*it] < t2[*it];
     }
   }
   if (this->total_ordering) {
     Tuple::const_iterator cit1 = t1.begin();
     Tuple::const_iterator cit2 = t2.begin();
     while (cit1 != t1.end() && cit2 != t2.end()) {
       if (*cit1 != *cit2) {
         return *cit1 < *cit2;
       }
       ++cit1;
       ++cit2;
     }
     if (cit1 == t1.end()) {
       return cit2 != t2.end();
     }
   }
   return false;
 }
示例#2
0
double error_total(double (*efn)(MeshFunction*, MeshFunction*, RefMap*, RefMap*),
		   double (*nfn)(MeshFunction*, RefMap*), Tuple<Solution*>& slns1, Tuple<Solution*>& slns2	)
{
  Tuple<Solution*>::iterator it1, it2;
  double error = 0.0, norm = 0.0;

  for (it1=slns1.begin(), it2=slns2.begin(); it1 < slns1.end(); it1++, it2++) {
    assert(it2 < slns2.end());
    error += sqr(calc_abs_error(efn, *it1, *it2));
    if (nfn) norm += sqr(calc_norm(nfn, *it2));
  }

  return (nfn ? sqrt(error/norm) : sqrt(error));
}
void TupleStorageSubBlock::paranoidInsertTypeCheck(const Tuple &tuple, const AllowedTypeConversion atc) {
#ifdef QUICKSTEP_DEBUG
  assert(relation_.size() == tuple.size());

  Tuple::const_iterator value_it = tuple.begin();
  CatalogRelation::const_iterator attr_it = relation_.begin();

  while (value_it != tuple.end()) {
    switch (atc) {
      case kNone:
        assert(value_it->getType().equals(attr_it->getType()));
        break;
      case kSafe:
        assert(value_it->getType().isSafelyCoercibleTo(attr_it->getType()));
        break;
      case kUnsafe:
        assert(value_it->getType().isCoercibleTo(attr_it->getType()));
        break;
    }

    ++value_it;
    ++attr_it;
  }
#endif
}
示例#4
0
	inline Tuple *replace_tuple(const Tuple *t, size_t pos, const Value &val)
	{
		Tuple *ret = new_tuple(std::max(t->m_count, pos+1));
		std::copy(t->begin(), t->begin() + std::min(pos, t->m_count), ret->m_data);
		if (pos < t->m_count)
			std::copy(t->begin() + pos + 1, t->end(), ret->m_data + pos + 1);
		std::fill(ret->begin() + t->m_count, ret->end(), Nil);
		ret->m_data[pos] = val;
		return ret;
	}
示例#5
0
bool
Tuple::operator<(const Tuple& rhs) const
{
  auto iterl = begin();
  auto iterr = rhs.begin();

  while (iterl != end() && iterr != rhs.end())
  {
    if (iterl->first < iterr->first)
    {
      return true;
    }
    else if (iterr->first < iterl->first)
    {
      return false;
    }
    else if (iterl->second < iterr->second)
    {
      return true;
    }
    else if (iterr->second < iterl->second)
    {
      return false;
    }
    //this pair is equal, go to the next one
    ++iterl;
    ++iterr;
  }

  if (iterl == end() && iterr == rhs.end())
  {
    //they must be equal, so return false
    return false;
  }
  else if (iterl == end())
  {
    return true;
  }
  else
  {
    return false;
  }
}
示例#6
0
 inline Constant
 get_dimension(const Tuple& k, size_t index)
 {
   Tuple::const_iterator i = k.find(index);
   if (i == k.end())
   {
     throw DimensionNotFound();
   }
   return i->second;
 }
示例#7
0
 bool operator()(const Tuple& tup) const {
   auto& tarr = static_types_array<T...>::arr;
   if (tup.size() >= (sizeof...(T) - wc_count)) {
     auto fpush = [](const typename Tuple::const_iterator&) {};
     auto fcommit = [] {};
     auto frollback = [] {};
     return match(tup.begin(), tup.end(), tarr.begin(), tarr.end(),
            fpush, fcommit, frollback);
   }
   return false;
 }
示例#8
0
 bool operator()(const Tuple& tup) const {
   auto tup_size = tup.size();
   if (tup_size >= size) {
     auto& tarr = static_types_array<T...>::arr;
     auto begin = tup.begin();
     begin += (tup_size - size);
     return std::equal(begin, tup.end(),
               (tarr.begin() + 1), // skip 'anything'
               types_only_eq);
   }
   return false;
 }
示例#9
0
 TaggedConstant
 operator()(const Tuple& k)
 {
   Tuple::const_iterator iter = k.find(m_index);
   if (iter != k.end())
   {
     return TaggedConstant(iter->second, k);
   }
   else
   {
     return TaggedConstant(Types::Special::create(SP_DIMENSION), k);
   }
 }
  bool addEntry(const Tuple &tuple) {
	  Tuple::const_iterator attr_it;
	  int bloom_filter_id = 0;
	  for (attr_it = tuple.begin(); attr_it != tuple.end(); ++attr_it, ++bloom_filter_id) {
		  if (!attr_it->isNull()) {
			  ScopedPtr<char> attr_data_ptr(new char[attr_it->getInstanceByteLength()]);
			  attr_it->copyInto(static_cast<void*>(attr_data_ptr.get()));
			  bloom_filters_.get()[bloom_filter_id].insert(attr_data_ptr.get(),
					  	  	  	  	  	  	  	  	 attr_it->getInstanceByteLength());
		  }
	  }
	  return true;
  }
/**
 * @brief utility function that prints a Tuple on the specified ostream
 */
void ActionPluginFinalCallback::printTuple(std::ostream& output,
		const Tuple& tuple, const RegistryPtr registryPtr) {
	bool first = true;
	for (Tuple::const_iterator it = tuple.begin(); it != tuple.end(); it++) {
		if (first)
			first = !first;
		else
			output << ", ";
		if (it->isConstantTerm() || it->isVariableTerm())
			output << registryPtr->getTermStringByID(*it);
		else
			output << it->address;
	}
}
示例#12
0
 bool operator()(const Tuple& tup) const {
   if (not tup.dynamically_typed()) {
     // statically typed tuples return &typeid(type_list<T...>)
     // as type token
     return typeid(detail::type_list<T...>)== *(tup.type_token());
   }
   // always use a full dynamic match for dynamic typed tuples
   else if (tup.size() == sizeof...(T)) {
     auto& tarr = static_types_array<T...>::arr;
     return std::equal(tup.begin(), tup.end(), tarr.begin(),
               types_only_eq);
   }
   return false;
 }
void TupleStorageSubBlock::paranoidInsertTypeCheck(const Tuple &tuple) {
#ifdef QUICKSTEP_DEBUG
  assert(relation_.size() == tuple.size());

  Tuple::const_iterator value_it = tuple.begin();
  CatalogRelationSchema::const_iterator attr_it = relation_.begin();

  while (value_it != tuple.end()) {
    assert(value_it->isPlausibleInstanceOf(attr_it->getType().getSignature()));

    ++value_it;
    ++attr_it;
  }
#endif
}
示例#14
0
  bool operator()(const Tuple& tup, MappingVector& mv) const {
    auto& tarr = static_types_array<T...>::arr;
    if (tup.size() >= (sizeof...(T) - wc_count)) {
      size_t commited_size = 0;
      auto fpush = [&](const typename Tuple::const_iterator& iter) {
        mv.push_back(iter.position());

      };
      auto fcommit = [&] { commited_size = mv.size(); };
      auto frollback = [&] { mv.resize(commited_size); };
      return match(tup.begin(), tup.end(), tarr.begin(), tarr.end(),
             fpush, fcommit, frollback);
    }
    return false;
  }
示例#15
0
 bool operator()(const Tuple& tup) const {
   auto tup_size = tup.size();
   if (tup_size >= (size - 1)) {
     auto& tarr = static_types_array<T...>::arr;
     // first range [0, X1)
     auto begin = tup.begin();
     auto end = begin + wc_pos;
     if (std::equal(begin, end, tarr.begin(), types_only_eq)) {
       // second range [X2, N)
       begin = end = tup.end();
       begin -= (size - (wc_pos + 1));
       auto arr_begin = tarr.begin() + (wc_pos + 1);
       return std::equal(begin, end, arr_begin, types_only_eq);
     }
   }
   return false;
 }
示例#16
0
TTailHairpin::TTailHairpin(const Tuple &tuple, const Tuple &size) {
    int len = size[1];
    Tuple t = tuple;
    std::sort(t.begin(), t.end(), std::less<int>{});
    Frag frag;
        for (int i = t[0]; i <= t[1]; i++) {
            frag.push_back(i);
        }
        d_frags.push_back(std::move(frag));
        for (int i = t[2]; i < len; i++) {
            frag.push_back(i);
        }
        d_frags.push_back(std::move(frag));
        d_max_len = std::max(t[1] - t[0] - 1, len - t[2] - 1);
    d_indices = std::make_unique<Mati>(d_max_len, 3);
    for (int i = 0; i < d_max_len; i++) for (int j = 0; j < 3; j++) (*d_indices)(i, j) = -1;
    set_indices(0, d_frags[0].front() + 1, d_frags[0].back() - 1);
    set_indices(1, d_frags[1].front() + 1, len - 1);
}