User Tools

Site Tools


haas:fall2015:data:projects:dls0

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:fall2015:data:projects:dls0 [2015/11/08 13:49] – [Project Overview] wedgehaas:fall2015:data:projects:dls0 [2015/11/16 15:55] (current) – [Errata] wedge
Line 11: Line 11:
 This section will document any updates applied to the project since original release: This section will document any updates applied to the project since original release:
  
-  * __revision #__<description> (DATESTRING)+  * __revision 1__unit-cpstack was reporting incorrect status codes (20151116) 
 +    * on test 7, a copy of a populated stack, the unit test was incorrectly expecting "DLS_EMPTY | DLS_SUCCESS | DLL_EMPTY | DLL_SUCCESS", instead of "DLS_SUCCESS | DLL_SUCCESS" (FIXED)
  
 =====Objective===== =====Objective=====
Line 97: Line 98:
  
 Should you be having any lingering issues with your doubly-linked list implementation, remember that the **test reference implementation** is (and has been) available. With this, you don't have to worry about all the supporting node and list functions that aren't the focus of the project. Should you be having any lingering issues with your doubly-linked list implementation, remember that the **test reference implementation** is (and has been) available. With this, you don't have to worry about all the supporting node and list functions that aren't the focus of the project.
-====New header file: inc/data.h==== +====inc/stack.h==== 
-With the introduction of the status codes in previous projects (and stack introducing its own)I decided to break out that information into its own header file. All other header files now include **data.h**, so nothing is lost or inaccessible. +To implement a stack, we'll be creating a new type of struct. Continuing our previous patternwe'll isolate that specific information in its own header file:
- +
-Here's what's in the file:+
  
 <code c> <code c>
-#ifndef  _DATA_H +#ifndef _STACK_H 
-#define  _DATA_H+#define _STACK_H
  
-// Status codes for the doubly linked list implementation+//////////////////////////////////////////////////////////////////////
 // //
-#define  DLL_SUCCESS        0 +// Stack relies on list (which relies on node) to work. 
-#define  DLL_MALLOC_FAIL    1 +// See the layers?
-#define  DLL_ALREADY_ALLOC +
-#define  DLL_NULL           4 +
-#define  DLL_EMPTY          8 +
-#define  DLL_DEFAULT_FAIL   64 +
-#define  DLL_FAIL           128 +
- +
-// Status codes for the stack implementation+
 // //
-#define  DLS_SUCCESS        256 +#include "list.h"
-#define  DLS_CREATE_FAIL    512 +
-#define  DLS_NULL           1024 +
-#define  DLS_EMPTY          2048 +
-#define  DLS_OVERFLOW       4096 +
-#define  DLS_UNDERFLOW      8192 +
-#define  DLS_DEFAULT_FAIL   16384 +
-#define  DLS_FAIL           32768+
  
-// Status codes for the list's display() function modes+//////////////////////////////////////////////////////////////////////
 // //
-#define  DISPLAY_FORWARD    0           // display list forward +// Define the stack struct
-#define  DISPLAY_POSLESS    0           // display list without position indices +
-#define  DISPLAY_ASVALUE    0           // display list data in numeric form +
-#define  DISPLAY_WITHPOS    1           // display list with position indices +
-#define  DISPLAY_REVERSE    2           // display list in reverse order +
-#define  DISPLAY_INASCII    4           // display list data in ASCII form +
- +
-// custom types (mostly for shortening typing)+
 // //
-typedef unsigned short int  code_t;     // status code data type +struct stack { 
-typedef unsigned long int   uli;        // shorter than typing 'unsigned long int' +    Node              *top           // pointer to top of stack 
- +    List              *data          // pointer to stack data 
-#endif +    ulli               size          // size of stack
-</code> +
- +
-In addition to the status codes (for list and stack), we also see new defines for display(), better visualizing the numeric modes. +
- +
-Finally, there's two new typedefs to create shortcut types (to save on long typing, throwing off alignment of code): +
- +
-  * **code_t** - basically just an unsigned short int, and will expand upon the status codes explored in the dll projects (to include stack status codes too). +
-  * **uli** - nothing short of a shortcut: an unsigned long int. +
- +
-====In inc/list.h==== +
-There is one change (an addition) that has been made to **list.h**, and that is the return of the **qty** element: +
- +
-<code c> +
-struct list +
-    Node              *first          // pointer to start of list +
-    Node              *last           // pointer to end of list +
-    uli                qty            // count of nodes in list+
 }; };
