fourth commit (cleaning up code)
authorBrendan Hansen <brendan.f.hansen@gmail.com>
Fri, 22 Feb 2019 16:17:58 +0000 (10:17 -0600)
committerBrendan Hansen <brendan.f.hansen@gmail.com>
Fri, 22 Feb 2019 16:17:58 +0000 (10:17 -0600)
main.lua
modules/graph_algorithms.h
modules/graph_standard.c
modules/graph_utils.c
modules/utils.c
modules/utils.h

index 409a62b0b77a1d1feeb134d7efac3761f2e24889..19d5536a5ed1579a8560034cff509bc59839bc80 100644 (file)
--- a/main.lua
+++ b/main.lua
@@ -7,8 +7,12 @@ function love.load()
        local node2 = graphs.add_node(graph)
        local node3 = graphs.add_node(graph)
 
+       print("NODES", node1, node2, node3)
+
        graphs.add_directed(graph, node1, node2, 2)
        graphs.add_directed(graph, node2, node3, 4)
+
+       graphs.print_graph(graph)
 end
 
 function love.update()
index ceead3d1b0e6c155bc7b6e9abd89345dd0eb7b89..838f9ef801fb096adddc77d3f8c2d423c66991fd 100644 (file)
@@ -1,4 +1,6 @@
 #ifndef __GRAPH_ALGORITHM_H__
 #define __GRAPH_ALGORITHM_H__
 
+
+
 #endif
\ No newline at end of file
index 24405aafec835ce44548cf1236b298d8705bbf44..f7b0aea9752495b1d21f5abe80d1dcb3b4584eb4 100644 (file)
@@ -243,7 +243,6 @@ int del_edge(lua_State *L)
        }
 
        return 0;
-
 }
 
 static connect find_node(header head, int node_id)
index cb9e4d17f9fe49864d3da046076e3bbc6ea5b21b..809b70647c05be8ebead8e2bb755c4768e196249 100644 (file)
@@ -3,14 +3,16 @@
 int get_nodes(lua_State *L)
 {
        header head = (header) lua_touserdata(L, 1);
-       lua_pop(L, 1);
+       lua_pop(L, 1); // Take off the pointer parameter
 
-       lua_newtable(L);
+       lua_newtable(L); // Push a new table onto the stack
 
        int index = 1;
        for (connect jogger = head->front; jogger != NULL; jogger = jogger->next_node) {
-               lua_pushnumber(L, index);
-               lua_newtable(L);
+               lua_pushnumber(L, index); // Push the next index of the node, sets up for settable call
+               lua_newtable(L); // Push on the table that will store each node
+
+               // Add the fields to our node table
 
                lua_pushnumber(L, jogger->node_id);
                lua_setfield(L, 3, "id");
@@ -20,6 +22,7 @@ int get_nodes(lua_State *L)
                lua_pushnumber(L, jogger->y);
                lua_setfield(L, 3, "y");
 
+               // Put our node table in the table we are returning
                lua_settable(L, 1);
                
                index++;
@@ -64,7 +67,6 @@ int get_edges(lua_State *L)
        return 1;
 }
 
-
 int print_graph(lua_State *L)
 {
        header head = (header)lua_touserdata(L,1);
index be76908668c0981dba2679a6d47348674abbde9f..d5fa0c19ca7e6cee6c0a6c4bd6445cd9222b5188 100644 (file)
@@ -3,7 +3,7 @@
 
 #include "utils.h"
 
-int top(sq_node_p stack_top)
+int sq_top(sq_node_p stack_top)
 {
        if(stack_top == NULL)
        {
@@ -13,7 +13,7 @@ int top(sq_node_p stack_top)
        return stack_top->value;
 }
 
-int front(sq_node_p queue_front)
+int sq_front(sq_node_p queue_front)
 {
        if(queue_front == NULL)
        {
@@ -24,7 +24,7 @@ int front(sq_node_p queue_front)
 }
 
 //FUNCTIONS HANDELING CHANGING THE STACK
-sq_node_p push(sq_node_p stack_top, int val)
+sq_node_p sq_push(sq_node_p stack_top, int val)
 {
        sq_node_p new_node = (sq_node_p)malloc(sizeof(sq_node));
        new_node->value = val;
@@ -32,7 +32,7 @@ sq_node_p push(sq_node_p stack_top, int val)
        return new_node;
 }
 
-sq_node_p pop(sq_node_p stack_top)
+sq_node_p sq_pop(sq_node_p stack_top)
 {
        sq_node_p temp = stack_top;
 
@@ -51,7 +51,7 @@ sq_node_p pop(sq_node_p stack_top)
 }
 
 //FUNCTIONS HANDELING CHANGING THE QUEUE
-sq_node_p enque(sq_node_p front_of_queue, int val)
+sq_node_p sq_enque(sq_node_p front_of_queue, int val)
 {
        sq_node_p new_node = (sq_node_p)malloc(sizeof(sq_node));
        new_node->value = val;
@@ -74,7 +74,7 @@ sq_node_p enque(sq_node_p front_of_queue, int val)
        return front_of_queue;
 }
 
-sq_node_p deque(sq_node_p front_of_queue)
+sq_node_p sq_deque(sq_node_p front_of_queue)
 {
        if(front_of_queue == NULL)
        {
@@ -91,7 +91,7 @@ sq_node_p deque(sq_node_p front_of_queue)
        return front_of_queue;
 }
 
-void print_sq(sq_node_p sq)
+void sq_print(sq_node_p sq)
 {
        sq_node_p runner = sq;
 
index 30e4052c253437c82b31f83bf709d2dc76fd10be..eee22b80fb41b33f17dc4e20103d1957364f3a3e 100644 (file)
@@ -8,5 +8,20 @@ typedef struct sq_node {
        struct sq_node * next;
 } sq_node, *sq_node_p;
 
+int sq_top(sq_node_p stack_top);
+int sq_front(sq_node_p queue_front);
+
+sq_node_p sq_push(sq_node_p stack_top, int val);
+sq_node_p sq_pop(sq_node_p stack_top);
+sq_node_p sq_enque(sq_node_p front_of_queue, int val);
+sq_node_p sq_deque(sq_node_p front_of_queue);
+
+void sq_print(sq_node_p sq);
+
+// Helper macros that make the call site of these functions cleaner
+#define push(sq, val)  ((sq) = sq_push( (sq), (val)))
+#define pop(sq, val)   ((sq) = sq_pop(  (sq), (val)))
+#define enque(sq, val) ((sq) = sq_enque((sq), (val)))
+#define deque(sq, val) ((sq) = sq_deque((sq), (val)))
 
 #endif
\ No newline at end of file