Exemple #1
0
//
// Function:	shrink()
// 
// Purpose:		Uniformly shrinks this member func around it's center
//
// Arguments:
//
//		int x_delta - how much to shrink the member func by		
//
// Returns:
//
//		void
//
// Author:	Michael Zarozinski
// Date:	9/99
// 
// Modification History
// Author	Date		Modification
// ------	----		------------
//
//
void MemberFuncTri::shrink(int x_delta )
{
	int delta = abs(x_delta);

	move_node(0, nodes[0].x + delta, nodes[0].y);
	move_node(2, nodes[2].x - delta, nodes[2].y);
 
} // end MemberFuncTri::shrink()
Exemple #2
0
/* Push nodes from source to aRef and bRef alternatively */
void alternating_split(struct node* source, struct node** aRef, struct node** bRef)
{
	*aRef = NULL;
	*bRef = NULL;
	while(source!=NULL)
	{
		move_node(aRef, &source);
		if(source!=NULL)
			move_node(bRef, &source);
	}
}
Exemple #3
0
struct node *sort_merge(struct node *list1, struct node *list2)
{
	struct node *result;
	struct node **result_ref = &result;
	while (1) {
		if (list1 == NULL) {
			*result_ref = list2;
			break;
		}
		if (list2 == NULL) {
			*result_ref = list1;
			break;
		}
		if (list1->data < list2->data) {
			move_node(result_ref, &list1);
		} else {
			move_node(result_ref, &list2);
		}
		result_ref = &((*result_ref)->next);
	}
	return result;
}
Exemple #4
0
/*
Merge the nodes of the two lists into a single list taking a node
alternately from each list, and return the new list.
*/
struct node* shuffle_merge(struct node* plista, struct node* plistb)
{
    struct node* phead = NULL;
    struct node** ref_plast = &phead;
    while(plista != NULL || plistb != NULL) {
        if(plista != NULL) {
            move_node(ref_plast, &plista);
            ref_plast = &((*ref_plast)->next);
        } else {
            *ref_plast = plistb;
            break;
        }
        if(plistb != NULL) {
            move_node(ref_plast, &plistb);
            ref_plast = &((*ref_plast)->next);
        } else {
            *ref_plast = plista;
            break;
        }
    }
    return phead;
}
Exemple #5
0
//
// Function:	move()
// 
// Purpose:		Moves ALL the nodes for the member func by the delta passed in.
//
// Arguments:
//
//		int x_delta - how many 'x' elements (in the values[] array) to move each node by 
//
// Returns:
//
//		void
//
// Author:	Michael Zarozinski
// Date:	7/99
// 
// Modification History
// Author	Date		Modification
// ------	----		------------
//
//
void MemberFuncBase::move(int x_delta) 
{

	if (x_delta == 0)
		return; // nothing to do!

	// move all the nodes... 

	// we need to be careful about the order we move them in.
	// if they are being move to the right (positive offset) we need to
	// move the last point and work our way to the first point so we don't
	// cross any points if the offset is large.
	// likewize if we're moving to the left (negative offset) move them in
	// order (first to last)

	int start, end, increment;	// values that determine how we loop
 	int node_count = get_node_count();

	if (x_delta < 0)
		{
		// moving to the left
		start = 0;
		end = node_count;
		increment = 1;

		// adjust the delta so we don't "collapse" the term
		
		if (nodes[0].x + x_delta < 0)
			x_delta = -nodes[0].x;

		} // end if offset negative
	else
		{
		// offset is positive
		start = node_count - 1;
		end = -1;
		increment = -1;
		if (nodes[node_count - 1].x + x_delta > FuzzyVariableBase::get_x_array_max_idx())
			x_delta = ( FuzzyVariableBase::get_x_array_max_idx()) - nodes[node_count - 1].x;

		} // end if offset positive

	// now move them all (note the 'y' direction is invariant when moving all nodes at once)

	for (int i = start; i != end; i += increment)
		{
  		move_node(i, nodes[i].x + x_delta, nodes[i].y );

		} // end loop through nodes

} // end MemberFuncBase::move()
Exemple #6
0
int main()
{   
    struct node *plista = create_list();
    struct node *plistb = create_list();
    print(plista);
    print(plistb);
    move_node(&plista, &plistb);
    printf("after move_head:\n");
    print(plista);
    print(plistb);

    printf("\n");
    return 0;
}
Exemple #7
0
struct node* sorted_merge(struct node* a, struct node* b)
{
	struct node* returned = NULL;
	if(a==NULL && b==NULL)
		return NULL;
	else if(a!=NULL && b==NULL)
	{
		returned = sorted_merge(a->next, NULL);
		move_node(&returned, &a);
	}
	else if(a==NULL && b!=NULL)
	{
		returned = sorted_merge(NULL, b->next);
		move_node(&returned, &b);
	}
	else if(a!=NULL && b!=NULL)
	{
		if(b->data <= a->data)
		{
			returned = sorted_merge(a, b->next);
			b->next == NULL;
			move_node(&returned,&b);
			//a->next == NULL;
			//move_node(&returned,&a);
		}
		else
		{
			returned = sorted_merge(a->next, b);
			a->next == NULL;
			move_node(&returned,&a);
			//b->next == NULL;
			//move_node(&returned,&b);
		}
	}
	return returned;
}
Exemple #8
0
Fichier : dary.c Projet : tkng/dary
/* This function does no error check. You must check and ensure this function
   must not fail before calling. */
