Example #1
0
void Andrew() {
  list<point>::reverse_iterator rit;
  point a;
  sort(pts.begin(),pts.end(),sup);
  U.clear();
  L.clear();
  for (int i=0; i<n; i++) {
    while (L.size()>=2) {
      rit = L.rbegin();
      a = *rit;
      rit++;
      if (det(a,*rit,pts[i])>=0) {
	L.pop_back();
      }
      else break;
    }
    L.push_back(pts[i]);
  }
  for (int i=0; i<n; i++) {
    while (U.size()>=2) {
      rit = U.rbegin();
      a = *rit;
      rit++;
      if (det(a,*rit,pts[i])<=0) {
	U.pop_back();
      }
      else break;
    }
    U.push_back(pts[i]);
  }
  U.pop_front();
  L.pop_back();
}
Example #2
0
//display in rorder
void display_all_r(const list<int> &li)
{
	list<int>::const_reverse_iterator riter;
	for(riter = li.rbegin(); riter!= li.rend(); riter++)
		cout << *riter << " , ";
	cout << "\n";	
}
Example #3
0
int find_match(unsigned long src, unsigned long dst, double ts, double interval)
{
  list<ts_src_dst>::reverse_iterator it;
  for(it=interval_packets.rbegin(); it!= interval_packets.rend(); ++it)
  {
    if(src == it->_dst && dst == it->_src)
    {
      /*
      memset(srcip_buf, 0, 256);
      memset(dstip_buf, 0, 256);
      strcpy(srcip_buf, inet_ntoa(src_ip));
      strcpy(dstip_buf, inet_ntoa(dst_ip));

      src_ip1.s_addr = it->_src;
      dst_ip1.s_addr = it->_dst;
      memset(srcip_buf1, 0, 256);
      memset(dstip_buf1, 0, 256);
      strcpy(srcip_buf1, inet_ntoa(src_ip1));
      strcpy(dstip_buf1, inet_ntoa(dst_ip1));
      printf("%f\t%s\t%s\t%f\t%s\t%s\n",it->_ts, srcip_buf1, dstip_buf1, ts, srcip_buf, dstip_buf);
      */
      if(ts-it->_ts <= interval)
	return 1;
    }
  }
  return 0;
}
Example #4
0
void checkdumpnesting(string &s, unsigned int team, list< vector<fixture> > &prevgames, unsigned int n) {
	char buffer[100];
	list< vector<fixture> >::reverse_iterator rit;
	bool stop=false;
	vector<unsigned int> teamssincelast(n,0);
	for( rit=prevgames.rbegin() ; rit != prevgames.rend(); rit++ ) {
		vector<fixture>::iterator fx;
		for(fx=rit->begin() ; fx != rit->end(); fx++ ) {
			if(fx->team1==team || fx->team2==team) {
				stop=true;
				break;
			}
		}
		if(stop) break;
		for(fx=rit->begin() ; fx != rit->end(); fx++ ) {
			teamssincelast[fx->team1]++;
			teamssincelast[fx->team2]++;
		}
	}
	string cat;
	for(unsigned int i=0; i<n; i++) {
		if(teamssincelast[i]>=2) {
			snprintf(buffer, sizeof(buffer), " %d,", i+1);
			cat+=buffer;
		}
	}
	if(cat.size()) {
		snprintf(buffer, sizeof(buffer), "\t%d:", team+1);
		s+=buffer;
		s+=cat;
	}
}
Example #5
0
void callFunc(AstNode* ast) {
	FuncObject* func = null;
	for (list<FuncObject*>::reverse_iterator i = funcs.rbegin(); i != funcs.rend(); i++) {
		FuncObject *obj = *i;

		if (strcmp(obj->name, (char*) ast->value) == 0) {
			func = obj;
			break;
		}
	}

	if (func == null) {
		printf("Unknown variable %s", (char*) ast->value);
		exit(1);
	}

	AstNode* node = func->value->left;
	AstNode* valNode = ast->left;
	while (node != null && node->left != null && valNode != null && valNode->left != null) {
		DefObject *object = (DefObject*) node->left->left->value;
		defineVar(object->name, calc(valNode->left));

		node = node->right;
		valNode = valNode->right;
	}

	_interpretate(func->value->right);
}
 void del(){
     if(size > 0){
         list<pair<int, int> >::reverse_iterator it = val_list.rbegin();
         kv_map.erase(it->first);
         val_list.pop_back();
         size--;
     }
 }
Example #7
0
	bool is_erased(sc_addr val)
	{
		list::reverse_iterator iter = erased->rbegin();
		while (iter != erased->rend())
			if (*iter++ == val)
				return true;
		return false;
	}
