]> git.mdlowis.com Git - projs/libcds.git/commitdiff
Renamed files in preparation for new datastructures and started unit test files
authorMike D. Lowis <mike@mdlowis.com>
Thu, 22 Mar 2012 17:23:20 +0000 (13:23 -0400)
committerMike D. Lowis <mike@mdlowis.com>
Thu, 22 Mar 2012 17:23:20 +0000 (13:23 -0400)
16 files changed:
.gitignore
src/ht/ht.c [moved from src/hashtable/hashtable.c with 100% similarity]
src/ht/ht.h [moved from src/hashtable/hashtable.h with 100% similarity]
src/linked_list/linked_list.c [deleted file]
src/lists/double_link/dll.c [moved from tests/DUMMY with 100% similarity]
src/lists/double_link/dll.h [new file with mode: 0644]
src/lists/single_link/sll.c [new file with mode: 0644]
src/lists/single_link/sll.h [moved from src/linked_list/linked_list.h with 54% similarity]
src/trees/avl/avl.c [new file with mode: 0644]
src/trees/avl/avl.h [new file with mode: 0644]
src/trees/binary/bt.c [new file with mode: 0644]
src/trees/binary/bt.h [new file with mode: 0644]
src/trees/redblack/rbt.c [new file with mode: 0644]
src/trees/redblack/rbt.h [new file with mode: 0644]
tests/ht/test_ht.c [new file with mode: 0644]
tests/lists/sll/test_sll.c [new file with mode: 0644]