static void
move_conflicts_real(dary *da, const int *conflicts, int move_to)
{
   int i = 0;
   int offsets[257];
   int parent_index = get_parent_index(da, conflicts[0]);

   calc_offsets(conflicts, offsets);

   da->base[parent_index] = move_to - (conflicts[0] - da->base[parent_index]);

   for (i = 0; conflicts[i] != -1; i++) {
      move_node(da, conflicts[i], move_to + offsets[i]);
   }
   //  dary_dump(da);
}
Exemple #9
0
void main()
{
	struct node* head = BuildOneTwoThree();
	print_list(head);
//	int count = Count(head, 2);
//	int count = get_nth(head, 0);
//	printf("Count is: %d\n", count);
//	delete_list(&head);
//	print_list(head);
//	int i = 0;
//	int length = list_length(head);
/*	for(i = 0; i<length; i++)
	{
		int c = pop(&head);
		printf("%d\t", c);
	}
	printf("\n");
*/
//	insert_nth(&head,0,10);
//	print_list(head);
#ifdef SORTED_INSERT
	struct node* new_node1 = (struct node*) malloc(sizeof(struct node));
	new_node1->data = 13;
	sorted_insert(&head, new_node1);
	print_list(head);
	struct node* new_node2 = (struct node*) malloc(sizeof(struct node));
	new_node2->data = 0;
	sorted_insert(&head, new_node2);
	print_list(head);
	struct node* new_node3 = (struct node*) malloc(sizeof(struct node));
	new_node3->data = 8;
	sorted_insert(&head, new_node3);
	print_list(head);
	struct node* new_node4 = (struct node*) malloc(sizeof(struct node));
	new_node4->data = 4;
	sorted_insert(&head, new_node4);
	print_list(head);
	struct node* new_node5 = (struct node*) malloc(sizeof(struct node));
	new_node5->data = 30;
	sorted_insert(&head, new_node5);
	print_list(head);
#endif

#ifdef INSERT_SORT
	insert_nth(&head,0,10);
	insert_nth(&head,1,20);
	insert_nth(&head,3,14);
	insert_nth(&head,4,78);
	insert_nth(&head,1,32);
	insert_nth(&head,3,42);
	print_list(head);
	insert_sort(&head);
	print_list(head);
#endif

#ifdef APPEND	
	struct node* head1 = BuildOneTwoThree();
	insert_nth(&head1,0,10);
	print_list(head1);
	append(&head,&head1);
	print_list(head);
	print_list(head1);
#endif

#ifdef SPLIT_FRONT_BACK
	struct node* new_node5 = (struct node*) malloc(sizeof(struct node));
	new_node5->data = 30;
	sorted_insert(&head, new_node5);
	struct node* new_node6 = (struct node*) malloc(sizeof(struct node));
	new_node6->data = 10;
	sorted_insert(&head, new_node6);

	struct node* head1 = NULL;
	struct node* head2=NULL;
	front_back_split(head, &head1, &head2);
	print_list(head1);
	print_list(head2);
#endif
#ifdef REMOVE_DUPLICATES
	struct node* new_node5 = (struct node*) malloc(sizeof(struct node));
	new_node5->data = 2;
	sorted_insert(&head, new_node5);
	struct node* new_node6 = (struct node*) malloc(sizeof(struct node));
	new_node6->data = 1;
	sorted_insert(&head, new_node6);
	print_list(head1);
	remove_duplicates(head1);
	print_list(head1);
#endif

#ifdef MOV_NODE
	struct node* a = BuildOneTwoThree();
	struct node* b = BuildOneTwoThree();
	print_list(a);
	print_list(b);

	move_node(&a,&b);
	print_list(a);
	print_list(b);
#endif

#ifdef ALTERNATING_SPLIT
	struct node* a = NULL;
	struct node* b = NULL;
	alternating_split(head, &a, &b);
	print_list(a);
	print_list(b);
#endif

#ifdef SHUFFLE_MERGE
	struct node* a = BuildOneTwoThree();
	struct node* b = BuildOneTwoThree();
	print_list(a);
	print_list(b);
	struct node* c = shuffle_merge(a,b);
	print_list(c);
#endif

#ifdef SORTED_MERGE
	struct node* a = BuildOneTwoThree();
	struct node* b = BuildOneTwoThree();
	struct node* new_node1 = (struct node*) malloc(sizeof(struct node));
	new_node1->data = 13;
	sorted_insert(&a, new_node1);
	struct node* new_node2 = (struct node*) malloc(sizeof(struct node));
	new_node2->data = 0;
	sorted_insert(&b, new_node2);
	struct node* new_node3 = (struct node*) malloc(sizeof(struct node));
	new_node3->data = 8;
	sorted_insert(&a, new_node3);
	struct node* new_node4 = (struct node*) malloc(sizeof(struct node));
	new_node4->data = 4;
	sorted_insert(&a, new_node4);
	struct node* new_node5 = (struct node*) malloc(sizeof(struct node));
	new_node5->data = 30;
	sorted_insert(&b, new_node5);
	print_list(a);
	print_list(b);
	struct node* c = sorted_merge(a,b);
	print_list(c);
#endif

#ifdef MERGE_SORT
	insert_nth(&head,0,10);
	insert_nth(&head,1,20);
	insert_nth(&head,3,14);
	insert_nth(&head,4,78);
	insert_nth(&head,1,32);
	insert_nth(&head,3,42);
	print_list(head);
	merge_sort(&head);
//	print_list(head);
#endif
	insert_nth(&head,0,10);
	insert_nth(&head,1,20);
	insert_nth(&head,3,14);
	insert_nth(&head,4,78);
	insert_nth(&head,1,32);
	insert_nth(&head,3,42);
	print_list(head);
	reverse(&head);
	print_list(head);

}
Exemple #10
0
EdgeWeight two_way_fm::perform_refinement(PartitionConfig & cfg, 
                                          graph_access& G, 
                                          complete_boundary & boundary,
                                          std::vector<NodeID> & lhs_start_nodes, 
                                          std::vector<NodeID> & rhs_start_nodes, 
                                          boundary_pair * pair,        
                                          NodeWeight & lhs_part_weight,
                                          NodeWeight & rhs_part_weight,
                                          EdgeWeight & cut,
                                          bool & something_changed) {

        PartitionConfig config = cfg;//copy it since we make changes on that 
        if(lhs_start_nodes.size() == 0 or rhs_start_nodes.size() == 0) return 0; // nothing to refine

        quality_metrics qm;
        ASSERT_NEQ(pair->lhs, pair->rhs);
        ASSERT_TRUE(assert_directed_boundary_condition(G, boundary, pair->lhs, pair->rhs));
        ASSERT_EQ( cut, qm.edge_cut(G, pair->lhs, pair->rhs));

        refinement_pq* lhs_queue = NULL;
        refinement_pq* rhs_queue = NULL;
        if(config.use_bucket_queues) {
                EdgeWeight max_degree = G.getMaxDegree();
                lhs_queue = new bucket_pq(max_degree); 
                rhs_queue = new bucket_pq(max_degree); 
        } else {
                lhs_queue = new maxNodeHeap(); 
                rhs_queue = new maxNodeHeap(); 
        }

        init_queue_with_boundary(config, G, lhs_start_nodes, lhs_queue, pair->lhs, pair->rhs);  
        init_queue_with_boundary(config, G, rhs_start_nodes, rhs_queue, pair->rhs, pair->lhs);  

        queue_selection_strategy* topgain_queue_select = new queue_selection_topgain(config);
        queue_selection_strategy* diffusion_queue_select = new queue_selection_diffusion(config);
        queue_selection_strategy* diffusion_queue_select_block_target = new queue_selection_diffusion_block_targets(config);
        
        vertex_moved_hashtable moved_idx; 

        std::vector<NodeID> transpositions;

        EdgeWeight inital_cut   = cut;
        int max_number_of_swaps = (int)(boundary.getBlockNoNodes(pair->lhs) + boundary.getBlockNoNodes(pair->rhs));
        int step_limit          = (int)((config.fm_search_limit/100.0)*max_number_of_swaps);
        step_limit              = std::max(step_limit, 15);
        int min_cut_index       = -1;

        refinement_pq* from_queue       = 0;
        refinement_pq* to_queue         = 0;

        PartitionID from                = 0; 
        PartitionID to                  = 0;

        NodeWeight * from_part_weight   = 0;
        NodeWeight * to_part_weight     = 0;

        stop_rule* st_rule                      = new easy_stop_rule();
        partition_accept_rule* accept_partition = NULL;
        if(config.initial_bipartitioning) {
                accept_partition = new ip_partition_accept_rule(config, cut,lhs_part_weight, rhs_part_weight, pair->lhs, pair->rhs);
        } else {
                accept_partition = new normal_partition_accept_rule(config, cut,lhs_part_weight, rhs_part_weight);
        }
        queue_selection_strategy* q_select;

        if(config.softrebalance || config.rebalance || config.initial_bipartitioning) { 
                if(config.initial_bipartitioning) {
                        q_select = diffusion_queue_select_block_target;
                } else {
                        q_select = diffusion_queue_select;
                }
        } else {
                q_select = topgain_queue_select;
        }

        //roll forwards
        EdgeWeight best_cut = cut; 
        int number_of_swaps = 0;
        for(number_of_swaps = 0; number_of_swaps < max_number_of_swaps; number_of_swaps++) {
                if(st_rule->search_should_stop(min_cut_index, number_of_swaps, step_limit)) break;

                if(lhs_queue->empty() && rhs_queue->empty()) { 
                        break; 
                }

                q_select->selectQueue(lhs_part_weight, rhs_part_weight, 
                                pair->lhs, pair->rhs,
                                from,to, 
                                lhs_queue, rhs_queue,
                                &from_queue, &to_queue);

                if(!from_queue->empty()) {
                        Gain gain = from_queue->maxValue();
                        NodeID node = from_queue->deleteMax();

                        ASSERT_TRUE(moved_idx[node].index == NOT_MOVED);

                        boundary.setBlockNoNodes(from, boundary.getBlockNoNodes(from)-1);
                        boundary.setBlockNoNodes(to, boundary.getBlockNoNodes(to)+1);

                        if(from == pair->lhs) {
                                from_part_weight = &lhs_part_weight;         
                                to_part_weight   = &rhs_part_weight;         
                        } else {
                                from_part_weight = &rhs_part_weight;         
                                to_part_weight   = &lhs_part_weight; 
                        }

                        move_node(config, G, node, moved_idx, 
                                        from_queue, to_queue, 
                                        from, to,
                                        pair,
                                        from_part_weight, to_part_weight,
                                        boundary);

                        cut -= gain;

                        if( accept_partition->accept_partition(config, cut, lhs_part_weight, rhs_part_weight, pair->lhs, pair->rhs, config.rebalance)) {
                                ASSERT_TRUE( cut <= best_cut || config.rebalance);
                                if( cut < best_cut ) {
                                        something_changed = true;
                                }
                                best_cut = cut;
                                min_cut_index = number_of_swaps;
                        }

                        transpositions.push_back(node);
                        moved_idx[node].index = MOVED;
                } else {
                        break;
                }

        }

        ASSERT_TRUE(assert_directed_boundary_condition(G, boundary, pair->lhs, pair->rhs)); 
        ASSERT_EQ( cut, qm.edge_cut(G, pair->lhs, pair->rhs));
        
        //roll backwards
        for(number_of_swaps--; number_of_swaps > min_cut_index; number_of_swaps--) {
                ASSERT_TRUE(transpositions.size() > 0);

                NodeID node = transpositions.back();
                transpositions.pop_back();

                PartitionID nodes_partition = G.getPartitionIndex(node);

                if(nodes_partition == pair->lhs) {
                        from_queue       = lhs_queue;
                        to_queue         = rhs_queue;
                        from             = pair->lhs;
                        to               = pair->rhs;
                        from_part_weight = &lhs_part_weight;
                        to_part_weight   = &rhs_part_weight;
                } else {
                        from_queue       = rhs_queue;
                        to_queue         = lhs_queue;
                        from             = pair->rhs;
                        to               = pair->lhs;
                        from_part_weight = &rhs_part_weight;
                        to_part_weight   = &lhs_part_weight;

                }

                boundary.setBlockNoNodes(from, boundary.getBlockNoNodes(from)-1);
                boundary.setBlockNoNodes(to, boundary.getBlockNoNodes(to)+1);

                move_node_back(config, G, node, moved_idx, 
                                from_queue, to_queue, 
                                from, to,
                                pair,
                                from_part_weight, 
                                to_part_weight,
                                boundary);
        }

        //clean up
        cut = best_cut;

        boundary.setEdgeCut(pair, best_cut);
        boundary.setBlockWeight(pair->lhs, lhs_part_weight);
        boundary.setBlockWeight(pair->rhs, rhs_part_weight);

        delete lhs_queue;
        delete rhs_queue;
        delete topgain_queue_select;
        delete diffusion_queue_select;
        delete diffusion_queue_select_block_target;
        delete st_rule;
        delete accept_partition;

        ASSERT_EQ( cut, qm.edge_cut(G, pair->lhs, pair->rhs));
        ASSERT_TRUE(assert_directed_boundary_condition(G, boundary, pair->lhs, pair->rhs)); 
        ASSERT_TRUE(  (int)inital_cut-(int)best_cut >= 0 || cfg.rebalance); 
        // the computed partition shouldnt have a edge cut which is worse than the initial one
        return inital_cut-best_cut;
}
Exemple #11
0
void MemberFuncBase::move_node(int idx, _point pt) 
{
	move_node(idx, pt.x, pt.y);	
};
Exemple #12
0
void my_callback(u_char *useless,const struct pcap_pkthdr* pkthdr,const u_char*
        packet)
{
	packet_num++;
	packet_len+=pkthdr->caplen;

    	static   int count = 0;
	//static int nn=0;
	static int i;
	static unsigned short eth_type;
	static int vlan_flag=0;
		//sem_getvalue(&shmp[i]->sem,&semnum);
		//printf("sem:%d\n",semnum);		
	//usleep(1000);
	static int semnum;
//	sem_getvalue(&bin_sem,&semnum);
	//	printf("sem:%d\n",semnum);
		//printf("mmmmmmmmmmmmmm\n");
		if(exitflag)
		{
			/*for(i=0;i<snortnum;++i)
			{
				memcpy(shmp[i]->data[shmp[i]->tail],"########",strlen("########"));
				shmp[i]->tail=(shmp[i]->tail+1)%shmp[i]->looplen;
				my_lock_release(shmp[i]);
			}
		
				sleep(4);

			for(i=0;i<snortnum;++i)
			{
				destroy_loop(shmp[i]);
				DeleteShm(shmid[i]);
			}*/
			for(i=0;i<PRO_MAX+2;++i)
			{
	
				printf("%s:%lld\n",pro_map[i],pronum[i]);
		  	 }
		   	printf("losepacket=%lld\n",losepacket);
			//sem_post(&bin_sem);
			 NS_TIME_END(time);
	
			speed1(NS_GET_TIMEP(time),packet_num,packet_len);

			printf("count=%d,\nfind_pro=%lld\n",count,find_pro);
	
				printf("exit\n");
			del_HB(&hb);
		
			acsmFree (acsm);
		//	exitflag=0;
			exit(0);
		} 
//return;
		 mac=(struct ether_header*)packet;
		 eth_type=ntohs(mac->ether_type);
		
		 if((eth_type==0x8100))
		 {
		 	vlan_flag=1;
		 	//msg("W:****0X%04X\n",eth_type);
		 	eth_type=(packet[16])*256+packet[17];
		 }
		 else
		 	vlan_flag=0;
		
		// msg("W:0X%04X\n",eth_type);
		 if((eth_type!=0x0800))//不是ip数据报
		       	return;
		 if(vlan_flag)
		 	ip=(struct ip*)(packet+size_mac+4);
	 	 else
 			ip=(struct ip*)(packet+size_mac);

		
		/*char ipdotdecs[20]={0};
	       char ipdotdecc[20]={0};
		inet_ntop(AF_INET,(void*)&(ip->ip_src),ipdotdecs,16);
			inet_ntop(AF_INET,(void*)&(ip->ip_dst),ipdotdecc,16);*/
//printf("%s-->%s: len:%d\n",ipdotdecs,ipdotdecc,pkthdr->caplen);

			
		if((ip->ip_p==6))//tcp
		{
		//	msg("EIStcp\n");
			//tcp=(struct fniff_tcp*)(packet+size_mac+size_ip);
			tcp=(struct fniff_tcp*)((char*)ip+size_ip);
			sd.b_ip=(ip->ip_src.s_addr);
			sd.l_ip=(ip->ip_dst.s_addr);
			if(sd.b_ip>sd.l_ip)
			{
				sd.b_port=ntohs(tcp->th_sport);
				sd.l_port=ntohs(tcp->th_dport);
			}
			else
			{
				sd.b_ip^=sd.l_ip;
				sd.l_ip^=sd.b_ip;
				sd.b_ip^=sd.l_ip;
			
				sd.b_port=ntohs(tcp->th_dport);
				sd.l_port=ntohs(tcp->th_sport);					
			}			
			hash=hash_HB(sd.b_ip,sd.b_port,sd.l_ip,sd.l_port);
		
			tcplen=ntohs(ip->ip_len)-(ip->ip_hl*4)-(tcp->th_off*4);
	
		//	msg("EIStcp11111111111\n");
		//	printf("ntohs(ip->ip_len)=%d\n",ntohs(ip->ip_len)+14);
			// packet.tcp_URG=tcp->th_flags&TH_URG;
			  ack=tcp->th_flags&TH_ACK;
			 // packet.tcp_PSH=tcp->th_flags&TH_PUSH;
			  rst=tcp->th_flags&TH_RST;
			  syn=tcp->th_flags&TH_SYN;
			  fin=tcp->th_flags&TH_FIN;
			 datalen=pkthdr->caplen;
		   
			ptcp=(unsigned char*)tcp+(tcp->th_off*4);     	

			temp=find_node(hb[hash].virtual_sn,&sd);  
		  
			if(temp==NULL&&syn&&!ack&&tcplen==0)//not find
		      	{
		      		//msg("E no\n");
		      		SN* q=get_node();
		      		q->sdipport=sd;
		      		q->state=1;
				insert_node(&(hb[hash].virtual_sn),q);
				hb[hash].virtual_sn_num++;
				//msg("**********=%ld\n",hb[hash].virtual_sn_num);
				#if 0				
				if(sd.b_port==21||sd.l_port==21)
				{
					q->state=10;			
					pronum[FTP]++;
				}
				else if(sd.b_port==80||sd.l_port==80)
				{
					q->state=10;
					pronum[HTTP]++;
				}
				memcpy(fortest,packet,pkthdr->caplen);
				#endif
		
		      	}
		      	else if(temp!=NULL)
		      	{
		      		// printf("state:%d\n",temp->state);
		      	
		      		if((temp->state==1)&&syn&&ack&&(tcplen==0))
		      		{
		      			//msg("W:my ooooooooooooooooooo\n");
		      			temp->state=2;
		      		}
		      		else if(temp->state==2&&ack&&!syn&&tcplen==0)
		      		{
		      			temp->state=3;
		      			//msg("W:its ===============================static\n");
		      				//msg("W:my hash:%u\n",hash);
		      		}
		      		else if(temp->state>=3&&temp->state<9)
		      		{
		      			//if(tcplen==0)
		      			//	return;
		      			//msg("W:my hash:%u\n",hash);
		      			//msg("+++++\n");
					//msg("ttttttttttttt\n");
		      			p=get_BC_node();
					//msg("mmmmmmmmm\n");
					if(p==NULL)
						{msg("EISget bc node error\n");exit(0);}
		      			
		      			p->datalen=pkthdr->caplen;
		      			p->tcplen=tcplen;
					//msg("tcplen=%d,pkthdr->caplen=%d\n",tcplen,pkthdr->caplen);
					if(tcplen<0)
					{
						msg("EIS tcp<0\n");
						exit(0);
					}				
		      			p->next=NULL;
		      			memcpy(p->buf,packet,pkthdr->caplen);
					p->ptcp=(unsigned char*)(p->buf)+(tcp->th_off*4)+((unsigned char*)tcp-(unsigned char*)mac);//ptcp;
		      			temp->tcp_content_len+=tcplen;			
		      			if(temp->bc_head==NULL)
		      			{
		      				temp->bc_head=temp->bc_tail=p;
		      			}
		      			else
		      			{
		      				temp->bc_tail->next=p;
		      				temp->bc_tail=p;
		      			}
		      			temp->state++;
		      			if((temp->state==9)||rst||fin||(temp->tcp_content_len>150))
		      			{
		      				//msg("EIS static\n");
						#if 0
		      				p=temp->bc_head;
		      				while(p!=NULL)
		      				{				
							if(p->tcplen!=0)
							acsmSearch(acsm,p->ptcp,p->tcplen,PrintMatch);
		      					p=p->next;
		      				}
						#else
						acSearch(acsm,temp->bc_head);
		      				acSearch(acsm,temp->bc_head);
						#endif
		      				i=getSummary(acsm->acsmPatterns,feature_num); 
						    		
		      				pronum[i]++;
						temp->proto=i;
		      				if(rst||fin)
		      				{
							temp->state=10;
							resume_BC_node(temp->bc_head);
		      					resume_node(temp);
		      					hb[hash].virtual_sn_num--;
		      					
							//msg("*********=%ld\n",hb[hash].virtual_sn_num);
							if(hb[hash].virtual_sn_num==0)
								hb[hash].virtual_sn=NULL;
		      					return;
		      				}
		      				temp->state=10;
		      				resume_BC_node(temp->bc_head);
			      			temp->bc_head=NULL;
			      			temp->bc_tail=NULL;
		      			}
		      			
		      		}
		      		else if(temp->state>=10)
		      		{	

		      			if(rst||fin)
					{
						//resume_node(temp);
						move_node(&(hb[hash].virtual_sn),temp);
						hb[hash].virtual_sn_num--;
						//msg("**************=%ld\n",hb[hash].virtual_sn_num);
						if(hb[hash].virtual_sn_num==0)
							hb[hash].virtual_sn=NULL;
						return;
					}
		      		} 
				else
				{
					msg("ggggggggggg\n");
				}
		      		
		      	}     	
			
			    
	     }//tcp
	     else if(ip->ip_p==1)//icmp
	     {
		//printf("2222\n");
	     	//static char pro_map[PRO_MAX+2][20]={"HTTP","FTP","POP3","SMTP","UNKOWN","UDP","ICMP"};
	 	pronum[PRO_MAX+1]++;
	    }
	    else if(ip->ip_p==17)//udp
	    	{
			//printf("1111111\n");
	    		pronum[PRO_MAX]++;
	    	}   
		else
		{
			printf("no\n");
		}
}
EdgeWeight kway_graph_refinement_core::single_kway_refinement_round_internal(PartitionConfig & config, 
                                                                    graph_access & G, 
                                                                    complete_boundary & boundary, 
                                                                    boundary_starting_nodes & start_nodes, 
                                                                    int step_limit,
                                                                    vertex_moved_hashtable & moved_idx,
                                                                    bool compute_touched_partitions,
                                                                    std::unordered_map<PartitionID, PartitionID> &  touched_blocks) {

        commons = kway_graph_refinement_commons::getInstance(config);
        refinement_pq* queue = NULL;
        if(config.use_bucket_queues) {
                EdgeWeight max_degree = G.getMaxDegree();
                queue                 = new bucket_pq(max_degree);
        } else {
                queue                 = new maxNodeHeap(); 
        }

        init_queue_with_boundary(config, G, start_nodes, queue, moved_idx);  
        
        if(queue->empty()) {delete queue; return 0;}

        std::vector<NodeID> transpositions;
        std::vector<PartitionID> from_partitions;
        std::vector<PartitionID> to_partitions;

        int max_number_of_swaps = (int)(G.number_of_nodes());
        int min_cut_index       = -1;

        EdgeWeight cut         = std::numeric_limits<int>::max()/2; // so we dont need to compute the edge cut
        EdgeWeight initial_cut = cut;

        //roll forwards
        EdgeWeight best_cut = cut;
        int number_of_swaps = 0;
        int movements       = 0;

        kway_stop_rule* stopping_rule = NULL;
        switch(config.kway_stop_rule) {
                case KWAY_SIMPLE_STOP_RULE: 
                        stopping_rule = new kway_simple_stop_rule(config);
                        break;
                case KWAY_ADAPTIVE_STOP_RULE: 
                        stopping_rule = new kway_adaptive_stop_rule(config);
                        break;

        }

        for(number_of_swaps = 0, movements = 0; movements < max_number_of_swaps; movements++, number_of_swaps++) {
                if( queue->empty() ) break;
                if( stopping_rule->search_should_stop(min_cut_index, number_of_swaps, step_limit) ) break;

                Gain gain = queue->maxValue();
                NodeID node = queue->deleteMax();

#ifndef NDEBUG
                PartitionID maxgainer;
                EdgeWeight ext_degree;
                ASSERT_TRUE(moved_idx[node].index == NOT_MOVED);
                ASSERT_EQ(gain, commons->compute_gain(G, node, maxgainer, ext_degree));
                ASSERT_TRUE(ext_degree > 0);
#endif

                PartitionID from = G.getPartitionIndex(node); 
                bool successfull = move_node(config, G, node, moved_idx, queue, boundary);

                if(successfull) {
                        cut -= gain;
                        stopping_rule->push_statistics(gain);

                        bool accept_equal = random_functions::nextBool();
                        if( cut < best_cut || ( cut == best_cut && accept_equal )) {
                                best_cut = cut;
                                min_cut_index = number_of_swaps;
                                if(cut < best_cut)
                                        stopping_rule->reset_statistics();
                        }

                        from_partitions.push_back(from);
                        to_partitions.push_back(G.getPartitionIndex(node));
                        transpositions.push_back(node);
                } else {
                        number_of_swaps--; //because it wasnt swaps
                }
                moved_idx[node].index = MOVED;
                ASSERT_TRUE(boundary.assert_bnodes_in_boundaries());
                ASSERT_TRUE(boundary.assert_boundaries_are_bnodes());

        } 

        ASSERT_TRUE(boundary.assert_bnodes_in_boundaries());
        ASSERT_TRUE(boundary.assert_boundaries_are_bnodes());

        //roll backwards
        for(number_of_swaps--; number_of_swaps>min_cut_index; number_of_swaps--) {
                ASSERT_TRUE(transpositions.size() > 0);

                NodeID node = transpositions.back();
                transpositions.pop_back();

                PartitionID to = from_partitions.back();
                from_partitions.pop_back();
                to_partitions.pop_back();

                move_node_back(config, G, node, to,  moved_idx, queue, boundary);
        }

       
        //reconstruct the touched partitions
        if(compute_touched_partitions) {
                ASSERT_EQ(from_partitions.size(), to_partitions.size());
                for(unsigned i = 0; i < from_partitions.size(); i++) {
                        touched_blocks[from_partitions[i]] = from_partitions[i];
                        touched_blocks[to_partitions[i]]   = to_partitions[i];
                }
        }

        ASSERT_TRUE(boundary.assert_bnodes_in_boundaries());
        ASSERT_TRUE(boundary.assert_boundaries_are_bnodes());

        delete queue;
        delete stopping_rule;
        return initial_cut - best_cut; 
}
Exemple #14
0
Fichier : dary.c Projet : tkng/dary
static dary_status
move_conflicts2(dary *da, int n, uchar k)
{
   int conflicts[256+1], move_to; /* MAX conflicts 256, +1 is for termination */
   int retcode;
   int i = 0;

   get_children(da, n, conflicts);

   dprint("da->base[%d] =%d, k = %d", n, da->base[n], k);
  
   // ここはなんとか関数化できないか?
   if (conflicts[0] < da->base[n] + k) {
      while (conflicts[i] != -1) {
         i++;
      }
      dprint("last node is k");
      conflicts[i] = da->base[n] + k;
      conflicts[i+1] = -1;
   } else {
      int len = length(conflicts);
      memmove(&conflicts[1], conflicts, (len + 1) * sizeof(int));
      conflicts[0] = da->base[n] + k;
      dprint("first node is k");
   }
   i = 0;
   while (conflicts[i] != -1) {
      dprint("conflicts[%d] = %d", i, conflicts[i]);
      i++;
   }

   retcode = find_movable_location(da, conflicts, &move_to);

   if (retcode != DARY_STATUS_SUCCESS) {
      dprint("move_conflicts:Could not found movable location. Retrying...\n");
      retcode = extend_array(da, da->length + 256);
      if (retcode != DARY_STATUS_SUCCESS) {
         return retcode;
      }
      /* This find_movable_loc must be success, but ensure return value to make sure. */
      retcode = find_movable_location(da, conflicts, &move_to);
    
      if (retcode != DARY_STATUS_SUCCESS) {
         return retcode;
      }
   }

   i = 0;
   int offsets[257];

   calc_offsets(conflicts, offsets);

   for (i = 0; conflicts[i] != -1; i++) {
      if (conflicts[i] != da->base[n] + k) {
         move_node(da, conflicts[i], move_to + offsets[i]);
      }
   }
   da->base[n] = move_to - (conflicts[0] - da->base[n]);
   dprint("da->base[%d] = da->base[%d] (%d) + move_to %d - %d = %d",
          n, n, da->base[n], move_to, conflicts[0], 
          da->base[n] + (move_to - conflicts[0]));

   return DARY_STATUS_SUCCESS;
}