Example #8
0
CEAnalysisStep CounterexampleAnalyzer::getSpuriousTransition(list<CeIoVal> partOfCeTrace, TransitionGraph* originalTraceGraph, 
                                           const EState* compareFollowingHere, StateSets* statesPerCycleIndex) {
  assert(compareFollowingHere);
  const EState* currentState = compareFollowingHere;
  bool matchingState;
  CeIoVal realBehavior;
  int index = 1;
  CEAnalysisStep result;
  result.assertionCausingSpuriousInput = false;
  StateSets::iterator cycleIndexStates;
  if (statesPerCycleIndex) { //bookkeeping for analyzing the cyclic part of the counterexample
    cycleIndexStates = statesPerCycleIndex->begin();
  }
  // iterate over part of the counterexample and compare its behavior step-by-step against the original program's trace
  for (list<CeIoVal>::iterator i = partOfCeTrace.begin(); i != partOfCeTrace.end(); i++) {
    matchingState = false;
    EStatePtrSet successors = originalTraceGraph->succ(currentState);
    // the trace graph should always contain enough states for the comparision
    assert(successors.size()>0);
    // retrieve the correct state at branches in the original program (branches may exist due to inherent loops)
    // note: assuming deterministic input/output programs
    for (EStatePtrSet::iterator succ = successors.begin(); succ != successors.end(); succ++) {
      realBehavior = eStateToCeIoVal(*succ);
      //cout << "DEBUG: realBehavior: " << ceIoValToString(realBehavior) << "   ceTraceItem: " << ceIoValToString(*i) << endl;
      if (realBehavior == (*i)) {  //no spurious behavior when following this path, so continue here
        currentState = (*succ);
        index++;
        matchingState = true;
        if (statesPerCycleIndex) {
          //check if the real state has already been seen
          pair<boost::unordered_set<const EState*>::iterator, bool> notYetSeen = cycleIndexStates->insert(currentState);
          if (notYetSeen.second == false) {
            //state encountered twice at the some counterexample index. cycle found --> real counterexample
            result.analysisResult = CE_TYPE_REAL;
            return result;
          } else {
            cycleIndexStates++;
          }
        }
      // special case. output-> failing assertion occurs during execution of the original program, leading to a spurious input symbol.
      // RefinementConstraints should use the failing assertion's condition to add new constraints, trying to enforce the assertion to fail
      // and thus eliminating the spurious input symbol.
      } else if (realBehavior.second == IO_TYPE_ERROR && i->second == IO_TYPE_INPUT) {
        result.assertionCausingSpuriousInput = true;
        result.failingAssertionInOriginal = (*succ)->label();
      }
    }
    // if no matching transition was found, then the counterexample trace is spurious
    if (!matchingState) {
      result.analysisResult = CE_TYPE_SPURIOUS;
      result.spuriousIndexInCurrentPart = index;
      return result;
    }
  }
  IoType mostRecentOriginalIoType = (partOfCeTrace.rbegin())->second;
  determineAnalysisStepResult(result, mostRecentOriginalIoType, currentState, originalTraceGraph, index);
  return result; // partOfCeTrace could be successfully traversed on the originalTraceGraph
}
Example #9
0
void CRealTextParser::PopTag(list<Tag>& p_rlistTags, const wstring& p_crszTagName)
{
    for (list<Tag>::reverse_iterator riter = p_rlistTags.rbegin(); riter != p_rlistTags.rend(); ++riter) {
        if (riter->m_szName == p_crszTagName) {
            p_rlistTags.erase((++riter).base());
            return;
        }
    }
}
Example #10
0
int main() {
  int cpt = 1;
  bool Uvide,Lvide;
  flott x,y,per;
  list<point>::iterator it;
  list<point>::reverse_iterator rit;
  point a;

  while (cin >> n) {
    if (n==0) return 0;
    pts.clear();
    for (int i=0; i<n; i++) {
      cin >> x >> y;
      pts.push_back(point(x,y));
    }
    Andrew();
    
    cout << "Region #" << cpt++ << ":\n";

    Uvide = U.empty();
    Lvide = L.empty();
    
    
    if (Uvide) per = dist(L.front(),L.back());
    else if (Lvide) per = dist(U.front(),U.back());
    else per = dist(L.front(),U.front())+dist(L.back(),U.back());

    if (!Uvide) printf("(%.1f,%.1f)-",round(10*U.back().first)/10,round(10*U.back().second)/10);
    else printf("(%.1f,%.1f)-",round(10*L.back().first)/10,round(10*L.back().second)/10);

    if (!Lvide) {
      a = L.back();
      rit = L.rbegin();
      while (rit!=L.rend()) {
	per += dist(a,*rit);
	printf("(%.1f,%.1f)-",round(10*(rit->first))/10,round(10*(rit->second))/10);
	a = *rit;
	rit++;
      }
    }
    if (!Uvide) {
    it = U.begin();
    a = *it;
    while (it!=U.end()) {
      per += dist(a,*it);
      printf("(%.1f,%.1f)",round(10*it->first)/10,round(10*it->second)/10);
      a = *it;
      it++;
      if (it!=U.end()) cout << '-';
      else cout << '\n';
    }
    }
    printf("Perimeter length = %.2f\n\n",round(100*per)/100);
  }

  return 0;
}
vector<pair<int,double>> PastPricesTrendLine::findLocalOptima(list<double>& pastPrices, bool max)
{
	vector<pair<int,double>> result;

	bool previousAscending = false;
	bool previousDescending = false;
	bool ascending = false;
	bool descending = false;
	double lastPrice;

	list<double>::reverse_iterator rit;
	rit = pastPrices.rbegin();
	int position = 0;
	while (result.size() < 2 && rit != pastPrices.rend())
	{
		previousAscending = ascending;
		previousDescending = descending;
		if (rit != pastPrices.rbegin())
		{
			ascending = *rit - lastPrice > 0;
			descending = *rit - lastPrice < 0;
		}
		if (position > 2)
		{
			if (max)
			{
				if (descending && previousAscending || (!ascending && !descending && !previousAscending && !previousDescending))
				{
					result.emplace_back(position, *rit);
				}
			}
			else
				if (ascending && !previousAscending || (!ascending && !descending && !previousAscending && !previousDescending))
				{
					result.emplace_back(position, *rit);
				}

		}
		lastPrice = *rit;
		rit++;
		position++;;
	}
	return result;
}
void Hypergraph::findSampleSets(int vertexIdx, float &maxDist, const vector<float> &distMat, list<int> &sampleBuf, int &Vsize, int Vmax, int Smax)
{
	//srand(time(NULL));
	int nTotal = _nVertices + _edges.size();

	int bufMax = Vmax+Smax;
	list<int>::iterator Vpos = sampleBuf.begin();
	advance(Vpos, Vsize*2);
	sampleBuf.erase(Vpos, sampleBuf.end());

	for (int i=0; i<vertexIdx; ++i)
	{
		float p = (bufMax-sampleBuf.size()/2)*1.0f/(vertexIdx-i);
		if ((time(NULL)%1000)/1000.0f <= p)
		{
			float d = distMat[vertexIdx*(vertexIdx-1)/2+i];
			list<int>::iterator insertPos = sampleBuf.begin();
			list<int>::iterator insertPosNext = insertPos;
			if (insertPos!=sampleBuf.end())
			{
				advance(insertPosNext, 1);
			}
			while(insertPos!=sampleBuf.end() && (*insertPosNext<d || *insertPosNext==d && *insertPos<i))
			{
				advance(insertPos, 2);
				if (insertPos!=sampleBuf.end())
				{
					advance(insertPosNext, 2);
				}
			}


			if (insertPos==sampleBuf.end() || *insertPosNext>d || *insertPos != i)
			{
				list<int>::iterator it = sampleBuf.insert(insertPos, d);
				sampleBuf.insert(it, i);

				if (d<maxDist)
				{
					++Vsize;
					if (Vsize>=Vmax)
					{
						Vsize = Vmax;
						maxDist = *(sampleBuf.rbegin());
					}
				}
			}

			if (sampleBuf.size()>=2*bufMax)
			{
				break;
			}
		}
	}
}
Example #13
0
void
process(vector<int> const v, list<int> &lst, unsigned int n)
{
    list<int>::iterator k = lst.begin();

    for (vector<int>::const_iterator i = v.begin(); i < v.end() && k != lst.end(); i += n, ++k){
            *k = *i;
    }
    copy(lst.rbegin(), lst.rend(), ostream_iterator<int>(cout, " "));
    return;
}
Example #14
0
double RateOfChange::calculate(list<double>& pastPrices)
{
	double lastPrice = pastPrices.back();
	double priceNPeriodsAgo;
	
	list<double>::reverse_iterator it = pastPrices.rbegin();
	advance(it, getPeriod());
	priceNPeriodsAgo = *it;

	double ROC = (lastPrice - priceNPeriodsAgo) / priceNPeriodsAgo * 100;
	return ROC;
}
Example #15
0
list<char> mult(list<char> a, list<char> b) {
  //int ia, ib, ic(0), carry(0), c;
  int carry, c, ic;
  list<char>::reverse_iterator ia, ib;
  int lena = a.size();
  int lenb = b.size();
  char crev[ MAX_LEN_PROD * 2 + 3 ];
  memset(crev, '0', MAX_LEN_PROD * 2 + 3);
  for(ib = b.rbegin(); ib != b.rend(); ++ib) {    
    ic = distance(b.rbegin(),ib);
    carry = 0;
    for(ia = a.rbegin(); ia != a.rend(); ++ia) {      
      c = (*ib - '0') * (*ia - '0') + carry + crev[ic] - '0';
      carry = c / 10;
      crev[ ic++ ] = c % 10 + '0';
    }
    crev[ ic ] = carry + '0';
  }
  list<char> ret(crev, crev + ic + (carry > 0 ? 1 : 0));
  ret.reverse();
  return ret;
}
Example #16
0
void QueueWithPriority::print() {
    cout << "--- Print Queue ---" << endl;
    if ( qwp_list.empty() ) {
        cout << "Queue is empty" << endl;
    } else {
        cout << "Queue size: " << qwp_list.size() << endl;
    }
    // обратный итератор потому что наша очередь наоборот
    list<QueueElement>::reverse_iterator it;
    for (it=qwp_list.rbegin(); it!=qwp_list.rend(); ++it) {
        cout << "QueueElement: " << (*it).name << " - " << (*it).priority << endl;
    }
}
Example #17
0
void special_print(list<int>v){
	list<int>::iterator iter = v.begin();
	list<int>::reverse_iterator r_iter = v.rbegin();
	int i = 0;
	cout <<"[ ";
	while(i != (v.size()/2)){
		cout << *iter << ", " << *r_iter << ", ";
		++iter;
		++r_iter;
		i++;
	}
	cout << "]";
}
Example #18
0
VarObject* findVar(char* name) {
	for (list<VarObject*>::reverse_iterator i = vars.rbegin(); i != vars.rend(); i++) {
		VarObject *obj = *i;

		if (strcmp(obj->name, name) == 0) {
			return obj;
		}
	}

	printf("Unknown variable %s", name);
	exit(1);

	return null;
}
Example #19
0
	bool satisfiable() {
		for (size_t i = 1; i < size; i++)
			if (!visited[i])
				dfs(i);

		for (auto it = post_order.rbegin(); it != post_order.rend(); it++)
			if (visited[*it] && visited[not_(*it)])
				dfsr(*it);

		for (size_t i = 1; i <= atoms; i++)
			if (solution[i] && solution[not_(i)])
				return false;
		return true;
	}
