Exemple #1
0
void check_field(coord x, coord y){
	int res=0;
	//printf("check field\n");
	res+=search_cell(x,y+1);
	res+=search_cell(x,y-1);
	res+=search_cell(x+1,y);
	res+=search_cell(x+1,y+1);
	res+=search_cell(x+1,y-1);
	res+=search_cell(x-1,y);
	res+=search_cell(x-1,y-1);
	res+=search_cell(x-1,y+1);

	if( search_cell(x,y) && (res<2 || res>3) ){
		cell_q_size++;
		//mrealloc(cell_q,queue,cell_q_size);
		cell_q[cell_q_size-1].x=x;
		cell_q[cell_q_size-1].y=y;
		cell_q[cell_q_size-1].alive=0;
		return;
	}
	if( !(search_cell(x,y)) && res==3 ){
		cell_q_size++;
		//mrealloc(cell_q,queue,cell_q_size);
		cell_q[cell_q_size-1].x=x;
		cell_q[cell_q_size-1].y=y;
		cell_q[cell_q_size-1].alive=1;
	}
}
Exemple #2
0
 const V *get(const K &key)
 {
     b_tree_cell *r = search_cell(root, key);
     if (r == nullptr)
         return nullptr;
     return &(r->value);
 }
Exemple #3
0
void check_field(coord x, coord y){
	int res=0;
	//printf("check field\n");
	res+=search_cell(x,y+1);
	res+=search_cell(x,y-1);
	res+=search_cell(x+1,y);
	res+=search_cell(x+1,y+1);
	res+=search_cell(x+1,y-1);
	res+=search_cell(x-1,y);
	res+=search_cell(x-1,y-1);
	res+=search_cell(x-1,y+1);

	if( search_cell(x,y) && (res<2 || res>3) ){
		max_q++;
		q=(que*)realloc(q,max_q*sizeof(que));
		if(q==NULL){
			fprintf(stderr,"MEM ERR q\n");
			exit(1);	
		}
		q[max_q-1].x=x;
		q[max_q-1].y=y;
		q[max_q-1].alive=0;
		return;
	}
	if( !search_cell(x,y) && res==3 ){
		max_q++;
		q=(que*)realloc(q,max_q*sizeof(que));
		if(q==NULL){
			fprintf(stderr,"MEM ERR q\n");
			exit(1);	
		}
		q[max_q-1].x=x;
		q[max_q-1].y=y;
		q[max_q-1].alive=1;
		return;
	}
}
Exemple #4
0
void print_field(){
	coord x,y;
	int i;
	for(i=0;i<FIELD_VIS;i++)
		printf("-");
	printf("\n");
	for(y=-FIELD_VIS/2;y<FIELD_VIS/2;y++){
		for(x=-FIELD_VIS/2;x<FIELD_VIS/2;x++)
			if(search_cell(x,y)==1)
				printf("*");
			else 
				printf(" ");
		printf("\n");
	}
	for(i=0;i<FIELD_VIS;i++)
		printf("-");
	printf("\n");
}
Exemple #5
0
/* thread routine of each connection. thread reads request 
 * from client and if the request is cached, write the cached 
 * content to client; if the request is not cached, it passes
 * the request to server, reads response from server and passes
 * response to client. */
void *thread(void *vargp)
{
	int clientfd;
	struct client_request *request;
	struct cache_cell *cell;

	Pthread_detach(pthread_self());
	clientfd = (int)(long)vargp;
	
	request = allocate_request();
	parse_request_h(request, clientfd);
	
	/* handle hit case */
	if ((cell = search_cell(request->request_line)) != NULL)
		hit_handler(clientfd, cell, request);
	/* handle miss case */
	else
		miss_handler(clientfd, request);
	return NULL;
}
Exemple #6
0
 bool has(const K &key)
 {
     return search_cell(root, key) != nullptr;
 }
Exemple #7
0
void add_cell(coord in_x, coord in_y){	
	//if list_struct is empty
	if(search_cell(in_x,in_y))
		return;
	live_cells++;
	birth++;
	cell_list *pr; //save pointer to previous cell;
	int h=hash(in_x,in_y);
	if(ht[h].head==0){
		ht[h].head=(cell_list *)malloc(sizeof(cell_list));
		if(ht[h].head==NULL){
			printf("cell_list err mem\n");
			exit(1);
		}
		ht[h].head->x=in_x;
		ht[h].head->y=in_y;
		ht[h].head->next=NULL;
		return;
	}
	tmp=ht[h].head;
	while(tmp && tmp->x < in_x ){
		pr=tmp;
		tmp=tmp->next;
	}
	if(tmp && tmp->x==in_x){
		while(tmp && tmp->y<in_y){
			pr=tmp;
			tmp=tmp->next;
		}
		p=(cell_list *)malloc(sizeof(cell_list));
		if(p==NULL){
			printf("cell_list err mem\n");
			exit(1);
		}
		if(!tmp){
			p->next=tmp;
			pr->next=p;		
			p->x=in_x;
			p->y=in_y;
			return;
		}
		p->next=tmp->next;
		p->x=in_x;
		p->y=in_y;
		tmp->next=p;
	       	return;	
		//insert
	}
	p=(cell_list *)malloc(sizeof(cell_list));
	if(p==NULL){
		printf("cell_list err mem\n");
		exit(1);
	}
	if(!tmp){
		p->next=tmp;
		pr->next=p;		
		p->x=in_x;
		p->y=in_y;
		return;
	}
	int tmp_x=tmp->x;
	//if x>in_x
	while(tmp && tmp->x==tmp_x && tmp->y<in_y){
			pr=tmp;
			tmp=tmp->next;
	}
	if(!tmp){
		p->next=tmp;
		pr->next=p;		
		p->x=in_x;
		p->y=in_y;
		return;
	}
	p->next=tmp->next;
	p->x=in_x;
	p->y=in_y;
	tmp->next=p; 
}
Exemple #8
0
void add_cell(coord in_x, coord in_y){	
	if(search_cell(in_x,in_y))
		return;
	trace(4,"add_cell x=%d, y=%d\n",in_x,in_y);
	cell *pr=head;
	live_cells++;
	birth++;
	int h=hash(in_x,in_y);
	if(hash_t[h].head==0){
		hash_t[h].head=alloc_mem();
		hash_t[h].head->x=in_x;
		hash_t[h].head->y=in_y;
		hash_t[h].head->next=NULL;
		return;
	}
	tmp=hash_t[h].head;
	while(tmp && tmp->x < in_x ){
		pr=tmp;
		tmp=tmp->next;
	}
	if(tmp && tmp->x==in_x){
		while(tmp && tmp->y<in_y){
			pr=tmp;
			tmp=tmp->next;
		}
		p=alloc_mem();
		if(!tmp){
			p->next=tmp;
			pr->next=p;		
			p->x=in_x;
			p->y=in_y;
			return;
		}
		p->next=tmp->next;
		p->x=in_x;
		p->y=in_y;
		tmp->next=p;
	       	return;	
	}
	p=alloc_mem();
	if(!tmp){
		p->next=tmp;
		pr->next=p;		
		p->x=in_x;
		p->y=in_y;
		return;
	}
	int tmp_x=tmp->x;
	//if x>in_x
	while(tmp && tmp->x==tmp_x && tmp->y<in_y){
			pr=tmp;
			tmp=tmp->next;
	}
	if(!tmp){
		p->next=tmp;
		pr->next=p;		
		p->x=in_x;
		p->y=in_y;
		return;
	}
	p->next=tmp->next;
	p->x=in_x;
	p->y=in_y;
	tmp->next=p; 
}