Example #1
0
int makeNewCSpace()
{
  if(spacesDeleteList.empty()) {
    spaces.push_back(new PyCSpace);
    return (int)(spaces.size()-1);
  }
  else {
    int index = spacesDeleteList.front();
    spacesDeleteList.erase(spacesDeleteList.begin());
    spaces[index] = new PyCSpace;
    return index;
  }
}
  inline request_data::pointer get() {
    std::unique_lock<std::mutex> lock(mutex);

    request_data::pointer request;
    if (!requests.empty()) {
      request = requests.front();
      requests.pop_front();
    }

    (void)lock;

    return request;
  }
Example #3
0
void print(const list<T>& ll) {
    cout << "Empty: " << boolalpha << ll.empty() << endl;
    cout << "Size: " << ll.size() << endl;
    if(ll.size() > 0) {
        cout << "Front: " << ll.front() << endl;
        cout << "Back: " << ll.back() << endl;
    }
    cout << "Contents: ";
    for(auto& node : ll) {
        cout << node << " ";
    }
    cout << endl;
}
Example #4
0
int CCardOperator::getLittestCardRval(list<CCardSprite*>& lstCards){
    int seq = lstCards.front()->getSeq();
    int rval = vecCardInfo[seq].rval;
    
    for (list<CCardSprite*>::iterator iter = lstCards.begin();
         iter != lstCards.end(); ++iter) {
        seq = (*iter)->getSeq();
        if (vecCardInfo[seq].rval < rval) {
            rval = vecCardInfo[seq].rval;
        }
    }
    return rval;
}
Example #5
0
bool
CCardOperatorBase:: isTypeNormalBoom(const list<int>& lstCards){
    if (lstCards.size() >= BOOM_MIN_COUNTS) {
        int var = lstCards.front();
        for (int v : lstCards) {
            if (v != var) {
                return false;
            }
        }
        return true;
    }
    return false;
}
Example #6
0
VOID ASockIOFini()
{
	while(free_oconns.size()!=total_oconns) Sleep(0);
	PCONNECTION pconn;
	while(!free_oconns.empty()) {
		pconn = (PCONNECTION)free_oconns.front();
		free_oconns.pop_front();
		closesocket(pconn->s);
		delete(pconn);
	}
	WSACleanup();
	DeleteCriticalSection(&cs_free_olist);
}
Example #7
0
/*
 * Thread for issuing commands. 
 * Deques data from the receive queue and issues the commands with servoblaster
 */
