コード例 #1
0
/*
Creates and prints the graph seen in diagrams/simple-graph.png.
*/
void createSimpleGraph() {
	uint64 one = 1;
	uint64 two = 2;
	uint64 three = 3;
	uint64 four = 4;
	uint64 five = 5;

	// From our sample graph we know that 1 has the most children (3) so 
	// maxEdges MUST be at least that number.
	uint64 maxEdges = 3;
	// We also know that there are 5 nodes.
	uint64 initialCapacity = 5;
	RoomyGraph *g = RoomyGraph_make("simple-graph", maxEdges, initialCapacity);

	// Add all the nodes
	RoomyGraph_addNode(g, one);
	RoomyGraph_addNode(g, two);
	RoomyGraph_addNode(g, three);
	RoomyGraph_addNode(g, four);
	RoomyGraph_addNode(g, five);

	// Now, add all the edges
	RoomyGraph_addEdge(g, one, two);
	RoomyGraph_addEdge(g, one, three);
	RoomyGraph_addEdge(g, one, five);
	RoomyGraph_addEdge(g, three, one);
	RoomyGraph_addEdge(g, five, five);
	
	RoomyGraph_sync(g);
	uint64 nodeCount = RoomyGraph_nodeCount(g);
	printf("There are %lli nodes.\n", nodeCount);
	RoomyGraph_print(g);
	
	RoomyGraph_destroy(g);
}
コード例 #2
0
RoomyGraph* createBasicGraph(char *name) {
  // makes a graph with no edges.  don't forget to call sync!
	RoomyGraph *g = RoomyGraph_make(name, 3, 4);
	RoomyGraph_addNode(g, n1);
	RoomyGraph_addNode(g, n2);
	RoomyGraph_addNode(g, n3);
	RoomyGraph_addNode(g, n4);
	return g;
}
コード例 #3
0
ファイル: RoomyGraphTests.c プロジェクト: junli1026/hpc
int addMultipleNodes() {
	RoomyGraph *g = RoomyGraph_make("multiNode", 2, 4);
	uint64 first = 1;
	uint64 second = 2;
	RoomyGraph_addNode(g, first);
	RoomyGraph_addNode(g, second);
	RoomyGraph_sync(g);
	
	assert(TRUE == RoomyGraph_containsNode(g, first));
	assert(TRUE == RoomyGraph_containsNode(g, second));

	RoomyGraph_destroy(g);
	printf("addMultipleNodes completed successfully.\n");
	return PASSED;
}
コード例 #4
0
void RoomyGraph_addNodes(RoomyGraph *g, uint64 nodes[], uint64 nodeCount) {
	uint64 i;
	for(i = 0; i < nodeCount; i++) {
	  uint64 n = nodes[i];
		RoomyGraph_addNode(g, n);
	}
}
コード例 #5
0
ファイル: RoomyGraphTests.c プロジェクト: junli1026/hpc
int addEdgeTest() {
	RoomyGraph *g = RoomyGraph_make("addEdgeTest", 2, 2);
	uint64 from = 2;
	uint64 to = 4;
	RoomyGraph_addNode(g, from);
	RoomyGraph_addNode(g, to);
	RoomyGraph_addEdge(g, from, to);
	RoomyGraph_sync(g);

//	RoomyGraph_print(g);

	assert(TRUE == RoomyGraph_containsEdge(g, from, to));
	assert(FALSE == RoomyGraph_containsEdge(g, to, from));

	RoomyGraph_destroy(g);
	printf("addEdgeTest completed successfully.\n");
	return PASSED;
}
コード例 #6
0
ファイル: RoomyGraphTests.c プロジェクト: junli1026/hpc
int addNode() {
	// Create a very simple RG so we can add a single node to it.
	RoomyGraph *g = RoomyGraph_make("addNode", 2, 2);
	uint64 node = 3;
	RoomyGraph_addNode(g, node);
	RoomyGraph_sync(g);
	assert(TRUE == RoomyGraph_containsNode(g, node));
	RoomyGraph_destroy(g);
	printf("addNode completed successfully.\n");
	return PASSED;
}
コード例 #7
0
ファイル: RoomyGraphTests.c プロジェクト: junli1026/hpc
int addingSameNodeDoesntIncreaseCount() {
	RoomyGraph *g = RoomyGraph_make("multiAdds", 2, 2);
	uint64 node = 653;
	RoomyGraph_addNode(g, node);
	RoomyGraph_sync(g);
	assert(1 == RoomyGraph_nodeCount(g));
	
	RoomyGraph_addNode(g, node);
	RoomyGraph_sync(g);
	assert(1 == RoomyGraph_nodeCount(g));

	uint64 node2 = 1127;
	RoomyGraph_addNode(g, node2);
	RoomyGraph_sync(g);
	assert(2 == RoomyGraph_nodeCount(g));
	
	RoomyGraph_destroy(g);

	printf("addingSameNodeDoesntIncreaseCount completed successfully.\n");
	return PASSED;
}
コード例 #8
0
ファイル: RoomyGraphTests.c プロジェクト: junli1026/hpc
int containsNodeTest() {
	RoomyGraph *g = RoomyGraph_make("containsNodeTest", 2, 2);
	uint64 node = 3;
	RoomyGraph_addNode(g, node);
	RoomyGraph_sync(g);
	uint64 notIn = 4;
	assert(TRUE == RoomyGraph_containsNode(g, node));
	assert(FALSE == RoomyGraph_containsNode(g, notIn));
	RoomyGraph_destroy(g);
	printf("containsNodeTest completed successfully.\n");
	return PASSED;
}
コード例 #9
0
ファイル: RoomyGraphTests.c プロジェクト: junli1026/hpc
int ableToAddMoreThanInitialSize() {
	RoomyGraph *g = RoomyGraph_make("increaseCapacity", 2, 2);
	uint64 count = 0;
	while(count < 4) {
		count++;
		RoomyGraph_addNode(g, count);	
	}
	RoomyGraph_sync(g);
	assert(4 == RoomyGraph_nodeCount(g));
	//printf("Contents of RoomyGraph that has been expanded from size 2 to 4...\n");
	//RoomyGraph_print(g);
	RoomyGraph_destroy(g);
	printf("ableToAddMoreThanInitialSize completed successfully.\n");
	return PASSED;
}