/*
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
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;
}
示例#3
0
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;
}
// Helper functions ============================================================
double standardize(RoomyGraph *g, uint64 node, uint64 (*f)(RoomyGraph*, uint64)) {
  uint64 d = f(g, node);
  uint64 nodeCount = RoomyGraph_nodeCount(g);
  return ((double) d) / ((double)(nodeCount - 1));
}