void cmdIssuer() {
  while(1) {
    bool validData = false;
    queueMutex.lock();
    if(!cmdQueue.empty()) {
      char *data = (char *)cmdQueue.front();
      cmdQueue.pop_front();
      cout << "received message: " << data << endl;
      validData = true;
    }
    queueMutex.unlock();
  }
}
void RTSPropertiesViewImpl::onItemSelectionChanged(const list<NamingContextHelper::ObjectInfo>& items)
{
    if(items.size()!=1)
        return;

    const NamingContextHelper::ObjectInfo& item = items.front();
    if(item.id != currentItem.id){
        currentItem.id = item.id;
        currentItem.isAlive = item.isAlive;
        currentItem.kind = item.kind;
        showProperties();
    }
}
Example #9
0
list<int>::iterator Pathfinder::getClosestNode(int node,list<int>& targetNodes){
	int lCost=calcDistance(node, targetNodes.front());
    int tempCost;
    list<int>::iterator closestNode=targetNodes.begin();
    for(list<int>::iterator target_it=targetNodes.begin();target_it!=targetNodes.end();target_it++){
		tempCost=calcDistance(node, *target_it);
		if(lCost>tempCost){
			closestNode=target_it;
			lCost=tempCost;
		}	
    }	
    return closestNode;
}	
Example #10
0
int main() {
   string palabra = "ABCD";
   int tam = 0;
   Permutaciones(palabra);
   tam =  palabras.size();
   for (int i = 0; i < tam; ++i)
   {
      cout << palabras.front() << endl;
      palabras.pop_front();
   }
   cin.get();
   return 0;
}
Example #11
0
/// Sorts and filters a list of integers.
///
/// @param listVals
///     List of integers to sort and filter.
/// @param bRemoveZeros
///     Remove zeros from the list.
/* static */ void s_SortAndFilter(list<int>& listVals, bool bRemoveZeros)
{
    listVals.sort();
    listVals.unique();
    if (bRemoveZeros)
    {
        while (!listVals.empty() &&
               listVals.front() == 0)
        {
            listVals.pop_front();
        }
    }
}
Example #12
0
void update_giovanni(vector<list<int>> &adj, list<int> neighborhood, vector<int> &degs, int dancer, int degree)
{
    if(degree < degs[dancer])
    {
        degs[dancer] = degree;
        while(!neighborhood.empty())
        {
            int partner = neighborhood.front();
            update_giovanni(adj, adj[partner], degs, partner, degree+1);
            neighborhood.pop_front();
        }
    }
}
Example #13
0
int main() {
//    freopen("test.txt","r",stdin);
    int t;
    cin>>t;
    while(t--){
        int n;
        cin>>n;
        int v[n];
        int visited[n];
        for(int i=0;i<n;i++)
            visited[i]=0;
        for(int i=0;i<n;i++){
            int k;
            cin>>k;
            v[i]=k-1;
        }
        vector<int> countParent;
        for(int i=0;i<n;i++){
            visited[i]=1;
            if(!visited[v[i]]){
//                cout<<"i is:"<<i<<"\n";
                dfs(v[i],visited,v,1);
                countParent.push_back(temp.front());
//                cout<<"temp is:"<<temp.front()<<endl;
//                for(list<int> :: iterator it=temp.begin();it!=temp.end();it++)
//                {
//                    cout<<"list elements are:"<<*it<<" ";
//                }
//                cout<<"\n";
                temp.clear();
            }else if(i==v[i]){
                countParent.push_back(1);
            }
            
        }
//        cout<<countParent.size()<<"\n";
//        for(vector<int> ::iterator it=countParent.begin();it!=countParent.end();it++)
//            cout<<"map"<<*it<<"\n";
        /*if(countParent.size()==1){  
            cout<<countParent[0]<<"\n";
            continue;
        }
        
        long long lcm;
        lcm=(1ll*countParent[0]*countParent[1]/gcd(countParent[0],countParent[1]))%mod;
        for(int i=2;i<(int)countParent.size();i++)
            lcm=(lcm*countParent[i]/gcd(lcm,countParent[i]))%mod;*/
        cout<<lcms(countParent)<<"\n";
    }
    return 0;
}
	HIT_TYPE replace(int key) {
		int mpos = -1, trash;
		list<int>::iterator lpos;
		if (addr.size() == size) {
			trash = time.front(), time.pop_front();
			it = addr.find(trash);
			mpos = it->second.first;
			addr.erase(it);
		} else {
			mpos = memIdx++;
		}
		lpos = time.insert(time.end(), key);
		return addr.insert({key, make_pair(mpos, lpos)}).first;
	}
