User Tools

Site Tools


haas:summer2015:data:projects:dll0

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
haas:summer2015:data:projects:dll0 [2015/05/29 14:53] – [Errata] wedgehaas:summer2015:data:projects:dll0 [2015/06/27 20:30] (current) – [list library] wedge
Line 14: Line 14:
  
 =====Objective===== =====Objective=====
-In this project, we take our first opportunity to undergo a complete code re-write of linked list functionalitywhile we implement our first doubly linked list. +In this project, we continue our doubly-linked code re-write, this time focusing on the linked list. 
- +=====Procedure to obtain dll0===== 
-=====Procedure to Obtain dll0===== +As dll0 utilizes the code generated in dln0, transitioning to this project is merely a matter of upgrading:
-As this is a rewrite, dll0 is not based on any of the code you have written up to this point. As such, the transition process is slightly different:+
  
 <cli> <cli>
-lab46:~/src/data/sll3$ make get-dll0+lab46:~/src/data/dln0$ make upgrade-dll0
 ... ...
 </cli> </cli>
  
-The "get-" functionality is distinct from the "upgrade-" you have been using to transition between the sll* projects. When you upgrade, your existing code is copied over, because the next project builds upon what you did previously.+When you upgrade, your existing code is copied over, because the next project builds upon what you did previously.
  
-But when you "get" dll0, you are getting an entirely new project skeleton- NONE of your existing code is copied over (the structure has changed enough where copying your own code would have been rather problematic). +Once you run "**make upgrade-dll0**" you should have a **dll0** directory that you can access and commence working on just as you have with the other project directories.
- +
-Once you run "**make get-dll0**" you should have a **dll0** directory that you can access and commence working on just as you have with the other project directories.+
 =====Project Overview===== =====Project Overview=====
  
 For this project, we're going to be re-implementing MOST of the previous node and list functions. There have been a few changes, namely: For this project, we're going to be re-implementing MOST of the previous node and list functions. There have been a few changes, namely:
  
-====In inc/node.h==== 
-<code c 1> 
-#ifndef _NODE_H 
-#define _NODE_H 
- 
-#include <stdlib.h> 
- 
-struct node { 
-        char         value; 
-        struct node *after; 
-        struct node *prior; 
-}; 
-typedef struct node Node; 
- 
-Node *mknode(char  );     // allocate new node containing value 
-Node *cpnode(Node *);     // duplicate node 
-Node *rmnode(Node *);     // deallocate node 
- 
-#endif 
-</code> 
- 
-There is an addition of a "prior" node pointer, to allow connections to our previous neighbors. 
- 
-The node info element has been renamed to "value", just to make sure you understand what is going on code-wise. 
  
 ====In inc/list.h==== ====In inc/list.h====
Line 64: Line 37:
 #define _LIST_H #define _LIST_H
  
-#include "node.h"                       // list relies on node to work +#include "node.h"                          // list relies on node to work
- +
-#define  DLL_SUCCESS            0 +
-#define  DLL_MALLOC_FAIL        1 +
-#define  DLL_ALREADY_ALLOC      2 +
-#define  DLL_NULL               4 +
-#define  DLL_EMPTY              8 +
-#define  DLL_DEFAULT_FAIL       64 +
-#define  DLL_FAIL               128+
  
 struct list { struct list {
-    Node              *first;           // pointer to start of list +    Node              *first;              // pointer to start of list 
-    Node              *last;            // pointer to end of list+    Node              *last;               // pointer to end of list
 }; };
-typedef struct list    List;            // because we deserve nice things 
  
-int mklist (List **);                   // create/allocate new list struct +code_t  mklist (List **);                  // create new list struct 
-int cplist (List *,  List **);          // duplicate list contents +code_t  cplist (List  *, List **);         // duplicate list contents 
  
-int insert (List **, Node *, Node *);   // add node before given node +code_t  insert (List **, Node *, Node  *); // add node before given node 
-int append (List **, Node *, Node *);   // add node after given node+code_t  append (List **, Node *, Node  *); // add node after given node
  
-int display(List *,  int);              // display list from start to end +code_t  display(List  *, int);             // display list start to end 
-int find   (List *,  int,    Node **);  // locate node containing value+code_t  find   (List  *, int,    Node **); // locate node with value
  
 #endif #endif
 </code> </code>
  
-The following changes have taken place:+The following changes have taken place from the singly-linked list implementation:
  
   * **qty** has been removed from the list   * **qty** has been removed from the list
Line 99: Line 63:
   * **displayf()/displayb()** are gone, and previous functionality will be merged into one universal **display()** function.    * **displayf()/displayb()** are gone, and previous functionality will be merged into one universal **display()** function. 
  