Example #20
0
void add(list<ImageSet> &aSets, const cElFilename &aFilename)
{
	ImageSet::Info info(aFilename);
	list<ImageSet>::iterator it = aSets.begin();
	while (it != aSets.end() && it->mInfo != info) it++;

	if (it == aSets.end())
	{
		aSets.push_back(ImageSet(info));
		it = --aSets.rbegin().base();
	}

	it->mFilenames.push_back(aFilename);
}
Example #21
0
void g(list<int>& l) {
    list<int> tmp;
    list<int>::iterator it;
    list<int>::reverse_iterator rt;
    for (it = l.begin(); it != l.end(); it++)
        tmp.push_back(*it);
    l.clear();
    for (it = tmp.begin(); it != tmp.end(); it++) {
        l.push_back(*it);
        l.push_back(*it);
    }
    for (rt = l.rbegin(); rt != l.rend(); rt++)
        cout << *rt << " ";
    cout << endl;
}
void SipCtrlInterface::prepare_routes_uac(const list<sip_header*>& routes, string& route_field)
{
    if(!routes.empty()){
	
	list<sip_header*>::const_reverse_iterator it = routes.rbegin();

	route_field = c2stlstr((*it)->value);
	++it;

	for(; it != routes.rend(); ++it) {
		
	    route_field += ", " + c2stlstr((*it)->value);
	}
    }
}
void InterpreterDBG::sendStackInfo(list<pair<string, int> >& stk) {
  if(clientsock < 0) return;

  stringstream s;
  s << "<stackinfo>";
  int id = 0;
  for(list<pair<string, int> >::reverse_iterator it = stk.rbegin(); it != stk.rend(); ++it) {
    s << "<entry id=\"" << id++
      << "\" function=\"" << (*it).first
      << "\" line=\"" << (*it).second << "\"/>";
  }
  s << "</stackinfo>";

  sendData(s);
}
long long decode(list<int> &number,int base)
{

	long long num=0;
	long long power=1;
	for(list<int>::reverse_iterator i=number.rbegin();i!=number.rend();i++)
	{
		if(*i>0)
		{
			num+=power*(*i);
		}
		power*=base;
	}
	return num;
}
Example #25
0
 void put(int key, int value) {
     auto it = data.find(key);
     if (it != data.end()) {
         access_order.splice(access_order.begin(), access_order, it->second.second);
         data[key] = {value, access_order.begin()};
     } else {
         if (current_capacity == _capacity) {
             data.erase(*access_order.rbegin());
             access_order.pop_back();
         } else {
             current_capacity++;
         }
         access_order.push_front(key);
         data[key] = {value, access_order.begin()};
     }
 }