-typedef struct list    List;            // because we deserve nice things 
-</code> 
  
-We're also taking advantage of our new "uli" typedef, as you can see **qty** is defined as a **uli** type.+code_t  mkstack(Stack **, ulli);       // create new stack of size 
 +code_t  cpstack(Stack  *, Stack **);   // duplicate stack 
 +code_t  rmstack(Stack **);             // deallocate stack
  
-It should be noted (and stressed) that the utilization of **qty** should JUST be in maintaining a count. You need not re-implement or change the logic of any of your list functionality to base its operations or to rely on **qty** in any way (just as beforeif you do you'll lose credit).+code_t  push   (Stack **, Node   *);   // add new node onto stack 
 +code_t  pop    (Stack **, Node  **);   // grab node off of stack 
 +code_t  peek   (Stack  *Node  **);   // show top node of stack
  
-From the list's point of view, its sole purpose is for show.+code_t  isempty(Stack  *);             // check stack emptiness
  
-With that said, you likely only have to make changes to 4 functions in order to appropriately accommodate **qty**-- any low-level list operation that is responsible for initializing, adding, or taking nodes out of the list (creating, inserting, appending, obtaining). 
- 
-You may make use of the **qty** element to streamline your **display()** function's reverse list with index option. 
-====In inc/stack.h==== 
- 
-<code c 1> 
-#ifndef _STACK_H 
-#define _STACK_H 
- 
-#include "data.h"                    // helpful #defines 
-#include "list.h"                    // stack relies on list to work 
-                                     // (which relies on node) 
- 
-struct stack { 
-    List             *data;          // pointer to list containing data 
-    Node             *top;           // pointer to node at top of stack 
-    uli               size;          // maximum stack size (0 implies 
-};                                   // an unbounded stack) 
-typedef struct stack  Stack;         // because we deserve nice things 
- 
-code_t mkstack(Stack **, uli);       // create new stack (of max size) 
-code_t cpstack(Stack *, Stack **);   // create a copy of an existing stack 
-code_t rmstack(Stack **);            // clear and de-allocate an existing stack 
- 
-code_t push(Stack **, Node * );      // put new node on top of stack 
-code_t pop (Stack **, Node **);      // get (and disconnect) top node off stack 
- 
-code_t peek(Stack *,  Node **);      // get (don't disconnect) top node 
-code_t isempty(Stack *);             // determine if the stack is empty or not 
 #endif #endif
 </code> </code>
  
-For our stack implementation, just as with our doubly-linked list implementation, we will make increased used of the double pointer in order to achieve passing parameters by address.+As indicated, with stacks, suddenly a lot of the underlying details start to be abstracted away. And the total number of unique functions being created also tends to decrease. 
 + 
 +For our stack implementation, just as with our doubly-linked list implementation, we will make use of the double pointer in order to achieve passing parameters by address.
  
-This is necessary so that we can free up the return value of **push()** and **pop()** to be used for status (ie look out for stack overflows and underflows). You'll note the extensive deployment of the **code_t** type as the return value for all the stack functions (instead of lengthily having to type out "unsigned short int" in each case).+This is necessary so that we can free up the return value of **push()** and **pop()** to be used for status (ie look out for stack overflows and underflows).
  
 **peek()** and **isempty()** are being implemented as an exercise to aid in your understanding of stacks. Again, avoid their use except is a means of convenience (or to further optimize your code). The general rule of thumb is that the use of **peek()** and **isempty()** should result in shortening your code in a clear or clever way. **peek()** and **isempty()** are being implemented as an exercise to aid in your understanding of stacks. Again, avoid their use except is a means of convenience (or to further optimize your code). The general rule of thumb is that the use of **peek()** and **isempty()** should result in shortening your code in a clear or clever way.
Line 212: Line 148:
  
 In object-oriented programming, both **size** and **qty** would be **private** member variables of their respective classes, unable to be used by anything other than their respective member functions. In object-oriented programming, both **size** and **qty** would be **private** member variables of their respective classes, unable to be used by anything other than their respective member functions.
-====list library==== +====inc/data.h==== 
-Againtin **src/list/**, you are to add support for **qty** so that, just as the list's **first** and **last** maintain an accurate positioning of their respective aspects of the list, **qty** maintains a count of the total number of nodes still in the list. +With stacksthe following new information has been added to **data.h**:
- +
-===display() enhancements=== +
-You are also to implement 4 additional modes to the display() function.  +
- +
-This means you'll need to expand the current modulus divide by 4 to one of 8. +
- +
-The current modes are as follows:+
  
 <code c> <code c>
-//       modes: 0 display the list forward, no positional values +////////////////////////////////////////////////////////////////////// 
-//              1 display the list forward, with positional values +// 
-//              2 display the list backwards, no positional values +// Status codes for the doubly linked stack implementation 
-//              3 display the list backwards, with positional values+// 
 +#define  DLS_SUCCESS         0x0000000001000000 
 +#define  DLS_CREATE_FAIL     0x0000000002000000 
 +#define  DLS_NULL            0x0000000004000000 
 +#define  DLS_EMPTY           0x0000000008000000 
 +#define  DLS_OVERFLOW        0x0000000010000000 
 +#define  DLS_UNDERFLOW       0x0000000020000000 
 +#define  DLS_ERROR           0x0000000040000000 
 +#define  DLS_INVALID         0x0000000080000000 
 +#define  DLS_DEFAULT_FAIL    0x0000000000804000
 </code> </code>
  
-The new modes are (you may want to add these comments to your **display.c** file):+__**Technical note**__: Due to space constraints (there are 9 stack status codes), you'll notice **DLS_DEFAULT_FAIL** is not a unique number, but a combination of two previous values. This is made possible by using two values that should never be regularly occurring, and especially not in combination**DLN_DEFAULT_FAIL** and **DLL_DEFAULT_FAIL**. I had to employ a similar trick with queues, which you'll see in next week's project.
  
-<code c> 
-//          4 display the list forward, no positional values, in ASCII 
-//          5 display the list forward, with positional values, in ASCII 
-//          6 display the list backwards, no positional values, in ASCII 
-//          7 display the list backwards, with positional values, in ASCII 
-</code> 
  
-What has changed? In modes 4-7, instead of displaying the numeric value contained in the node's data element, you are instead to represent it as its ASCII character. 
  
-For example, if there was a numeric 65 stored in the node , in the mode 4-7 representation, an 'A' should instead be displayed. 
- 
-==display() output examples based on mode== 
-Let's say we have a list with the following elements: 
- 
-  first -> 51 -> 49 -> 51 -> 51 -> 55 -> NULL 
- 
-==mode 0: forward, no positions, as numbers== 
-<cli> 
-51 -> 49 -> 51 -> 51 -> 55 -> NULL 
-</cli> 
- 
-==mode 1: forward, with positions, as numbers== 
-<cli> 
-[0] 51 -> [1] 49 -> [2] 51 -> [3] 51 -> [4] 55 -> NULL 
-</cli> 
- 
-==mode 4: forward, no positions, in ASCII== 
-<cli> 
-'3' -> '1' -> '3' -> '3' -> '7' -> NULL 
-</cli> 
- 
-==mode 5: forward, with positions, in ASCII== 
-<cli> 
-[0] '3' -> [1] '1' -> [2] '3' -> [3] '3' -> [4] '7' -> NULL 
-</cli> 
- 
- 
-====List Library unit tests==== 
-As a result of the required changes to **display()** and the incorporation of **qty**, pertinent list unit tests will be enhanced, so you can make use of them to ensure implementation compliance. 
- 
-The pertinent list unit tests have been updated. You only need to focus on the following for the list library (remaining list functions need no changes): 
- 
-  * unit-mklist.c 
-  * unit-append.c 
-  * unit-insert.c 
-  * unit-obtain.c 
-  * unit-display.c 
- 
-The **verify-list.sh** script has been updated to display just these updated unit tests. 
  
 ====stack library==== ====stack library====
Line 296: Line 187:
   * **DLS_CREATE_FAIL** - memory allocation failed (considered in error)   * **DLS_CREATE_FAIL** - memory allocation failed (considered in error)
   * **DLS_NULL** - result is NULL (probably in error)   * **DLS_NULL** - result is NULL (probably in error)
-  * **DLS_EMPTY** - result is an empty list (may or may not be in error)+  * **DLS_EMPTY** - result is an empty list/stack (may or may not be in error)
   * **DLS_OVERFLOW** - operation exceeds allocated size of list (may be considered an error)   * **DLS_OVERFLOW** - operation exceeds allocated size of list (may be considered an error)
   * **DLS_UNDERFLOW** - operation cannot proceed due to lack of data (may be considered an error)   * **DLS_UNDERFLOW** - operation cannot proceed due to lack of data (may be considered an error)
   * **DLS_DEFAULT_FAIL** - default state of unimplemented functions (default error)   * **DLS_DEFAULT_FAIL** - default state of unimplemented functions (default error)
-  * **DLS_FAIL** - some error occurred+  * **DLS_ERROR** - some error occurred 
 +  * **DLS_INVALID** - invalid state (pointer to stack does not exist)
  
 For example, in the case of "DLS_CREATE_FAIL", there are actually a total of three states raised: For example, in the case of "DLS_CREATE_FAIL", there are actually a total of three states raised:
-  * DLS_FAIL (a problem has occurred)+  * DLS_ERROR (a problem has occurred)
   * DLS_CREATE_FAIL (a problem has occurred when using malloc())   * DLS_CREATE_FAIL (a problem has occurred when using malloc())
   * DLS_NULL (no memory allocated, so stack cannot be anything but NULL)   * DLS_NULL (no memory allocated, so stack cannot be anything but NULL)
  
-ALL THREE states must be returned from the function in question should such an occurrence take place+ALL THREE states must be returned from the function in question should such an occurrence take place (in additionvarious underlying list and node status codes may be present as well-- see the unit tests for more information).
- +
-It is also intended that when handling stack status codesany list status codes will also be present (that is why **code_t** is a short int, whereas the list status code was a char-- we have twice the amount of bytes for status code storage now-- lower 8-bits for list, upper 8-bits for stack). +
 ====Stack library unit tests==== ====Stack library unit tests====
 In **testing/stack/unit/**, you will find these files: In **testing/stack/unit/**, you will find these files:
Line 349: Line 238:
 It is also highly recommended to undertake as it will give you further experience working with these concepts. It is also highly recommended to undertake as it will give you further experience working with these concepts.
  
-Note this is a DIFFERENT approach than you would have taken in the program with sll2- you're to use stack functionality to aid you with the heavy lifting. While you will still make use of list functionality for grabbing the initial input, the actual palindrome comparison processing needs to heavily involve stacks.+Note this is a DIFFERENT approach than you would have taken in the program with sll2 and dll1- you're to use stack functionality to aid you with the heavy lifting. You should not be directly using any list functions in the implementation of this solution, except perhaps in the initial building of the input string (otherwise use the stackand let the stack use the list functions).
  
 =====Expected Results===== =====Expected Results=====
-To assist you in verifying a correct implementation, a fully working implementation of the node, list, and stack libraries should resemble the following (when running the respective verify script): +To assist you in verifying a correct implementation, you can check your implementation against the results of my implementation:
- +
-====node library==== +
-Here is what you should get for node: +
- +
-<cli> +
-lab46:~/src/data/dls0$ 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/dls0$  +
-</cli> +
- +
-As no coding changes were needed in the node library, these results should be identical to that of a fully functioning node implementation from the **dll0** project. +
- +
-====list library==== +
-Here is what you should get for list: +
- +
-<cli> +
-lab46:~/src/data/dls0$ bin/verify-list.sh  +
-==================================================== +
-=    Verifying Doubly-Linked List Functionality    = +
-==================================================== +
-  [mklist] Total:  15, Matches:  15, Mismatches:   0 +
-  [append] Total:  40, Matches:  40, Mismatches:   0 +
-  [insert] Total:  41, Matches:  41, Mismatches:   0 +
-  [obtain] Total:  70, Matches:  70, Mismatches:   0 +
- [display] Total:  28, Matches:  28, Mismatches:   0 +
-==================================================== +
- [RESULTS] Total: 194, Matches: 194, Mismatches:   0 +
-==================================================== +
-lab46:~/src/data/dls0$  +
-</cli> +
- +
-Due to the re-introduction of **qty** into list (impacting actions performed by **mklist()**, **append()**, **insert()**, and **obtain()**), along with feature additions to **display()**, those functions saw additional tests performed, so our original max total of **102** from **dll0** has now changed to **140** (ie various **qty** and **display()**-related tests adding to the previous total). +
- +
-Remember though- aside from the minor change of adding **qty** and enhancing **display()**, all remaining list functions need no change (and **mklist()/append()/insert()/obtain()** remained largely unchanged).+
  
 ====stack library==== ====stack library====
Line 400: Line 247:
  
 <cli> <cli>
-lab46:~/src/data/dls0$ bin/verify-stack.sh +lab46:~/src/data/dls0$ make check 
-=================================================== +====================================================== 
-  Verifying Doubly-Linked Stack Functionality   +   Verifying Doubly-Linked Stack Functionality     
-=================================================== +====================================================== 
-[mkstack] Total:   6, Matches:   6, Mismatches:   0 +   [mkstack] Total:   9, Matches:   9, Mismatches:   0 
-[cpstack] Total:  12, Matches:  12, Mismatches:   0 +      [push] Total:  18, Matches:  18, Mismatches:   0 
-[rmstack] Total:   6, Matches:   6, Mismatches:   0 +       [pop] Total:  19, Matches:  19, Mismatches:   0 
-   [push] Total:  30, Matches:  30, Mismatches:   0 +   [cpstack] Total:  11, Matches:  11, Mismatches:   0 
-    [pop] Total:  25, Matches:  25, Mismatches:   0 +      [peek] Total:  20, Matches:  20, Mismatches:   0 
-   [peek] Total:  37, Matches:  37, Mismatches:   0 +   [isempty] Total:   5, Matches:   5, Mismatches:   0 
-[isempty] Total:  13, Matches:  13, Mismatches:   0 +   [rmstack] Total:  10, Matches:  10, Mismatches:   0 
-=================================================== +====================================================== 
-[RESULTS] Total: 129, Matches: 129, Mismatches:   0 +   [RESULTS] Total:  92, Matches:  92, Mismatches:   0 
-=================================================== +====================================================== 
 lab46:~/src/data/dls0$  lab46:~/src/data/dls0$ 
 </cli> </cli>
-=====Submission Criteria===== +=====Submission===== 
-To be successful in this project, the following criteria must be met:+{{page>haas:fall2015:common:submitblurb#DATA&noheader&nofooter}}
  
-  * Project must be submit on time, by the posted deadline. 
-    * Late submissions will lose 25% credit per day, with the submission window closing on the 4th day following the deadline. 
-  * All code must compile cleanly (no warnings or errors) 
-    * all requested functions must be implemented in the related library 
-    * all requested functionality must conform to stated requirements (either on this project page or in comment banner in source code files themselves). 
-  * Executed programs must display in a manner similar to provided output 
-    * output formatted, where applicable, must match that of project requirements 
-  * Processing must be correct based on input given and output requested 
-  * Output, if applicable, must be correct based on values input 
-  * Code must be nicely and consistently indented (you may use the **indent** tool) 
-  * Code must be commented 
-    * Any "to be implemented" comments **MUST** be removed 
-      * these "to be implemented" comments, if still present at evaluation time, will result in points being deducted. 
-    * Sufficient comments explaining the point of provided logic **MUST** be present 
-  * Track/version the source code in a repository 
-  * Submit a copy of your source code to me using the **submit** tool (**make submit** will do this) by the deadline. 
haas/fall2015/data/projects/dls0.1446990540.txt.gz · Last modified: 2015/11/08 13:49 by wedge