-There is now a set of status/error codes that will be utilized as list function return values, so we can better report particular failures.+Just as with the doubly-linked node, there are now a set of status/error codes that will be utilized as list function return values, so we can better report particular failures.
  
 +====In inc/data.h====
 +In addition to what was there previously, we see the following:
 +
 +<code c 1>
 +// Status codes for the doubly linked list implementation
 +//
 +#define  DLL_SUCCESS         0x0000000000000100
 +#define  DLL_MALLOC_FAIL     0x0000000000000200
 +#define  DLL_ALREADY_ALLOC   0x0000000000000400
 +#define  DLL_NULL            0x0000000000000800
 +#define  DLL_ERROR           0x0000000000001000
 +#define  DLL_DEFAULT_FAIL    0x0000000000002000
 +#define  DLL_EMPTY           0x0000000000004000
 +#define  DLL_INVALID         0x0000000000008000
 +</code>
 +
 +Similar in many ways to the doubly-linked node status codes, we see a new possibility: EMPTY. This is the state of a list existing but having no nodes associated with it (which you should already be familiar with). Whenever this state exists, that status code MUST be set in the respective function being called (so, the list as a result of the function processing leaves us with an empty list).
 ====list operation status codes==== ====list operation status codes====
 You'll notice the presence of a set of #define's in the list header file. These are intended to be used to report on various states of list status after performing various operations. You'll notice the presence of a set of #define's in the list header file. These are intended to be used to report on various states of list status after performing various operations.
Line 112: Line 93:
   * **DLL_EMPTY** - result is an empty list (may or may not be in error)   * **DLL_EMPTY** - result is an empty list (may or may not be in error)
   * **DLL_DEFAULT_FAIL** - default state of unimplemented functions (default error)   * **DLL_DEFAULT_FAIL** - default state of unimplemented functions (default error)
-  * **DLL_FAIL** - some error occurred+  * **DLL_ERROR** - some error occurred 
 +  * **DLL_INVALID** - invalid use (passing a NULL pointer)
  
 For example, in the case of "DLL_MALLOC_FAIL", there are actually a total of three states raised: For example, in the case of "DLL_MALLOC_FAIL", there are actually a total of three states raised:
-  * DLL_FAIL (a problem has occurred)+  * DLL_ERROR (a problem has occurred)
   * DLL_MALLOC_FAIL (a problem has occurred when using malloc())   * DLL_MALLOC_FAIL (a problem has occurred when using malloc())
   * DLL_NULL (no memory allocated, so list cannot be anything but NULL)   * DLL_NULL (no memory allocated, so list cannot be anything but NULL)
Line 130: Line 112:
  
 ====List library unit tests==== ====List library unit tests====
-In **testing/list/unit/**, you will find these new files:+In **unit/list/**, you will find these new files:
  
   * **unit-mklist.c** - unit test for **mklist()** library function   * **unit-mklist.c** - unit test for **mklist()** library function
Line 160: Line 142:
 To assist you in verifying a correct implementation, a fully working implementation of the node and list libraries should resemble the following (when running the respective verify script): To assist you in verifying a correct implementation, a fully working implementation of the node and list libraries should resemble the following (when running the respective verify script):
  
-====node library==== 
-Here is what you should get for node: 
- 
-<cli> 
-lab46:~/src/data/dll0$ bin/verify-node.sh  
-==================================================== 
-=    Verifying Doubly-Linked Node Functionality    = 
-==================================================== 
-  [mknode] Total:   5, Matches:   5, Mismatches:   0 
-  [cpnode] Total:   6, Matches:   6, Mismatches:   0 
-  [rmnode] Total:   2, Matches:   2, Mismatches:   0 
-==================================================== 
- [RESULTS] Total:  13, Matches:  13, Mismatches:   0 
-==================================================== 
-lab46:~/src/data/dll0$  
-</cli> 
  
 ====list library==== ====list library====
Line 185: Line 151:
 =    Verifying Doubly-Linked List Functionality    = =    Verifying Doubly-Linked List Functionality    =
 ==================================================== ====================================================
-  [mklist] Total:  11, Matches:  11, Mismatches:   0 +  [mklist] Total:  12, Matches:  12, Mismatches:   0 
-  [cplist] Total:  17, Matches:  17, Mismatches:   0 +  [cplist] Total:  18, Matches:  18, Mismatches:   0 
-  [append] Total:  22, Matches:  22, Mismatches:   0 +  [append] Total:  36, Matches:  36, Mismatches:   0 
-  [insert] Total:  22, Matches:  22, Mismatches:   0+  [insert] Total:  36, Matches:  36, Mismatches:   0
  [display] Total:  12, Matches:  12, Mismatches:   0  [display] Total:  12, Matches:  12, Mismatches:   0
     [find] Total:  28, Matches:  28, Mismatches:   0     [find] Total:  28, Matches:  28, Mismatches:   0
 ==================================================== ====================================================
- [RESULTS] Total: 112, Matches: 112, Mismatches:   0+ [RESULTS] Total: 142, Matches: 142, Mismatches:   0
 ==================================================== ====================================================
 lab46:~/src/data/dll0$  lab46:~/src/data/dll0$ 
haas/summer2015/data/projects/dll0.1432911227.txt.gz · Last modified: 2015/05/29 14:53 by wedge