Example #15
0
int mrca(int* & P,list<int> taxa){
    int t=taxa.front();
    taxa.pop_front();
    bool flag = false;
    while (!flag && P[t]!=-1){
          t = P[t];
          flag=true;
          for (list<int>::iterator ia=taxa.begin();ia!=taxa.end();ia++){
              int j=*ia;
              if (!isAncestor(P,t,j)) {flag=false;break;}
          }
    }       
    return t;
}
Example #16
0
// Play or resume the song
void toggle_play(list<int> int_params, list<string> string_params, sp_session *session, sp_track *track) {
	string uri = string_params.front();

	if (!s_is_playing) {
		// just resume if its the same uri (current_uri is only set if the track has been loaded into the player)
		if (uri == s_current_uri)
			play_track(session, track);
		else {
			load_track_or_metadata(session, track, uri.c_str());
			s_play_after_loaded = true;
		}
	} else
		pause(int_params, string_params, session, track);
}
Example #17
0
bool detectIfAte (list <struct Coordinates> snakeBody, struct Coordinates bonus) {
     
     bool eaten;
     struct Coordinates snake;
     
     snake = snakeBody.front();
     
     if ((snake.x + 31 >= bonus.x && snake.x <= bonus.x + 31) && (snake.y+31 >= bonus.y && snake.y <= bonus.y + 31)) eaten = true; 
     else if ((snake.x <= bonus.x + 31 && snake.x >= bonus.x) && (snake.y+31 >= bonus.y && snake.y <= bonus.y + 31)) eaten = true;
     else if ((snake.y + 31 >= bonus.y && snake.y <= bonus.y + 31) && (snake.x+31 >= bonus.x && snake.x <= bonus.x + 31)) eaten = true;
     else if ((snake.y >= bonus.y && snake.y <= bonus.y + 31) && (snake.x+31 >= bonus.x && snake.x <= bonus.x + 31)) eaten = true;
     
     return eaten;
};
void UserInterface::showPTray(list<int> tray) const
{
	cout << "\nPrime Numbers found ->\n\n";

	while (tray.size() > 0)
	{
		cout << tray.front();
		cout << ", ";
		if (tray.size() % 10 == 0)
			cout << "\n";
		tray.pop_front();
	}
	cout << "\n\n";
}
Example #19
0
 void set(int key, int value) {
     if(hashmap.find(key) == hashmap.end()){
         if(hashmap.size() == capacity){
             hashmap.erase(store.back().first);
             store.pop_back();
         }
         store.push_front(make_pair(key, value));
         hashmap[key] = store.begin();
     }else{
         store.splice(store.begin(), store, hashmap[key]);
         hashmap[key] = store.begin();
         store.front().second = value;
     }
 }
Example #20
0
  inline request_data::pointer get()
  {
    boost::unique_lock< boost::mutex > lock(mutex);

    request_data::pointer p_ret;
    if (!requests.empty()) {
      p_ret = requests.front();
      requests.pop_front();
    }

    (void)lock;

    return p_ret;
  }
Example #21
0
// Нахождение стартовой точки - самой левой нижней
inline Point Jarvis::findBasePoint(const list<Point>& points)
{
    Point basePoint = points.front();

    for (auto& point : points)
    {
        if (point.y < basePoint.y)
            basePoint = point;
        else if (point.y == basePoint.y && point.x < basePoint.x)
            basePoint = point;
    }

    return basePoint;
}
Example #22
0
void HandRank::SetKickers(list<Card> cards, unsigned int& HandRank )
{
	if( cards.empty() )
		return;

	Card c = cards.front();
	cards.pop_front();
	SetKick1(c.GetValue(), HandRank);

	if( cards.empty() )
		return;

	c = cards.front();
	cards.pop_front();
	SetKick2(c.GetValue(), HandRank);

	if( cards.empty() )
		return;

	c = cards.front();
	cards.pop_front();
	SetKick3(c.GetValue(), HandRank);
}
Example #23
0
    T get_one()
    {
        std::lock_guard<std::mutex> lock(_mtx);

        if(_datas.size() == 0)
        {
            return T();
        }

        T one = _datas.front();
        _datas.pop_front();

        return one;
    }
void *schedule(void*){
  while(1){
    pthread_mutex_lock(&llock);
    pthread_mutex_lock(&elock);
        while (!r1.empty()){
           r2.push_back(r1.front());
                if(!r1.empty())r1.pop_front();
                pthread_cond_signal(&ewait);
        }
    pthread_mutex_unlock(&elock);
    pthread_mutex_unlock(&llock);
  }

}
/***
 *
 * Client registration adds the client information into the database
 *
 ***/