index 0951d207a2bbc139c0debdb79c3ca80a5b21626e..2f153e8f149924900cf5e6c0193d07c4bd924e86 100644 (file)
@@ -1,2 +1,4 @@
 build/*/
 cscope.out
+tags
+project.vim
similarity index 100%
rename from src/hashtable/hashtable.c
rename to src/ht/ht.c
similarity index 100%
rename from src/hashtable/hashtable.h
rename to src/ht/ht.h
diff --git a/src/linked_list/linked_list.c b/src/linked_list/linked_list.c
deleted file mode 100644 (file)
index a0df8ac..0000000
+++ /dev/null
@@ -1,119 +0,0 @@
-/******************************************************************************
- *  Copyright (C) 2011  Michael D. Lowis
- *
- *  This program is free software: you can redistribute it and/or modify
- *  it under the terms of the GNU General Public License as published by
- *  the Free Software Foundation, either version 3 of the License, or
- *  (at your option) any later version.
- *
- *  This program is distributed in the hope that it will be useful,
- *  but WITHOUT ANY WARRANTY; without even the implied warranty of
- *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *  GNU General Public License for more details.
- *
- *  You should have received a copy of the GNU General Public License
- *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
- *****************************************************************************/
-#include "linked_list.h"
-#include <stdlib.h>
-
-/******************************************************************************
- * Public Functions
- ******************************************************************************/
-LinkedList_T* LL_New( PTR_TYPE contents )
-{
-       LinkedList_T* list = (LinkedList_T*)malloc( sizeof(LinkedList_T) );
-       list->contents = contents;
-       list->next = NULL;
-       return list;
-}
-
-LinkedList_T* LL_Last( LinkedList_T* list )
-{
-       LinkedList_T* node = list;
-       while((node != NULL) && (node->next != NULL))
-       {
-               node = node->next;
-       }
-       return node;
-}
-
-LinkedList_T* LL_Get( LinkedList_T* list, int index )
-{
-       int current = 0;
-       LinkedList_T* node = list;
-       LinkedList_T* indexed_node = NULL;
-       while ((node != NULL))
-       {
-               if ( current == index )
-               {
-                       indexed_node = node;
-                       break;
-               }
-               node = node->next;
-               current++;
-       }
-       return indexed_node;
-}
-
-void LL_Add( LinkedList_T* list, PTR_TYPE contents )
-{
-       LinkedList_T* node = LL_Last( list );
-       node->next = LL_New( contents );
-}
-
-LinkedList_T* LL_Insert( LinkedList_T* list, int index, PTR_TYPE contents )
-{
-       int req_index = ((index-1) < 0) ? 0 : index-1;
-       LinkedList_T* node = LL_Get( list, req_index );
-       if(node != NULL)
-       {
-               LinkedList_T* next_next = node->next;
-               node->next = LL_New( contents );
-               node->next->next = next_next;
-               node = node->next;
-       }
-       return node;
-}
-
-void LL_Delete( LinkedList_T* list, int index, BOOL free_contents)
-{
-       LinkedList_T* node = LL_Get( list, (index-1));
-       if((node != NULL) && (node->next != NULL))
-       {
-               LinkedList_T* node_to_delete = node->next;
-               node->next = node_to_delete->next;
-               if (free_contents)
-               {
-                       free(node_to_delete->contents);
-               }
-               free(node_to_delete);
-       }
-}
-
-void LL_Free( LinkedList_T* list, BOOL free_contents)
-{
-       LinkedList_T* node = list;
-       while( node != NULL )
-       {
-               LinkedList_T* next = node->next;
-               if (free_contents)
-                       {
-                       free(node->contents);
-                       }
-               free(node);
-               node = next;
-       }
-}
-
-U32 LL_Length(LinkedList_T* list)
-{
-       U32 length = 0;
-       LinkedList_T* item = list;
-       for ( item = list; item != NULL; item = item->next )
-       {
-               length++;       
-       }
-       return length;
-}
-
similarity index 100%
rename from tests/DUMMY
rename to src/lists/double_link/dll.c
diff --git a/src/lists/double_link/dll.h b/src/lists/double_link/dll.h
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/src/lists/single_link/sll.c b/src/lists/single_link/sll.c
new file mode 100644 (file)
index 0000000..bed666d
--- /dev/null
@@ -0,0 +1,121 @@
+/******************************************************************************
+ *  Copyright (C) 2011  Michael D. Lowis
+ *
+ *  This program is free software: you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation, either version 3 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *****************************************************************************/
+#include "sll.h"
+#include <stdlib.h>
+
+/******************************************************************************
+ * Public Functions
+ ******************************************************************************/
+sll_node* sll_new( void* contents )
+{
+    sll_node* list = (sll_node*)malloc( sizeof(sll_node) );
+    list->contents = contents;
+    list->next = NULL;
+    return list;
+}
+
+sll_node* sll_last( sll_node* list )
+{
+    sll_node* node = list;
+    while((node != NULL) && (node->next != NULL))
+    {
+        node = node->next;
+    }
+    return node;
+}
+
+sll_node* sll_get( sll_node* list, int index )
+{
+    int current = 0;
+    sll_node* node = list;
+    sll_node* indexed_node = NULL;
+    while ((node != NULL))
+    {
+        if ( current == index )
+        {
+            indexed_node = node;
+            break;
+        }
+        node = node->next;
+        current++;
+    }
+    return indexed_node;
+}
+
+sll_node* sll_add( sll_node* list, void* contents )
+{
+    sll_node* node = sll_last( list );
+    node->next = sll_new( contents );
+}
+
+sll_node* sll_insert( sll_node* list, int index, void* contents )
+{
+    int req_index = ((index-1) < 0) ? 0 : index-1;
+    sll_node* node = sll_get( list, req_index );
+    if(node != NULL)
+    {
+        sll_node* next_next = node->next;
+        node->next = sll_new( contents );
+        node->next->next = next_next;
+        node = node->next;
+    }
+    return node;
+}
+
+sll_node* sll_delete( sll_node* list, int index, int free_contents)
+{
+    sll_node* node = sll_get( list, (index-1));
+    if((node != NULL) && (node->next != NULL))
+    {
+        sll_node* node_to_delete = node->next;
+        node->next = node_to_delete->next;
+        if (free_contents)
+        {
+            free(node_to_delete->contents);
+        }
+        free(node_to_delete);
+        node = node->next;
+    }
+    return node;
+}
+
+void sll_free( sll_node* list, int free_contents)
+{
+    sll_node* node = list;
+    while( node != NULL )
+    {
+        sll_node* next = node->next;
+        if (free_contents)
+            {
+            free(node->contents);
+            }
+        free(node);
+        node = next;
+    }
+}
+
+unsigned int sll_length(sll_node* list)
+{
+    unsigned int length = 0;
+    sll_node* item = list;
+    for ( item = list; item != NULL; item = item->next )
+    {
+        length++;
+    }
+    return length;
+}
+
similarity index 54%
rename from src/linked_list/linked_list.h
rename to src/lists/single_link/sll.h
index 551a1dae0dc69834ccb7bc9d44f479cfdeece289..1bed18e76f4314f739000dce6fa3e95e84d657d7 100644 (file)
 #ifndef LINKED_LIST_H
 #define LINKED_LIST_H
 
-#include "common.h"
-
-#define   PTR_TYPE  void *
-
-typedef struct LinkedList
+typedef struct node
 {
-       PTR_TYPE contents;
-       struct LinkedList * next;
-} LinkedList_T;
+    void* contents;
+    struct node* next;
+} sll_node;
 
 /**
- * @brief      Creates a new linked list node with the supplied value.
- * 
- * Allocates a new node on the heap and populates the node contents with the 
+ * @brief   Creates a new linked list node with the supplied value.
+ *
+ * Allocates a new node on the heap and populates the node contents with the
  * supplied contents pointer.
  *
- * @param      contents    The contents of the newly created node.
+ * @param   contents    The contents of the newly created node.
  *
- * @return     A pointer to the newly created node.
+ * @return  A pointer to the newly created node.
  * */
