int searchPentagonLinkedList(GSList **Nodes, GSList **WorkingList, GSList **Pentagons, int Target) {

	GSList *a,*b,*c,*d,*e;
	int i,n_pentagons = 0;
	int fail;
		
	for(a=*Nodes; a != NULL; a = a->next) {		
		for(b=*Nodes; b != NULL; b = b->next) {
			if((b==a)||(NPTR(a)->primes[1] != NPTR(b)->primes[0])) continue;
			fail=0;
			for(i=1; i<4; i++) {
				if(	(NPTR(b)->primes[i] == NPTR(a)->primes[0])||
					(NPTR(b)->primes[i] == NPTR(a)->primes[2])||
					(NPTR(b)->primes[i] == NPTR(a)->primes[3])) {
					fail=1;
					break;
				}
			}
			if(fail==1) continue;
			for(c=*Nodes; c != NULL; c = c->next) {
				if((c==b)||(c==a)||(NPTR(b)->primes[1] != NPTR(c)->primes[0])) continue;
				if((NPTR(c)->primes[3] != NPTR(a)->primes[2])) continue;
				fail=0;
				for(i=1; i<3; i++) {
					if(	(NPTR(c)->primes[i] == NPTR(a)->primes[0])||
						(NPTR(c)->primes[i] == NPTR(a)->primes[1])||
						(NPTR(c)->primes[i] == NPTR(a)->primes[3])||
						(NPTR(c)->primes[i] == NPTR(b)->primes[2])||
						(NPTR(c)->primes[i] == NPTR(b)->primes[3])) {
						fail=1;
						break;
					}
				}
				if(fail==1) continue;
				for(d=*Nodes; d != NULL; d = d->next) {
					if((d==c)||(d==b)||(d==a)) continue;
					if(	// testing for link values
						(NPTR(d)->primes[0] != NPTR(c)->primes[1])||
						(NPTR(d)->primes[2] != NPTR(a)->primes[3])||
						(NPTR(d)->primes[3] != NPTR(b)->primes[2])||
						// testing for unique values
						(NPTR(d)->primes[1] == NPTR(a)->primes[0])||
						(NPTR(d)->primes[1] == NPTR(a)->primes[1])||
						(NPTR(d)->primes[1] == NPTR(a)->primes[2])||
						(NPTR(d)->primes[1] == NPTR(b)->primes[1])||
						(NPTR(d)->primes[1] == NPTR(b)->primes[3])||
						(NPTR(d)->primes[1] == NPTR(c)->primes[2])) continue;
					for(e=*Nodes; e != NULL; e = e->next) {
						if((e==d)||(e==c)||(e==b)||(e==a)) continue;
						if(	// testing for link values
							(NPTR(e)->primes[0] != NPTR(d)->primes[1])||
							(NPTR(e)->primes[1] != NPTR(a)->primes[0])||
							(NPTR(e)->primes[2] != NPTR(b)->primes[3])||
							(NPTR(e)->primes[3] != NPTR(c)->primes[2])) continue;
						// a-b-c-d-e is a pentagon
						// found a Pentagon
						struct ring5 *working = malloc(sizeof(struct ring5));					
						working->nodes[0] = NPTR(a);							
						working->nodes[1] = NPTR(b);
						working->nodes[2] = NPTR(c);
						working->nodes[3] = NPTR(d);
						working->nodes[4] = NPTR(e);
						// if this pentagon is already in list - ignore
						if(add_Pentagon_to_list(Pentagons,WorkingList,working) == 1) n_pentagons+=10;							
						free(working);
					} // e loop
				} // d loop
			} // c loop			
		} // b loop
	} // a loop		
	return n_pentagons;
}
Beispiel #2
0
int
read_ns(void)
{
	struct inpcbtable pcbtable;
	struct inpcb *head, *prev, *next;
	struct inpcb inpcb;
	struct socket sockb;
	struct tcpcb tcpcb;
	void *off;
	int istcp;

	if (kd == NULL) {
		return (0);
	}

	num_ns = 0;

	if (namelist[X_TCBTABLE].n_value == 0)
		return 0;

	if (protos & TCP) {
		off = NPTR(X_TCBTABLE);
		istcp = 1;
	} else if (protos & UDP) {
		off = NPTR(X_UDBTABLE);
		istcp = 0;
	} else {
		error("No protocols to display");
		return 0;
	}

again:
	KREAD(off, &pcbtable, sizeof (struct inpcbtable));

	prev = head = (struct inpcb *)&((struct inpcbtable *)off)->inpt_queue;
	next = CIRCLEQ_FIRST(&pcbtable.inpt_queue);

	while (next != head) {
		KREAD(next, &inpcb, sizeof (inpcb));
		if (CIRCLEQ_PREV(&inpcb, inp_queue) != prev) {
			error("Kernel state in transition");
			return 0;
		}
		prev = next;
		next = CIRCLEQ_NEXT(&inpcb, inp_queue);

		if (!aflag) {
			if (!(inpcb.inp_flags & INP_IPV6) &&
			    inet_lnaof(inpcb.inp_faddr) == INADDR_ANY)
				continue;
			if ((inpcb.inp_flags & INP_IPV6) &&
			    IN6_IS_ADDR_UNSPECIFIED(&inpcb.inp_faddr6))
				continue;
		}
		KREAD(inpcb.inp_socket, &sockb, sizeof (sockb));
		if (istcp) {
			KREAD(inpcb.inp_ppcb, &tcpcb, sizeof (tcpcb));
			if (!aflag && tcpcb.t_state <= TCPS_LISTEN)
				continue;
			enter(&inpcb, &sockb, tcpcb.t_state, "tcp");
		} else
			enter(&inpcb, &sockb, 0, "udp");
	}
	if (istcp && (protos & UDP)) {
		istcp = 0;
		off = NPTR(X_UDBTABLE);
		goto again;
	}

	num_disp = num_ns;
	return 0;
}
int searchPentagonArray(GSList **Nodes, GSList **Pentagons, int Target) {
	
	
	int *NodePairs = NULL;
	int idx_pairs, n_nodes, n_pentagons;
	int a, a_offset, b, b_offset, c, c_offset, d, d_offset, e, e_offset;
	GSList *pNodeL, *pNodeR;
	struct ring5 *newring;
	
	// setup a (very) large array of node pairs describing their
	// relationship. adj=2, diag=1, unpair=0	
	n_nodes = g_slist_length(*Nodes);
	NodePairs = (int *)malloc(sizeof(int)*n_nodes*n_nodes);	
	pNodeL = *Nodes;
		
	while(pNodeL != NULL) {
		idx_pairs = (NPTR(pNodeL)->node4_id)*n_nodes;
		pNodeR = *Nodes;
		while(pNodeR != NULL) {
			if(diagonalNode4(NPTR(pNodeL), NPTR(pNodeR)) == 1) {
				NodePairs[idx_pairs++] = 1;
			} else if (adjacentNode4(NPTR(pNodeL), NPTR(pNodeR)) == 1) {
				NodePairs[idx_pairs++] = 2;
				} else {
				NodePairs[idx_pairs++] = 0;
				}
			pNodeR = pNodeR->next;			
			}
		pNodeL = pNodeL->next;	
	}
	
#if(1)
	// -----debug check array for consistency-----
	int adj=0, diag=0, unpair=0, err=0;
	for(idx_pairs=0; idx_pairs < (n_nodes*n_nodes); idx_pairs++) {
		switch(NodePairs[idx_pairs]) {
			case 2:
				adj++;
				break;
			case 1:
				diag++;
				break;
			case 0:
				unpair++;
				break;
			default:
				err++;
				break;
		}
	}	
	printf("adj = %d diag = %d unpair = %d err = %d\n",adj,diag,unpair,err);
	printf("Input items %d	pairs = %d\n", (n_nodes*n_nodes), (adj+diag+unpair));
	// -----end debug consistency check-----
#endif
	// main search for Pentagons

	*Pentagons = NULL;
	// 4 index search of this array to find Rings
	n_pentagons = 0;
	for(a=0; a<n_nodes; a++) {
		a_offset = a*n_nodes;
		for(b=0; b<n_nodes; b++) {
			b_offset = b*n_nodes;
			if(NodePairs[a_offset + b] != 2) continue;	// a->b			
			for(c=0; c<n_nodes; c++) {
				c_offset = c*n_nodes;
				if(	(NodePairs[b_offset + c] != 2)||	// b->c & a->c
					(NodePairs[a_offset + c] != 1)) continue;
				for(d=0; d<n_nodes; d++) {
					d_offset = d*n_nodes;
					if(	(NodePairs[c_offset + d] != 2)||	// c->d &d->a & b->d
						(NodePairs[d_offset + a] != 1)||
						(NodePairs[b_offset + d] != 1)) continue;
					for(e=0; e<n_nodes; e++) {
						e_offset = e*n_nodes;
						if(	(NodePairs[e_offset + a] == 2)||
							(NodePairs[e_offset + d] == 2)||
							(NodePairs[e_offset + b] == 1)||
							(NodePairs[e_offset + c] == 1))
						{	// found a Pentagon
							newring = malloc(sizeof(Ring5));
							newring->nodes[0] = (Node4*)g_slist_nth_data(*Nodes, a);							
							newring->nodes[1] = (Node4*)g_slist_nth_data(*Nodes, b);
							newring->nodes[2] = (Node4*)g_slist_nth_data(*Nodes, c);
							newring->nodes[3] = (Node4*)g_slist_nth_data(*Nodes, d);
							newring->nodes[4] = (Node4*)g_slist_nth_data(*Nodes, e);
							*Pentagons = g_slist_prepend(*Pentagons, newring);
							n_pentagons++;
							printf("%d %d %d %d %d\n",a,b,c,d,e);
						}
					}
				}
			}
		}
	}
	return n_pentagons;
}