void client_registration(HRegistMessage *m, int client_socket){

    printf("Client registration! (%d)\n", client_socket);

    /* store information about the client into the local database */

    FD_SET(client_socket,&listen_set);
    socket_set.push_back(client_socket);
    if (client_socket>highest_socket)
        highest_socket=client_socket;

    clientSignals[client_socket]=m->get_param();
    int id = m->get_id();

    printf("id :: %d \n", id);

    if (id) {
        /* the client is relocating its communicating agent */
        /* the server dissacociates the old socket with the client, and
         * uses the new one instead */
        int cs = clientSocket[id];
        clientSocket[id] = client_socket;
        char *appName = clientName[cs];
        printf("appName:: %s \n", appName);
        clientInfo[appName]=client_socket;
        clientName.erase(cs);
        clientName[client_socket] = appName;

        FD_CLR(cs, &listen_set);
        if (cs==*socketIterator)
            socketIterator++;
        socket_set.remove(cs);
        if (highest_socket==cs)
            highest_socket--;
    } else {
        /* generate id for the new client */
        id = id_set.front();
        id_set.pop_front();
        clientSocket[id] = client_socket;
    }
    clientId[client_socket] = id;
    printf("Send registration (id %d) confimation !\n", id);

    /* send the confirmation message with the client_id */
    HRegistMessage *mesg=new HRegistMessage(HMESG_CLIENT_REG,client_socket);
    mesg->set_id(id);
    send_message(mesg, client_socket);
    delete mesg;
}
Example #26
0
ImageOf<PixelMono16> converter::create_frame(list<AER_struct> i_lAER) {
    int size_stack;
    int _x;
    int _y;
    int _pol;
    double _ts;

    cout << "Initialisation of the table of accumulation of the events" << endl;
    start = clock();
    while(( ((double)start/CLOCKS_PER_SEC)*1e3+20.0) > (((double)clock()/CLOCKS_PER_SEC)*1e3))
    {
    //             cout << ((double)start/CLOCKS_PER_SEC)*1e3+200.0 << "\t" << ((double)clock()/CLOCKS_PER_SEC)*1e3 << endl;
    }
    cout << "Size of the list (number of event packed) : " << i_lAER.size() << endl;
    size_stack = (int)i_lAER.size();

    //Init the base-frame in gray value
    ImageOf<PixelMono16> _tmp_cart_img = base_img;

    if(size_stack > 0) {
        for(int i=0; i<width; i++) {
            for(int j=0; j<height; j++)
                cart_pol_acc[i][j] = 0;
        }
        for(int index=0;index<size_stack;index++) {
            AER_struct event = i_lAER.front();
            _x = event.y;//event.x;
            _y = event.x;//event.y;
            _pol = event.pol;
            _ts = event.ts;
            i_lAER.pop_front();
//            cout << '\t' << _x << " " << _y << " " << _pol << " " << _ts << endl;

            if(_x!=-1 && _y!=-1) {
                //**Cartesian image computation
                cart_pol_acc[_x][_y]+=_pol;
                if(cart_pol_acc[_x][_y]< 0)
                    _tmp_cart_img(127-_y,127-_x)=0;//_tmp_cart_img(_x,_y)=0;
                else
                    if(cart_pol_acc[_x][_y]> 0)
                        _tmp_cart_img(127-_y,127-_x)=255;//_tmp_cart_img(_x,_y)=255;
                    else
                        _tmp_cart_img(127-_y,127-_x)=125;//_tmp_cart_img(_x,_y)=125;
                //******************************
            }
        }
    }
    return _tmp_cart_img;
}
Example #27
0
void Quadrant::Apply_repulsion(unsigned int node, const NumericMatrix &lay, NumericMatrix &dvec, const NumericVector &nodes_size, double krep, bool prevent_overlap, float theta)
{
    if(num_nodes == 1)
    {
        if(node != nodes.front())
        {
            unsigned int j = nodes.front();
            float _mass_prod = nodes_mass[node] * nodes_mass[j];
            float _sum_sizes = nodes_size[node] + nodes_size[j];
            apply_repulsion_one_sided(node, lay, dvec, _mass_prod, _sum_sizes, lay(j, 0), lay(j, 1), krep, prevent_overlap);
        }
    }
    else
    {
        float node_x = lay(node, 0);
        float node_y = lay(node, 1);
        float D = sqrt((node_x - center_x) * (node_x - center_x) + (node_y - center_y) * (node_y - center_y));
        
        if(D * theta > size)
        {
    
            //Rprintf("Mass region: %f\n", nodes_mass[node] * mass);
            //Rprintf("## num_nodes: %d, a: %d, b: %d, x center: %f, y center: %f\n", nodes.size(), node, nodes.front(), center_x, center_y);
            //Rprintf("--- %f, %f, %f\n", nodes_mass[node], mass, nodes_mass[node] * mass);
            //Ignore sum_sizes
            apply_repulsion_one_sided(node, lay, dvec, nodes_mass[node] * mass, -1, center_x, center_y, krep, prevent_overlap);
        }
        else
        {
            list<Quadrant *>::const_iterator x;
            for(x = subQuadrants.begin(); x != subQuadrants.end(); x++)
                (*x)->Apply_repulsion(node, lay, dvec, nodes_size, krep, prevent_overlap, theta);
        }
    }
    
}
Example #28
0
void execMKD(session* ses, list<string> args) {
    string dir("");
    dir += ses->currentDir;
    dir += args.front();

    string resp("");
    if (mkdir(dir.c_str(), 0755) != -1) {
        resp += "257 ";
        resp += cutPathPrefix(dir);
        resp += " Directory created.";
    } else {
        resp += "550 Requested action not taken.";
    }
    respond(ses, resp);
}
Example #29
0
void mark_incomplete_cuts(seq_t &sequence, list<cut_t> &cuts) {
    for(auto cut = cuts.begin(); cut != cuts.end(); ++cut) {
        if(cut->is_n) {
            if(cut->begin != 0) {
                previous(cut)->is_incomplete = true;
            }
            if(cut->end != sequence.len) {
                next(cut)->is_incomplete = true;
            }
        }
    }

    cuts.front().is_incomplete = true;
    cuts.back().is_incomplete = true;
}
Example #30
-1
/* Load the palette, if any, for the given texture into a palette slot, and make
 * it current. */
