示例#1
0
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) 
{

	double* E = mxGetPr(prhs[0]);
	int* E_size = (int*) mxGetPr(prhs[1]);
	double* nodes = mxGetPr(prhs[2]);
	int nodes_num = mxGetScalar(prhs[3]);
	int step_threshold = mxGetScalar(prhs[4]);

	bool* trimed = (bool*) mxMalloc(nodes_num*sizeof(bool));
	bool* trimed_bak = (bool*) mxMalloc(nodes_num*sizeof(bool));
	bool* visited = (bool*) mxMalloc(nodes_num*sizeof(bool));

	for (int i = 0;i < nodes_num;i++)
	{
		trimed[i] = false;
		trimed_bak[i] = false;
		visited[i] = false;
	}

	for (int i = 0;i < nodes_num;i++)
	{
		if (visited[i]) {continue;}
		//mexPrintf("%d begin\n",i);
		int size = visit(i,E,E_size,trimed,visited);
		//if (size > 2) {mexPrintf("size:%d\n",size);}
		//mexPrintf("%d done\n",i);
		if (size >= step_threshold)
		{
			mycopy(trimed,trimed_bak,nodes_num);
		}
		else
		{
			mycopy(trimed_bak,trimed,nodes_num);
		}
	}

	int V_num = 0;

	for (int i = 0;i < nodes_num;i++)
	{
		if (trimed[i]) {V_num += 1;}
	}

	plhs[0] = mxCreateNumericMatrix(1,V_num,mxINT32_CLASS,mxREAL);
	int* V = (int*)mxGetData(plhs[0]);

	int j = 0;
	for (int i = 0;i < nodes_num;i++)
	{
		if (trimed[i])
		{
			V[j] = d2i(nodes[i]);
			j += 1;
		}
	}

	plhs[1] = mxCreateDoubleScalar(double(V_num));

}
示例#2
0
void		cDialogManager::DestroyDialog	(cDialog* pDialog) {
	if (!pDialog) return;
	mlDialogs.remove(pDialog);
	
	std::list<cWidget*> mycopy(pDialog->mlRootWidget); // use a copy of the list to avoid breakting iterator by automatic unregistering
	for (std::list<cWidget*>::iterator itor=mycopy.begin();itor!=mycopy.end();++itor) 
		pDialog->DestroyWidget(*itor); // this might trigger callbacks, must be outside dialog destructor
	
	delete pDialog;
	Reorder();
}
示例#3
0
void	cDialog::DestroyWidget			(cWidget* pWidget) {
	assert(pWidget);
	if (!pWidget || pWidget->mpDialog != this) return;
			
	// release children
	std::list<cWidget*> mycopy(pWidget->mlChild); // use a copy of the list to avoid breakting iterator by automatic unregistering
	for (std::list<cWidget*>::iterator itor=mycopy.begin();itor!=mycopy.end();++itor)
		(*itor)->Destroy();  // this might trigger callbacks, must be outside dialog destructor
		
	if (!pWidget->mpParent) mlRootWidget.remove(pWidget);
	if (pWidget->mpParent) pWidget->mpParent->DetachChild(pWidget);
	delete pWidget;
}
示例#4
0
main(){

  int c, len, maxlen=0;
  char line[100];
  char maxline[100];

  while((c=getchar())!=EOF){
    for(len=0; c!='\n'; len++){
      line[len]=c;
      c=getchar();
    }

    if(++len>maxlen){
      mycopy(line,maxline);
      maxlen=len;
    }
  }

  printf("La stringa piu` lunga e` \"%s\" di lunghezza %d.\n",maxline,maxlen);
}
int main()
{
    typedef boost::chrono::thread_clock clock_t;
    typedef boost::chrono::duration<float> dur_t;

#ifndef BOOST_GEOMETRY_INDEX_BENCHMARK_DEBUG
    size_t values_count = 1000000;
    size_t queries_count = 100000;
    size_t nearest_queries_count = 10000;
    unsigned neighbours_count = 10;
    size_t path_queries_count = 2000;
    size_t path_queries_count2 = 10000;
    unsigned path_values_count = 10;
#else
    size_t values_count = 1000;
    size_t queries_count = 1;
    size_t nearest_queries_count = 1;
    unsigned neighbours_count = 10;
    size_t path_queries_count = 1;
    size_t path_queries_count2 = 1;
    unsigned path_values_count = 10;
#endif

    float max_val = static_cast<float>(values_count / 2);
    std::vector< std::pair<float, float> > coords;
    std::vector<V> values;

    //randomize values
    {
        boost::mt19937 rng;
        //rng.seed(static_cast<unsigned int>(std::time(0)));
        boost::uniform_real<float> range(-max_val, max_val);
        boost::variate_generator<boost::mt19937&, boost::uniform_real<float> > rnd(rng, range);

        coords.reserve(values_count);

        std::cout << "randomizing data\n";
        for ( size_t i = 0 ; i < values_count ; ++i )
        {
            float x = rnd();
            float y = rnd();
            coords.push_back(std::make_pair(x, y));
            values.push_back(generate_value<V>::apply(x, y));
        }
        std::cout << "randomized\n";
    }

    typedef bgi::rtree<V, bgi::linear<16, 4> > RT;
    //typedef bgi::rtree<V, bgi::quadratic<16, 4> > RT;
    //typedef bgi::rtree<V, bgi::rstar<16, 4> > RT;

    std::cout << "sizeof rtree: " << sizeof(RT) << std::endl;

    for (;;)
    {
        std::vector<V> result;
        result.reserve(100);
        B result_one;

        // packing test
        {
            clock_t::time_point start = clock_t::now();

            RT t(values.begin(), values.end());

            dur_t time = clock_t::now() - start;
            std::cout << time << " - pack " << values_count << '\n';

            {
                clock_t::time_point start = clock_t::now();
                size_t temp = 0;
                for (size_t i = 0 ; i < queries_count ; ++i )
                {
                    float x = coords[i].first;
                    float y = coords[i].second;
                    result.clear();
                    t.query(bgi::intersects(B(P(x - 10, y - 10), P(x + 10, y + 10))), std::back_inserter(result));
                    temp += result.size();
                }
                dur_t time = clock_t::now() - start;
                std::cout << time << " - query(B) " << queries_count << " found " << temp << '\n';
            }
        }
        
        RT t;

        // inserting test
        {
            clock_t::time_point start = clock_t::now();
            t.insert(values);
            dur_t time = clock_t::now() - start;
            std::cout << time << " - insert " << values_count << '\n';
        }

        

        {
            clock_t::time_point start = clock_t::now();
            size_t temp = 0;
            for (size_t i = 0 ; i < queries_count ; ++i )
            {
                float x = coords[i].first;
                float y = coords[i].second;
                result.clear();
                t.query(bgi::intersects(B(P(x - 10, y - 10), P(x + 10, y + 10))), std::back_inserter(result));
                temp += result.size();
            }
            dur_t time = clock_t::now() - start;
            std::cout << time << " - query(B) " << queries_count << " found " << temp << '\n';
        }

#ifdef BOOST_GEOMETRY_INDEX_DETAIL_EXPERIMENTAL
        {
            clock_t::time_point start = clock_t::now();
            size_t temp = 0;
            for (size_t i = 0 ; i < queries_count ; ++i )
            {
                float x = coords[i].first;
                float y = coords[i].second;
                result.clear();
                std::copy(
                    t.qbegin(bgi::intersects(B(P(x - 10, y - 10), P(x + 10, y + 10)))),
                    t.qend(bgi::intersects(B(P(x - 10, y - 10), P(x + 10, y + 10)))),
                    std::back_inserter(result));
                temp += result.size();
            }
            dur_t time = clock_t::now() - start;
            std::cout << time << " - qbegin(B) qend(B) " << queries_count << " found " << temp << '\n';
        }
        {
            clock_t::time_point start = clock_t::now();
            size_t temp = 0;
            for (size_t i = 0 ; i < queries_count ; ++i )
            {
                float x = coords[i].first;
                float y = coords[i].second;
                result.clear();
                mycopy(
                    t.qbegin(bgi::intersects(B(P(x - 10, y - 10), P(x + 10, y + 10)))),
                    t.qend(),
                    std::back_inserter(result));
                temp += result.size();
            }
            dur_t time = clock_t::now() - start;
            std::cout << time << " - qbegin(B) qend() " << queries_count << " found " << temp << '\n';
        }
#ifdef BOOST_GEOMETRY_INDEX_DETAIL_ENABLE_TYPE_ERASED_ITERATORS
        {
            clock_t::time_point start = clock_t::now();
            size_t temp = 0;
            for (size_t i = 0 ; i < queries_count ; ++i )
            {
                float x = coords[i].first;
                float y = coords[i].second;
                result.clear();
                RT::const_query_iterator first = t.qbegin(bgi::intersects(B(P(x - 10, y - 10), P(x + 10, y + 10))));
                RT::const_query_iterator last = t.qend(bgi::intersects(B(P(x - 10, y - 10), P(x + 10, y + 10))));
                std::copy(first, last, std::back_inserter(result));
                temp += result.size();
            }
            dur_t time = clock_t::now() - start;
            std::cout << time << " - type-erased qbegin(B) qend(B) " << queries_count << " found " << temp << '\n';
        }
#endif
#endif

        {
            clock_t::time_point start = clock_t::now();
            size_t temp = 0;
            for (size_t i = 0 ; i < queries_count / 2 ; ++i )
            {
                float x1 = coords[i].first;
                float y1 = coords[i].second;
                float x2 = coords[i+1].first;
                float y2 = coords[i+1].second;
                float x3 = coords[i+2].first;
                float y3 = coords[i+2].second;
                result.clear();
                t.query(
                    bgi::intersects(B(P(x1 - 10, y1 - 10), P(x1 + 10, y1 + 10)))
                    &&
                    !bgi::within(B(P(x2 - 10, y2 - 10), P(x2 + 10, y2 + 10)))
                    &&
                    !bgi::covered_by(B(P(x3 - 10, y3 - 10), P(x3 + 10, y3 + 10)))
                    ,
                    std::back_inserter(result)
                    );
                temp += result.size();
            }
            dur_t time = clock_t::now() - start;
            std::cout << time << " - query(i && !w && !c) " << queries_count << " found " << temp << '\n';
        }

        result.clear();

        {
            clock_t::time_point start = clock_t::now();
            size_t temp = 0;
            for (size_t i = 0 ; i < nearest_queries_count ; ++i )
            {
                float x = coords[i].first + 100;
                float y = coords[i].second + 100;
                result.clear();
                temp += t.query(bgi::nearest(P(x, y), neighbours_count), std::back_inserter(result));
            }
            dur_t time = clock_t::now() - start;
            std::cout << time << " - query(nearest(P, " << neighbours_count << ")) " << nearest_queries_count << " found " << temp << '\n';
        }

#ifdef BOOST_GEOMETRY_INDEX_DETAIL_EXPERIMENTAL
        {
            clock_t::time_point start = clock_t::now();
            size_t temp = 0;
            for (size_t i = 0 ; i < nearest_queries_count ; ++i )
            {
                float x = coords[i].first + 100;
                float y = coords[i].second + 100;
                result.clear();
                std::copy(
                    t.qbegin(bgi::nearest(P(x, y), neighbours_count)),
                    t.qend(bgi::nearest(P(x, y), neighbours_count)),
                    std::back_inserter(result));
                temp += result.size();
            }
            dur_t time = clock_t::now() - start;
            std::cout << time << " - qbegin(nearest(P, " << neighbours_count << ")) qend(n) " << nearest_queries_count << " found " << temp << '\n';
        }
        {
            clock_t::time_point start = clock_t::now();
            size_t temp = 0;
            for (size_t i = 0 ; i < nearest_queries_count ; ++i )
            {
                float x = coords[i].first + 100;
                float y = coords[i].second + 100;
                result.clear();
                mycopy(
                    t.qbegin(bgi::nearest(P(x, y), neighbours_count)),
                    t.qend(),
                    std::back_inserter(result));
                temp += result.size();
            }
            dur_t time = clock_t::now() - start;
            std::cout << time << " - qbegin(nearest(P, " << neighbours_count << ")) qend() " << nearest_queries_count << " found " << temp << '\n';
        }
#ifdef BOOST_GEOMETRY_INDEX_DETAIL_ENABLE_TYPE_ERASED_ITERATORS
        {
            clock_t::time_point start = clock_t::now();
            size_t temp = 0;
            for (size_t i = 0 ; i < nearest_queries_count ; ++i )
            {
                float x = coords[i].first;
                float y = coords[i].second;
                result.clear();
                RT::const_query_iterator first = t.qbegin(bgi::nearest(P(x, y), neighbours_count));
                RT::const_query_iterator last = t.qend(bgi::nearest(P(x, y), neighbours_count));
                std::copy(first, last, std::back_inserter(result));
                temp += result.size();
            }
            dur_t time = clock_t::now() - start;
            std::cout << time << " - type-erased qbegin(nearest(P, " << neighbours_count << ")) qend(n) " << nearest_queries_count << " found " << temp << '\n';
        }
#endif

        {
            LS ls;
            ls.resize(6);
            
            clock_t::time_point start = clock_t::now();
            size_t temp = 0;
            for (size_t i = 0 ; i < path_queries_count ; ++i )
            {
                float x = coords[i].first;
                float y = coords[i].second;
                for ( int i = 0 ; i < 3 ; ++i )
                {
                    float foo = i*max_val/300;
                    ls[2*i] = P(x, y+foo);
                    ls[2*i+1] = P(x+max_val/100, y+foo);
                }                
                result.clear();
                t.query(bgi::path(ls, path_values_count), std::back_inserter(result));
                temp += result.size();
            }
            dur_t time = clock_t::now() - start;
            std::cout << time << " - query(path(LS6, " << path_values_count << ")) " << path_queries_count << " found " << temp << '\n';
        }

        {
            LS ls;
            ls.resize(2);

            clock_t::time_point start = clock_t::now();
            size_t temp = 0;
            for (size_t i = 0 ; i < path_queries_count2 ; ++i )
            {
                float x = coords[i].first;
                float y = coords[i].second;
                ls[0] = P(x, y);
                ls[1] = P(x+max_val/100, y+max_val/100);
                result.clear();
                t.query(bgi::path(ls, path_values_count), std::back_inserter(result));
                temp += result.size();
            }
            dur_t time = clock_t::now() - start;
            std::cout << time << " - query(path(LS2, " << path_values_count << ")) " << path_queries_count2 << " found " << temp << '\n';
        }

        {
            clock_t::time_point start = clock_t::now();
            size_t temp = 0;
            for (size_t i = 0 ; i < path_queries_count2 ; ++i )
            {
                float x = coords[i].first;
                float y = coords[i].second;
                S seg(P(x, y), P(x+max_val/100, y+max_val/100));
                result.clear();
                t.query(bgi::path(seg, path_values_count), std::back_inserter(result));
                temp += result.size();
            }
            dur_t time = clock_t::now() - start;
            std::cout << time << " - query(path(S, " << path_values_count << ")) " << path_queries_count2 << " found " << temp << '\n';
        }
#endif
        {
            clock_t::time_point start = clock_t::now();
            for (size_t i = 0 ; i < values_count / 10 ; ++i )
            {
                float x = coords[i].first;
                float y = coords[i].second;
                
                t.remove(generate_value<V>::apply(x, y));
            }
            dur_t time = clock_t::now() - start;
            std::cout << time << " - remove " << values_count / 10 << '\n';
        }

        std::cout << "------------------------------------------------\n";
    }

    return 0;
}
示例#6
0
static void setids(int mode,uid_t owner,gid_t group)
{
    register int n,m;
    int pv[2];

    /*
     * Create a token to pass to the new program for validation.
     * This token can only be procured by someone running with an
     * effective userid of root, and hence gives the clone a way to
     * certify that it was really invoked by THISPROG.  Someone who
     * is already root could spoof us, but why would they want to?
     *
     * Since we are root here, we must be careful:  What if someone
     * linked a valuable file to tmpname?
     */
    unlink(tmpname);	/* should normally fail */
#ifdef O_EXCL
    if((n = open(tmpname, O_WRONLY | O_CREAT | O_EXCL, SPECIAL)) < 0 ||
            unlink(tmpname) < 0)
#else
    if((n = open(tmpname, O_WRONLY | O_CREAT ,SPECIAL)) < 0 || unlink(tmpname) < 0)
#endif
        error_exit(badexec);
    if(n != FDVERIFY)
    {
        close(FDVERIFY);
        if(fcntl(n,F_DUPFD,FDVERIFY) != FDVERIFY)
            error_exit(badexec);
    }
    mode |= S_IEXEC|(S_IEXEC>>3)|(S_IEXEC>>6);
    /* create a pipe for synchronization */
    if(pipe(pv) < 0)
        error_exit(badexec);
    if((n=fork()) == 0)
    {   /* child */
        close(FDVERIFY);
        close(pv[1]);
        if((n=fork()) == 0)
        {   /* grandchild -- cleans up clone file */
            signal(SIGHUP, SIG_IGN);
            signal(SIGINT, SIG_IGN);
            signal(SIGQUIT, SIG_IGN);
            signal(SIGTERM, SIG_IGN);
            read(pv[0],pv,1); /* wait for clone to close pipe */
            while(unlink(tmpname) < 0 && errno == ETXTBSY)
                sleep(1);
            exit(0);
        }
        else if(n == -1)
            exit(1);
        else
        {
            /* Create a set[ug]id file that will become the clone.
             * To make this atomic, without need for chown(), the
             * child takes on desired user and group.  The only
             * downsize of this that I can see is that it may
             * screw up some per- * user accounting.
             */
            if((m = open(THISPROG, O_RDONLY)) < 0)
                exit(1);
            if((mode & S_ISGID) && setgid(group) < 0)
                exit(1);
            if((mode & S_ISUID) && owner && setuid(owner) < 0)
                exit(1);
#ifdef O_EXCL
            if((n = open(tmpname,O_WRONLY|O_CREAT|O_TRUNC|O_EXCL, mode)) < 0)
#else
            unlink(tmpname);
            if((n = open(tmpname,O_WRONLY|O_CREAT|O_TRUNC, mode)) < 0)
#endif /* O_EXCL */
                exit(1);
            /* populate the clone */
            m = mycopy(m,n);
            if(chmod(tmpname,mode) <0)
                exit(1);
            exit(m);
        }
    }
    else if(n == -1)
        error_exit(badexec);
    else
    {
        arglist[0] = (char*)tmpname;
        close(pv[0]);
        /* move write end of pipe into FDSYNC */
        if(pv[1] != FDSYNC)
        {
            close(FDSYNC);
            if(fcntl(pv[1],F_DUPFD,FDSYNC) != FDSYNC)
                error_exit(badexec);
        }
        /* wait for child to die */
        while((m = wait(0)) != n)
            if(m == -1 && errno != EINTR)
                break;
        /* Kill any setuid status at this point.  That way, if the
         * clone is not setuid, we won't exec it as root.  Also, don't
         * neglect to consider that someone could have switched the
         * clone file on us.
         */
        if(setuid(ruserid) < 0)
            error_exit(badexec);
        execv(tmpname,arglist);
        error_exit(badexec);
    }
}