-LinkedList_T* LL_New( PTR_TYPE contents );
+sll_node* sll_new( void* contents );
 
 /**
- * @brief      Finds and returns the last node in the supplied linked list.
+ * @brief   Finds and returns the last node in the supplied linked list.
  *
- * @param      list    The linked list to search.
+ * @param   list    The linked list to search.
  *
- * @return     Pointer to the last node in the supplied list.
+ * @return  Pointer to the last node in the supplied list.
  * */
-LinkedList_T* LL_Last(LinkedList_T* list);
+sll_node* sll_last(sll_node* list);
 
 /**
- * @brief      Return the node at the specified index in a linked list.
+ * @brief   Return the node at the specified index in a linked list.
  *
  * Loops through the linked list and returns the node in the list at the
  * specified index. Returns NULL if the index is out of range.
  *
- * @param      list    The list to search for the supplied index.
- * @param      index   The index of the node to return.
+ * @param   list    The list to search for the supplied index.
+ * @param   index   The index of the node to return.
  *
- * @return     A pointer to the node and the supplied index, NULL if out of range.
+ * @return  A pointer to the node and the supplied index, NULL if out of range.
  * */
-LinkedList_T* LL_Get(LinkedList_T* list, int index);
+sll_node* sll_get(sll_node* list, int index);
 
 /**
- * @brief      Adds a new node to an existing linked list.
+ * @brief   Adds a new node to an existing linked list.
  *
- * @param      list
- * @param      contents
+ * @param   list
+ * @param   contents
+ *
+ * @return Pointer to the newly added node.
  * */
-void LL_Add( LinkedList_T* list, PTR_TYPE contents );
+sll_node* sll_add( sll_node* list, void* contents );
 
 /**
- * @brief      Inserts a new node in a linked list at the specified index.
+ * @brief   Inserts a new node in a linked list at the specified index.
  *
- * @param      list
- * @param      index
- * @param      contents
+ * @param   list
+ * @param   index
+ * @param   contents
  *
- * @return     Pointer to the newly inserted node, NULL if index is out of range.
+ * @return  Pointer to the newly inserted node, NULL if index is out of range.
  * */
-LinkedList_T* LL_Insert( LinkedList_T* list, int index, PTR_TYPE contents);
+sll_node* sll_insert( sll_node* list, int index, void* contents);
 
 /**
- * @brief      Deletes a node from the supplied list.
+ * @brief   Deletes a node from the supplied list.
  *
  * Deletes the node found at the supplied index from the supplied list and frees
  * the memory used by the node and its contents.
  *
- * @param      list
- * @param      index
+ * @param   list
+ * @param   index
  * @param   free_contents Whether or not to also free the contents of the node.
+ *
+ * @return Pointer to the node that is now at the supplied index.
  * */
-void LL_Delete( LinkedList_T* list, int index, BOOL free_contents);
+sll_node* sll_delete( sll_node* list, int index, int free_contents);
 
 /**
- * @brief      Frees all memory used by a linked list.
+ * @brief   Frees all memory used by a linked list.
  *
  * Loops through the supplied list and frees all nodes. Also frees contents if
- * free_contents is passed TRUE. This is to avoid trying to free memory 
+ * free_contents is passed TRUE. This is to avoid trying to free memory
  * allocated on the stack.
  *
- * @param      list          The list to be freed.
+ * @param   list          The list to be freed.
  * @param   free_contents Whether or not to also free the contents of each node.
  * */
-void LL_Free( LinkedList_T* list, BOOL free_contents);
+void sll_free( sll_node* list, int free_contents);
 
 /**
  * @brief Returns the number of elements in the list.
- * 
+ *
  * Loops through the supplied list and returns a count of the number of elements
  * contained in the list.
  *
@@ -114,6 +114,6 @@ void LL_Free( LinkedList_T* list, BOOL free_contents);
  *
  * @return The number of elements in the list.
  **/
-U32 LL_Length(LinkedList_T* list);
+unsigned int sll_length(sll_node* list);
 
 #endif