static void SetPalette( unsigned TexResource )
{
	/* If the texture isn't paletted, we have nothing to do. */
	if( g_TexResourceToTexturePalette.find(TexResource) == g_TexResourceToTexturePalette.end() )
		return;

	/* Is the palette already loaded? */
	if( g_TexResourceToPaletteIndex.find(TexResource) == g_TexResourceToPaletteIndex.end() )
	{
		/* It's not.  Grab the least recently used slot. */
		int iPalIndex = g_PaletteIndex.front();

		/* If any other texture is currently using this slot, mark that palette unloaded. */
		for( map<unsigned,int>::iterator i = g_TexResourceToPaletteIndex.begin(); i != g_TexResourceToPaletteIndex.end(); ++i )
		{
			if( i->second != iPalIndex )
				continue;
			g_TexResourceToPaletteIndex.erase(i);
			break;
		}

		/* Load it. */
#if !defined(XBOX)
		TexturePalette& pal = g_TexResourceToTexturePalette[TexResource];
		g_pd3dDevice->SetPaletteEntries( iPalIndex, pal.p );
#else
		ASSERT(0);
#endif

		g_TexResourceToPaletteIndex[TexResource] = iPalIndex;
	}
	
	const int iPalIndex = g_TexResourceToPaletteIndex[TexResource];

	/* Find this palette index in the least-recently-used queue and move it to the end. */
	for(list<int>::iterator i = g_PaletteIndex.begin(); i != g_PaletteIndex.end(); ++i)
	{
		if( *i != iPalIndex )
			continue;
		g_PaletteIndex.erase(i);
		g_PaletteIndex.push_back(iPalIndex);
		break;
	}

#if !defined(XBOX)
	g_pd3dDevice->SetCurrentTexturePalette( iPalIndex );
#else
	ASSERT(0);
#endif
}