示例#1
0
int urlCheck(char *url,char *host){
    UPU *tmp;
    if(memmem(url,strlen(url),host,strlen(host))==NULL)
	return 0;
    if(memcmp(url,"mail",4)==0)
	return 0;
    if(find(failedPool,url,strlen(url))!=NULL)
	return 0;
    if(find(URLPool,url,strlen(url))!=NULL)
	return 0;
    if(find(finishPool,url,strlen(url))!=NULL)
	return 0;
    if(CURL_typeTest(url)){
	return 1;
    }else{
	tmp=failedPool[hashfn(url)];
	if(tmp!=NULL){
	    while(tmp->next!=NULL){
		tmp=tmp->next;
	    }
	    myAdd(&(tmp->next),url,strlen(url));
	}else{
	    myAdd(&(failedPool[hashfn(url)]),url,strlen(url));
	}
	return 0;
    }
}
示例#2
0
文件: power.cpp 项目: OspreyX/acado
returnValue Power::initDerivative() {

	if( initialized ) return SUCCESSFUL_RETURN;
	initialized = BT_TRUE;

	Operator *oneTmp = new DoubleConstant(1.0, NE_ONE);
	Operator *subTmp = mySubtract( argument2, oneTmp );

	derivative01 = convert2TreeProjection(myPower( argument1, subTmp));
	derivative02 = convert2TreeProjection(myLogarithm( argument1 ));

	derivative12 = convert2TreeProjection(myProd( derivative01, argument2 ));

	Operator *twoTmp = new DoubleConstant(2.0,NE_NEITHER_ONE_NOR_ZERO);
	Operator *subTmp2 = mySubtract( argument2, twoTmp );
	Operator *prodTmp = myProd( argument2, subTmp );
	Operator *prodTmp2 = myProd( argument2, derivative02 );
	Operator *addTmp = myAdd( oneTmp, prodTmp2 );

	derivative21 = convert2TreeProjection(myPower( argument1, subTmp2));
	derivative22 = convert2TreeProjection(myProd( prodTmp, derivative21 ));
	derivative23 = convert2TreeProjection(myProd( derivative01, addTmp ));

	delete oneTmp;
	delete subTmp;
	delete twoTmp;
	delete subTmp2;
	delete prodTmp;
	delete prodTmp2;
	delete addTmp;

	argument1->initDerivative();
	return argument2->initDerivative();
}
示例#3
0
文件: power.cpp 项目: OspreyX/acado
Operator* Power::AD_forward( int dim,
                               VariableType *varType,
                               int *component,
                               Operator **seed,
                               int &nNewIS,
                               TreeProjection ***newIS ){

    if( dargument1 != 0 )
        delete dargument1;

    if( dargument2 != 0 )
    	delete dargument2;

    dargument1 = argument1->AD_forward(dim,varType,component,seed,nNewIS,newIS);
    dargument2 = argument2->AD_forward(dim,varType,component,seed,nNewIS,newIS);

	Operator *prodTmp1 = myProd( this, derivative02);
    Operator *prodTmp2 = myProd( dargument2, prodTmp1 );
    Operator *prodTmp4 = myProd( dargument1, derivative12 );

    Operator *result = myAdd( prodTmp2, prodTmp4 );

    delete prodTmp1;
    delete prodTmp2;
    delete prodTmp4;

    return result;
}
示例#4
0
int myMult(int a, int b) {
	int res = 0;
	while(b) {
		if (b & 1)
			res = myAdd(res, a);
		a <<= 1;
		b >>= 1;
	}
}
int main(){
	int k;
	scanf("%d", &k);
	stu * pre=NULL, * head = NULL;
	top3 *re = (top3*)malloc(sizeof(top3));
	re->a = re->b = re->c = NULL;
	while(k--){
		stu * t = (stu*)malloc(sizeof(stu));
		int sa, sb;
		scanf("%d %d %d", &t->id, &sa, &sb);
		t->sum = sa + sb;
		myAdd(re, t);
	}
	printf("%d %d\n", re->a->id, re->a->sum);
	printf("%d %d\n", re->b->id, re->b->sum);
	printf("%d %d\n", re->c->id, re->c->sum);
}
示例#6
0
文件: power.cpp 项目: OspreyX/acado
Operator* Power::differentiate( int index ){

	dargument1 = argument1->differentiate( index );
	dargument2 = argument2->differentiate( index );

	Operator *prodTmp1 = myProd( this, derivative02);
	Operator *prodTmp2 = myProd( dargument2, prodTmp1 );
	Operator *prodTmp4 = myProd( dargument1, derivative12 );

	Operator *result = myAdd( prodTmp2, prodTmp4 );

	delete prodTmp1;
	delete prodTmp2;
	delete prodTmp4;

	return result;

}
示例#7
0
int main(int argc,char *argv[]){
    if(argc<2)
	usage(0);
    char *sourceURL=argv[1];
    clock_t begin, end;
    int i=0;
    char *handleURL;
    int pos;
    UPU *tmp;
    URL_FILE *buf;
    char prefix[10],host[1024],path[4096],filename[4096];


    for(i=0;i<HashSize;i++){
	URLPool[i]=NULL;
	finishPool[i]=NULL;
	failedPool[i]=NULL;
    }
    memset(prefix,0,10);
    memset(host,0,1024);
    memset(path,0,4096);
    memset(filename,0,4096);
    sepURL(sourceURL,prefix,host,path,filename);
    //check/create Folder    
    folderInit(host);
    readRec(sourceURL);
    //init
    if(!logInit(host)){
	printf("log file error\n");
	exit(1);
    }
    pos=hashfn(sourceURL);
    myAdd(&URLPool[pos],sourceURL,strlen(sourceURL));
    //start loop
    begin=clock();
    i=0;
    while(getPoolSize(URLPool)!=0){
	//random get one URL Structure Pointer from URLPool
	handleURL=randGet(URLPool);
	pos=hashfn(handleURL);
	printf("run [%d] %s\n",pos,handleURL);
	memset(prefix,0,10);
	memset(host,0,1024);
	memset(path,0,4096);
	memset(filename,0,4096);
	sepURL(handleURL,prefix,host,path,filename);
	//put the url in finishPool
	tmp=finishPool[pos];
	if(tmp==NULL){
	    myAdd(&finishPool[pos],handleURL,strlen(handleURL));
	}else{
	    while(tmp->next!=NULL){
		tmp=tmp->next;
	    }
	    myAdd(&(tmp->next),handleURL,strlen(handleURL));
	}
	//start run the CURL
	if((buf=runCURL(handleURL))!=NULL){	    
	    //write to File
	    myWrite(host,filename,buf->buffer,buf->buffer_len,i++);
	    getURL(buf->buffer,buf->buffer_len,handleURL,prefix,host,path,filename);
	    printf("%d\n",getPoolSize(URLPool));
	    memset(buf->buffer,0,buf->buffer_len);
	    free(buf->buffer);
	    fflush(logfp);
	}
	else{
	    printf("no content\n");
	}
	free(buf);
    }
    logClose();
    end=clock();
    printf("finally finish: %d 's URL, cost %lf sec\n",getPoolSize(finishPool),(double)( end - begin ) / CLOCKS_PER_SEC);
    myDump(host);
    return 0;
}
示例#8
0
void getURL(char *body,int len,char *srcURL,char *prefix,char *host,char *path,char *filename){
    char *tag=" href=";
    char *buf;
    char *url_l,*url_r;
    int url_len;
    char url[4096],*realURL;
    char *delimiter="\"";
    char *delimiter2="\'";
    int dlen=strlen(delimiter);
    int pos;
    UPU *tmp;
    //preprocess
    filter(body,len);
    buf=memmem(body,len,tag,5);    
    memset(url,0,4096);
    fprintf(logfp,"do get URL from %s\n",srcURL);
    while(1){
	if(buf!=NULL){
	    
	    // left of delimiter
	    if((url_l=memmem(buf,len-(buf-body),delimiter,dlen))!=NULL){
		url_l+=dlen;
		// right of delimiter
		url_r=memmem(url_l+1,len-(url_l-body)-1,delimiter,dlen); 
		// url length
	    }else if((url_l=memmem(buf,len-(buf-body),delimiter2,dlen))!=NULL){
		url_l+=dlen;
		// right of delimiter
		url_r=memmem(url_l+1,len-(url_l-body)-1,delimiter2,dlen); 
	    }else{
		url_l=buf+6;
		url_r=memmem(url_l,len-(url_l-body),">",1);
	    }
	    // url length	
	    url_len=url_r-url_l;
	    if(url_len>0){
		memcpy(url,url_l,url_len);
		url[url_len]='\0';

		realURL=getRealURL(srcURL,url,prefix,host,path,filename);
		memset(url,0,url_len);		
		url_len=strlen(realURL);

		if(urlCheck(realURL,host)){
		    if(memmem(realURL,url_len,srcURL,strlen(srcURL)-strlen(filename))!=NULL){
			pos=hashfn(realURL);
			if((tmp=URLPool[pos])==NULL){
			    fprintf(logfp,"[add] %s\n",realURL);
			    myAdd(&(URLPool[pos]),realURL,url_len);
			}else{
			    while(tmp->next!=NULL)
				tmp=tmp->next;
			    fprintf(logfp,"[add] %s\n",realURL);
			    myAdd(&(tmp->next),realURL,url_len);
			}		    
		    }
		}
		memset(realURL,0,url_len);
		free(realURL);
	    }
	}
	else
	    break;
	buf=memmem(url_r,len-(url_r-body),tag,5);
    }
}