// Formats the mapping of the ConfigurableElements
string CSubsystem::formatMappingDataList(
        const list<const CConfigurableElement*>& configurableElementPath) const
{
    // The list is parsed in reverse order because it has been filled from the leaf to the trunk
    // of the tree. When formatting the mapping, we want to start from the subsystem level
    ostringstream ossStream;
    list<const CConfigurableElement*>::const_reverse_iterator it;
    for (it = configurableElementPath.rbegin(); it != configurableElementPath.rend(); ++it) {

        const CInstanceConfigurableElement* pInstanceConfigurableElement =
                static_cast<const CInstanceConfigurableElement*>(*it);

        ossStream << pInstanceConfigurableElement->getFormattedMapping() << ", ";
    }
    return ossStream.str();
}
Example #27
0
void ReadTriMesh(){
  if (surface!=0){
    MovedTris.sort();
    int CheckSurface=0;
    for(list<int>::const_reverse_iterator it = MovedTris.rbegin(); it != MovedTris.rend(); it++){
      surface->RemoveTri(*it);
      CheckSurface=1;
    }
    MovedTris.clear();
    if (surface->no_tris==0 && CheckSurface !=0) {
      delete surface;
      mesh->surf_list.remove(surface);
      mesh->no_surfs=mesh->no_surfs-1;
    }
  }
  surface = mesh->CreateSurface();
}
Example #28
0
bool ok()
{
  bool end_tag,short_tag;
  pos=0;
  stack.clear();

  while (pos < (int)line.length()) {
    if (matches("T")) continue;
    if (matches("&")) {
      if (matches("lt;") || matches("gt;") || matches("amp;")) continue;
      if (matches("xHH")) {
	while (matches("HH")) { }
	if (!matches(";")) return false;
      } else {
	// & not followed by valid escape sequence
	return false;
      }
      continue;
    }
    if (matches("<")) {
      end_tag=matches("/");

      int name_start=pos;
      while (matches("A")) { };
      int name_end=pos;
      string tag=line.substr(name_start,name_end-name_start);
      if (tag == "") return false;

      if (!end_tag) short_tag=matches("/");
      else short_tag = false;
      if (!matches(">")) return false;

      if (DEBUG) { cout << "encountered <" << (end_tag ? "/" : "") << tag << (short_tag ? "/" : "") << ">" << endl; }

      if (!end_tag && !short_tag) { stack.push_back(tag); }
      if (end_tag) { 
	if (stack.empty() || *stack.rbegin() != tag) return false;
	stack.pop_back();
      }
      continue;
    }
    return false;
  }
  return stack.empty();
}
Example #29
0
RObject *get_variable(const char *name){
  list<unordered_map<string, RObject*>*>::reverse_iterator rit;
  //unordered_map<string, Instruccion*>* stack;
  rit = scope_stack.rbegin();
  RObject *object=NULL;
  do {
    if ((*rit)->find(name) != (*rit)->end())
      object = (**rit)[name];
    rit++;
  } while (object == NULL && rit != scope_stack.rend());
  if (name[0] == '@' && object == NULL && excecuting_current_class != NULL)
    object = excecuting_current_class->get_instance_variable(name);
  if (object == NULL && global_variables->find(name) != global_variables->end())
    object = (*global_variables)[name];
  if (object == NULL){
    object = new RObject(true);
  }
  return object;
}
Example #30
0
static void cb_mouse(double mx, double my, int flags)
{
	if (flags & MOUSE_RELEASE)
	{
		points.push_back(new Point(mx,my));
		if(points.size() > 1)
		{
			auto ip(points.rbegin());
			auto jp(points.rbegin());
			ip++;
			Point p3 = **jp;
			for(; ip!=points.rend(); ip++)
			{
				Point p4 = **ip;
				edges.push_back(new Edge(p3,p4));
            }
		}
	}
};