diff --git a/src/trees/avl/avl.c b/src/trees/avl/avl.c
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/src/trees/avl/avl.h b/src/trees/avl/avl.h
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/src/trees/binary/bt.c b/src/trees/binary/bt.c
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/src/trees/binary/bt.h b/src/trees/binary/bt.h
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/src/trees/redblack/rbt.c b/src/trees/redblack/rbt.c
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/src/trees/redblack/rbt.h b/src/trees/redblack/rbt.h
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/tests/ht/test_ht.c b/tests/ht/test_ht.c
new file mode 100644 (file)
index 0000000..2302194
--- /dev/null
@@ -0,0 +1,9 @@
+#include "unity.h"
+
+void setUp(void)
+{
+}
+
+void tearDown(void)
+{
+}
diff --git a/tests/lists/sll/test_sll.c b/tests/lists/sll/test_sll.c
new file mode 100644 (file)
index 0000000..a661a81
--- /dev/null
@@ -0,0 +1,121 @@
+#include "unity.h"
+
+// File Under Test
+#include "sll.h"
+
+void setUp(void)
+{
+}
+
+void tearDown(void)
+{
+}
+
+//-----------------------------------------------------------------------------
+void test_sll_new_should_allocate_memory_for_and_return_a_pointer_to_a_new_linked_list(void)
+{
+    TEST_FAIL_MESSAGE("Not Implemented");
+}
+
+//-----------------------------------------------------------------------------
+void test_sll_last_should_return_the_last_element_in_the_given_list(void)
+{
+    TEST_FAIL_MESSAGE("Not Implemented");
+}
+
+void test_sll_last_should_return_null_if_the_list_is_empty(void)
+{
+    TEST_FAIL_MESSAGE("Not Implemented");
+}
+
+//-----------------------------------------------------------------------------
+void test_sll_get_should_return_a_pointer_to_the_node_at_the_given_index(void)
+{
+    TEST_FAIL_MESSAGE("Not Implemented");
+}
+
+void test_sll_get_should_return_null_if_the_list_is_empty(void)
+{
+    TEST_FAIL_MESSAGE("Not Implemented");
+}
+
+//-----------------------------------------------------------------------------
+void test_sll_add_should_add_a_new_node_to_the_end_of_the_given_list_with_the_supplied_contents_and_return_a_pointer_to_the_new_node(void)
+{
+    TEST_FAIL_MESSAGE("Not Implemented");
+}
+
+void test_sll_add_should_return_a_new_list_if_the_given_list_is_null(void)
+{
+    TEST_FAIL_MESSAGE("Not Implemented");
+}
+
+//-----------------------------------------------------------------------------
+void test_sll_insert_should_create_a_new_node_add_it_to_the_list_at_the_desired_index_and_return_a_pointer_to_it(void)
+{
+    TEST_FAIL_MESSAGE("Not Implemented");
+}
+
+void test_sll_insert_should_return_null_if_the_specified_index_does_not_exist(void)
+{
+    TEST_FAIL_MESSAGE("Not Implemented");
+}
+
+void test_sll_insert_should_return_null_if_the_supplied_list_is_null(void)
+{
+    TEST_FAIL_MESSAGE("Not Implemented");
+}
+
+//-----------------------------------------------------------------------------
+void test_sll_delete_should_delete_the_node_at_the_specified_index_in_the_given_list_and_free_both_its_memory_and_contents_when_free_contents_is_1(void)
+{
+    TEST_FAIL_MESSAGE("Not Implemented");
+}
+
+void test_sll_delete_should_delete_the_node_at_the_specified_index_in_the_given_list_and_free_only_its_memory_when_free_contents_is_0(void)
+{
+    TEST_FAIL_MESSAGE("Not Implemented");
+}
+
+void test_sll_delete_should_do_nothing_if_the_specified_index_does_not_exist_in_the_list(void)
+{
+    TEST_FAIL_MESSAGE("Not Implemented");
+}
+
+void test_sll_delete_should_do_nothing_if_the_supplied_list_is_null(void)
+{
+    TEST_FAIL_MESSAGE("Not Implemented");
+}
+
+//-----------------------------------------------------------------------------
+void test_sll_free_should_call_free_on_all_nodes_and_contents_in_the_supplied_list_when_free_contents_is_1(void)
+{
+    TEST_FAIL_MESSAGE("Not Implemented");
+}
+
+void test_sll_free_should_call_free_on_all_nodes_and_NOT_contents_in_the_supplied_list_when_free_contents_is_0(void)
+{
+    TEST_FAIL_MESSAGE("Not Implemented");
+}
+
+void test_sll_free_should_do_nothing_when_supplied_list_is_null(void)
+{
+    TEST_FAIL_MESSAGE("Not Implemented");
+}
+
+//-----------------------------------------------------------------------------
+void test_sll_length_should_return_2_list_when_list_is_of_length_2(void)
+{
+    TEST_FAIL_MESSAGE("Not Implemented");
+}
+
+void test_sll_length_should_return_1_when_list_is_of_length_1(void)
+{
+    TEST_FAIL_MESSAGE("Not Implemented");
+}
+
+void test_sll_length_should_return_0_when_supplied_list_is_null(void)
+{
+    TEST_FAIL_MESSAGE("Not Implemented");
+}
+