SlideShare uma empresa Scribd logo
1 de 24
Baixar para ler offline
i
Concordance Project
Mark L. Short
Version 1
11/12/2014 2:24:00 PM
ii
iii
Table of Contents
Main Page......................................................................................................................................................................2
Class Index ....................................................................................................................................................................4
File Index.......................................................................................................................................................................5
Class Documentation.....................................................................................................................................................6
sorted_list< _Ty >......................................................................................................................................................6
File Documentation .....................................................................................................................................................11
Concordance/Concordance.cpp ...............................................................................................................................11
Concordance/SortedList.h .......................................................................................................................................16
Concordance/stdafx.cpp...........................................................................................................................................17
Concordance/stdafx.h ..............................................................................................................................................18
Concordance/targetver.h..........................................................................................................................................20
Index............................................................................................................................................................................21
1
2
Main Page
Author:
Mark L. Short
Date:
November 11, 2014
Cite: Introduction to Algorithms, Thomas H. Cormen, Charles E. Leiserson, Ronald L. Rivest,
Clifford Stein
Course: CMPS Algorithm Analysis (graduate level)
Instructor: Dr. Timothy Donovan
Assignment:
“Write a program to maintain an alphabetical list of strings. Use a linked list class to insert and
delete strings into an ordered linked list. Your application program should read a list of strings
and place them in your linked list and then print the strings out in alphabetical order. It should
read a second list of strings and delete them from the list. Finally it should print the items remaining
in the list in alpha order. Echo the input strings.”
Analysis:
'Concordance' - A Concordance is an alphabetical list of the principal words used in a book or body of
work, with their immediate contexts. http://en.wikipedia.org/wiki/Concordance_(publishing)
'Linked List' - In computer science, a linked list is a data structure consisting of a group of nodes which
together represent a sequence. Under the simplest form, each node is composed of a data and a reference
(in other words, a link) to the next node in the sequence; more complex variants add additional links.
http://en.wikipedia.org/wiki/Linked_list
'Ordered Linked List' - is a subset of 'Linked Lists' where each element is inserted into the data structure
at a specific location to maintain some ordering property of the overall collection of elements.
Brief comparison of data-structures
Operation Linked List 'Ordered'
Linked List
Array Dynamic
Array
Balanced
Tree
Searching O(n) O(n) O(1) O(1) O(log n)
Insert/Delete
(Begin/End)
O(1) O(n) na O(1) + copy O(log n)
Insert/Delete
(middle)
O(n) O(n) na O(1) + copy O(log n)
On review of the various data-structures and related algorithms available and previously covered, an
'ordered' linked-list is most likely the worst performing one to use for the implementation of a
'Concordance'.
3
Enhancements:
1. Heavy reliance and proper use of a standardize set of template classes and the extension of the STL
list template class, in a manner that would meet industry coding standards.
2. Project documentation that exceeds any academic documentation standard.
3. Use of consistent coding standards that exceed typical academic standards.
Commentary:
The topic of 'algorithm analysis' is not without criticism in the professional computing community,
especially the kind of analysis covered in this course that focuses on a very narrow spectrum of analysis
based primarily on mathematical models involving "big-O notation".
http://en.wikipedia.org/wiki/Big_O_notation
This brand of analysis feels more appropriate to those insulated in an academic environment with little
urgency to address real-world performance issues involving multi-threading, cache-awareness,
concurrency, or application scalability. In this context, 'algorithm analysis' is merely theoretical.
According to Dr. Ian Sommerville, author of the core text used in this department's software engineering
courses:
"University courses should aim to develop student's ability to think in
abstractions, to develop reliable and robust programs and to understand
the often complex relationships between hardware, software and the
organizations that use software-intensive systems."
“if we [universities] can’t recruit the most able software engineers,
it will become increasingly theoretical and out of touch with what is
going on in the world"
While the topic of implementation of a 'Concordance' is one of probable value in terms of 'algorithm
analysis', the dictates of this assignment actually forbids any actual 'algorithm analysis' activity from being
performed by the student and instead, reduces it to a mundane undergraduate-level exercise of coding an
ordered linked-list; an implementation that would never survive any level of scrutiny of a formal source-
code review or walk-through in the professional community in terms of providing respectable application
performance.
Additionally, it goes further by invalidating the course through a complete disregard of any algorithm
performance analysis on the project and mandating the implementation and use of possibly the very worst
performing data-structure in this instance.
This assignment is not only "out of touch" with the world, but is "out of touch" with the course text, the
course lectures and very essence of the course instruction it was meant to reinforce.
While I am extremely critical of this assignment, I equally bear the burden of a failure to 'read the fine-
print' and catching the details in time to raise my objections earlier.
4
Class Index
Class List
Here are the classes, structs, unions and interfaces with brief descriptions:
sorted_list< _Ty > (The sorted_list class template is an extension of the STL list class template to provide
a mechanism to allow an 'ordered' insert and maintain its sorted property ) .................................6
5
File Index
File List
Here is a list of all files with brief descriptions:
Concordance/Concordance.cpp (Implementation of Concordance Project ) ................................11
Concordance/SortedList.h (Implementation of Sorted List ) ..........................................................16
Concordance/stdafx.cpp (Source file that includes just the standard includes ) ...........................17
Concordance/stdafx.h (Application header file ) ..............................................................................18
Concordance/targetver.h (Windows OS platform header file ) ......................................................20
6
Class Documentation
sorted_list< _Ty > Class Template Reference
The sorted_list class template is an extension of the STL list class template to provide a mechanism
to allow an 'ordered' insert and maintain its sorted property.
#include <SortedList.h>
Public Member Functions
 sorted_list ()
Default constructor.
 bool empty (void) const
Time complexity is O(1).
 size_type size (void) const throw ()
Time complexity is O(1).
 iterator begin () throw ()
 const_iterator begin () const throw ()
 iterator end () throw ()
 const_iterator end () const throw ()
 bool ordered_insert (const _Ty &_Val)
ordered_insert performs a linear search of the list for the _Val and inserts at the correct location if not found.
 bool remove (const _Ty &_Val)
remove performs a linear search of list for _Val and removes it if found.
Detailed Description
template<class _Ty>class sorted_list< _Ty >
The sorted_list class template is an extension of the STL list class template to provide a mechanism
to allow an 'ordered' insert and maintain its sorted property.
It is not generally a good idea to inherit from an STL class template, which requires containment
in the alternative.
Constructor & Destructor Documentation
template<class _Ty> sorted_list< _Ty >::sorted_list ()[inline]
Default constructor.
Definition at line 43 of file SortedList.h.
44 : m_list()
45 { };
7
Member Function Documentation
template<class _Ty> iterator sorted_list< _Ty >::begin () throw ) [inline]
Return values:
returns iterator for beginning of mutable sequence
Definition at line 67 of file SortedList.h.
Referenced by _tmain().
68 { return m_list.begin(); };
template<class _Ty> const_iterator sorted_list< _Ty >::begin () const throw ) [inline]
Return values:
returns iterator for beginning of nonmutable sequence
Definition at line 74 of file SortedList.h.
75 { return m_list.begin(); };
template<class _Ty> bool sorted_list< _Ty >::empty (void ) const[inline]
Time complexity is O(1).
Return values:
returns true if container is empty
Definition at line 52 of file SortedList.h.
Referenced by sorted_list< _Ty >::ordered_insert().
53 { return m_list.empty(); };
template<class _Ty> iterator sorted_list< _Ty >::end () throw ) [inline]
Return values:
returns iterator for end of mutable sequence
Definition at line 81 of file SortedList.h.
Referenced by _tmain().
82 { return m_list.end(); };
template<class _Ty> const_iterator sorted_list< _Ty >::end () const throw ) [inline]
Return values:
returns iterator for end of nonmutable sequence
Definition at line 88 of file SortedList.h.
89 { return m_list.end(); };
8
template<class _Ty> bool sorted_list< _Ty >::ordered_insert (const _Ty & _Val)[inline]
ordered_insert performs a linear search of the list for the _Val and inserts at the correct location if not found.
Time complexity is O(n).
Parameters:
in _Val data item to be inserted
Return values:
returns true if _Val was inserted
Definition at line 100 of file SortedList.h.
References sorted_list< _Ty >::empty().
Referenced by _tmain().
101 {
102 bool bResult = false;
103
104 if ( empty ( ) )
105 {
106 m_list.push_back ( _Val );
107 bResult = true;
108 }
109 else
110 { // now we get to traverse the list to see if we find _Val
111 bool bFound = false;
112 for ( iterator it = m_list.begin ( ); it != m_list.end ( ); ++it )
113 {
114 if ( _Val == *it )
115 { // item found, cannot insert a duplicate
116 bFound = true;
117 break;
118 }
119 else if ( _Val < *it )
120 {
121 m_list.insert(it, _Val);
122 bResult = true;
123 break;
124 }
125 }
126 // has item been found or inserted yet?
127 if ((bFound == false) && (bResult == false))
128 { // if not then push it on the end of the ordered_list
129 m_list.push_back(_Val);
130 bResult = true;
131 }
132 }
133
134 return bResult;
135 };
Here is the call graph for this function:
9
template<class _Ty> bool sorted_list< _Ty >::remove (const _Ty & _Val)[inline]
remove performs a linear search of list for _Val and removes it if found.
Time complexity is O(n).
Parameters:
in _Val data item to be removed
Return values:
returns true if _Val was found and removed
Definition at line 145 of file SortedList.h.
Referenced by _tmain().
146 {
147 bool bReturn = false;
148 // erase each element matching _Val
149 iterator _Val_it = m_list.end ( );
150
151 for ( iterator _First = m_list.begin ( ); _First != m_list.end ( ); )
152 {
153 if ( *_First == _Val )
154 {
155 if ( std::addressof ( *_First ) == std::addressof ( _Val ) )
156 {
157 _Val_it = _First++;
158 }
159 else
160 {
161 _First = m_list.erase ( _First );
162 bReturn = true;
163 }
164 }
165 else
166 {
167 ++_First;
168 }
169 }
170
171 if ( _Val_it != m_list.end ( ) )
172 {
173 m_list.erase ( _Val_it );
174 bReturn = true;
175 }
176
177 return bReturn;
178 }
10
template<class _Ty> size_type sorted_list< _Ty >::size (void ) const throw ) [inline]
Time complexity is O(1).
Return values:
returns number of elements in the sequence
Definition at line 60 of file SortedList.h.
61 { return m_list.size(); };
The documentation for this class was generated from the following file:
 Concordance/SortedList.h
11
File Documentation
Concordance/Concordance.cpp File Reference
Implementation of Concordance Project.
#include "stdafx.h"
#include "SortedList.h"
#include <fstream>
#include <vector>
#include <string>
#include <cctype>
Include dependency graph for Concordance.cpp:
Typedefs
 typedef sorted_list< std::string > sortedStringList
Functions
 size_t LoadData (const TCHAR *szFileName, std::vector< std::string > &vArray)
LoadData reads input data from text file and returns contents in an STL vector.
 template<class _FwdIt > void printMembers (_FwdIt _itBegin, _FwdIt _itEnd)
printMembers outputs the contents of a range of STL iterators to standard out.
 int _tmain (int argc, _TCHAR *argv[])
_tmain is the main entry point for the application.
Variables
 const TCHAR g_szDataFileName_1 [] = _T ( "passage1.txt" )
 const TCHAR g_szDataFileName_2 [] = _T ( "passage2.txt" )
Detailed Description
Implementation of Concordance Project.
Definition in file Concordance.cpp.
12
Typedef Documentation
typedef sorted_list<std::string> sortedStringList
Definition at line 116 of file Concordance.cpp.
Function Documentation
int _tmain (int argc, _TCHAR * argv[])
_tmain is the main entry point for the application.
Definition at line 180 of file Concordance.cpp.
References sorted_list< _Ty >::begin(), sorted_list< _Ty >::end(), g_szDataFileName_1, g_szDataFileName_2,
LoadData(), sorted_list< _Ty >::ordered_insert(), printMembers(), sorted_list< _Ty >::remove(), and tcout.
181 {
182 typedef std::vector<std::string>::iterator itDataSet;
183
184 sortedStringList lstConcordance;
185
186 std::vector<std::string> vDataSet_1;
187 std::vector<std::string> vDataSet_2;
188
189 // have the vectors pre-allocate enough storage for 256 elements
190 // in order to minimize any reallocations needed as for the subsequent
191 // 'LoadData' methods.
192 vDataSet_1.reserve ( 256 );
193 vDataSet_2.reserve ( 256 );
194
195 // lets read in the program data from the text files
196 size_t nStringsLoaded_1 = LoadData ( g_szDataFileName_1, vDataSet_1 );
197 size_t nStringsLoaded_2 = LoadData ( g_szDataFileName_2, vDataSet_2 );
198
199 // print content of Data Set 1
200 tcout << _T ( "S1: (unordered) set of input strings" ) << std::endl;
201 tcout << _T ( "-----------------------------------------------------" ) << std::endl;
202 printMembers ( vDataSet_1.begin ( ), vDataSet_1.end ( ) );
203 tcout << std::endl;
204
205 // begin processing data from 1st input file and insert loaded strings into the
Concordance
206 for ( itDataSet it = vDataSet_1.begin ( ); it != vDataSet_1.end ( ); ++it )
207 {
208 lstConcordance.ordered_insert ( *it );
209 }
210
211 // print the sorted, filtered content of the Concordance
212 tcout << _T ( "Concordance listing of sorted, unique strings" ) << std::endl;
213 tcout << _T ( "-----------------------------------------------------" ) << std::endl;
214 printMembers ( lstConcordance.begin ( ), lstConcordance.end ( ) );
215 tcout << std::endl;
216
217 // print content of Data Set 2
218 tcout << _T ( "S2:(unordered) set of input strings" ) << std::endl;
219 tcout << _T ( " (to be removed from Concordance)" ) << std::endl;
220 tcout << _T ( "-----------------------------------------------------" ) << std::endl;
221 printMembers ( vDataSet_2.begin ( ), vDataSet_2.end ( ) );
222 tcout << std::endl;
223
224 // begin processing data from 2nd input file and remove strings from the
lstConcordance
225 for ( itDataSet it = vDataSet_2.begin(); it != vDataSet_2.end(); ++it )
226 {
227 lstConcordance.remove ( *it );
13
228 }
229
230 // print the final content of the Concordance
231 tcout << _T ( "Concordance (updated) listing of sorted, unique strings" ) <<
std::endl;
232 tcout << _T ( " (after removal of S2)" ) <<
std::endl;
233 tcout << _T ( "-----------------------------------------------------" ) <<
std::endl;
234 printMembers ( lstConcordance.begin ( ), lstConcordance.end ( ) );
235 tcout << std::endl;
236
237 return 0;
238 }
Here is the call graph for this function:
14
size_t LoadData (const TCHAR * szFileName, std::vector< std::string > & vArray)
LoadData reads input data from text file and returns contents in an STL vector.
Parameters:
in szFileName name of the data file to be loaded
out vArray reference to an STL vector of strings
Return values:
returns the number of items read into the vector
Definition at line 129 of file Concordance.cpp.
References tcout.
Referenced by _tmain().
130 {
131 size_t nReturn = 0;
132
133 std::ifstream infile;
134
135 infile.open ( szFileName );
136
137 if ( infile.bad ( ) )
138 {
139 tcout << _T ( "Error opening data file:" ) << szFileName << std::endl;
140 }
141 else
142 {
143 std::string stringData;
144 // process the data
145 while ( infile >> stringData )
146 {
147 // check last char for trailing punctuation to remove
148 size_t nLen = stringData.length();
149 if ( (nLen > 1) && (std::ispunct(stringData[nLen - 1])) )
150 stringData.resize(nLen - 1);
151
152 vArray.push_back ( stringData );
153 nReturn++;
154 }
155
156 infile.close ( );
157 }
158
159 return nReturn;
160 }
15
template<class _FwdIt > void printMembers (_FwdIt _itBegin, _FwdIt _itEnd)
printMembers outputs the contents of a range of STL iterators to standard out.
Definition at line 167 of file Concordance.cpp.
References tcout.
Referenced by _tmain().
168 {
169 int iLineCtr = 1;
170 for ( _FwdIt it = _itBegin; it != _itEnd; ++it )
171 {
172 std::string& str = *it;
173 tcout << std::setw(4) << iLineCtr++ << _T(") ") << str.c_str() << std::endl;
174 }
175 }
Variable Documentation
const TCHAR g_szDataFileName_1[] = _T ( "passage1.txt" )
Definition at line 118 of file Concordance.cpp.
Referenced by _tmain().
const TCHAR g_szDataFileName_2[] = _T ( "passage2.txt" )
Definition at line 119 of file Concordance.cpp.
Referenced by _tmain().
16
Concordance/SortedList.h File Reference
Implementation of Sorted List.
#include <list>
Include dependency graph for SortedList.h:
This graph shows which files directly or indirectly include this file:
Classes
 class sorted_list< _Ty >
The sorted_list class template is an extension of the STL list class template to provide a mechanism to allow an
'ordered' insert and maintain its sorted property.
Detailed Description
Implementation of Sorted List.
Author:
Mark L. Short
Date:
November 11, 2014
Definition in file SortedList.h.
17
Concordance/stdafx.cpp File Reference
Source file that includes just the standard includes.
#include "stdafx.h"
Include dependency graph for stdafx.cpp:
Detailed Description
Source file that includes just the standard includes.
Concordance.pch will be the pre-compiled header stdafx.obj will contain the pre-compiled type information
Author:
Mark L. Short
Date:
November 11, 2014
Definition in file stdafx.cpp.
18
Concordance/stdafx.h File Reference
Application header file.
#include "targetver.h"
#include <stdio.h>
#include <tchar.h>
#include <string>
#include <iostream>
#include <iomanip>
Include dependency graph for stdafx.h:
This graph shows which files directly or indirectly include this file:
Macros
 #define _CRT_SECURE_NO_WARNINGS
 #define tcout std::cout
 #define tstring std::string
Detailed Description
Application header file.
Include file for standard system include files, or project specific include files that are used frequently, but
are changed infrequently
Author:
Mark L. Short
Date:
November 11, 2014
19
Definition in file stdafx.h.
Macro Definition Documentation
#define _CRT_SECURE_NO_WARNINGS
Definition at line 17 of file stdafx.h.
#define tcout std::cout
Definition at line 38 of file stdafx.h.
Referenced by _tmain(), LoadData(), and printMembers().
#define tstring std::string
Definition at line 39 of file stdafx.h.
20
Concordance/targetver.h File Reference
Windows OS platform header file.
#include <SDKDDKVer.h>
Include dependency graph for targetver.h:
This graph shows which files directly or indirectly include this file:
Detailed Description
Windows OS platform header file.
Author:
Mark L. Short
Date:
November 11, 2014
Definition in file targetver.h.
21
Index
_CRT_SECURE_NO_WARNINGS
stdafx.h, 19
_tmain
Concordance.cpp, 12
begin
sorted_list, 7
Concordance.cpp
_tmain, 12
g_szDataFileName_1, 15
g_szDataFileName_2, 15
LoadData, 14
printMembers, 15
sortedStringList, 12
Concordance/Concordance.cpp, 11
Concordance/SortedList.h, 16
Concordance/stdafx.cpp, 17
Concordance/stdafx.h, 18
Concordance/targetver.h, 20
empty
sorted_list, 7
end
sorted_list, 7
g_szDataFileName_1
Concordance.cpp, 15
g_szDataFileName_2
Concordance.cpp, 15
LoadData
Concordance.cpp, 14
ordered_insert
sorted_list, 8
printMembers
Concordance.cpp, 15
remove
sorted_list, 9
size
sorted_list, 10
sorted_list
begin, 7
empty, 7
end, 7
ordered_insert, 8
remove, 9
size, 10
sorted_list, 6
sorted_list< _Ty >, 6
sortedStringList
Concordance.cpp, 12
stdafx.h
_CRT_SECURE_NO_WARNINGS, 19
tcout, 19
tstring, 19
tcout
stdafx.h, 19
tstring
stdafx.h, 19

Mais conteúdo relacionado

Destaque

Claude Langlois Resume 2016
Claude Langlois Resume 2016Claude Langlois Resume 2016
Claude Langlois Resume 2016Claude Langlois
 
Taller práctico 10 claves para la implementación de tendencias y enfoques inn...
Taller práctico 10 claves para la implementación de tendencias y enfoques inn...Taller práctico 10 claves para la implementación de tendencias y enfoques inn...
Taller práctico 10 claves para la implementación de tendencias y enfoques inn...William Escobar Roa
 
Presentación de250
Presentación de250Presentación de250
Presentación de250nadialelli3
 
Sistemas operativos
Sistemas operativosSistemas operativos
Sistemas operativosjairomarti
 

Destaque (8)

metallodomiki
metallodomikimetallodomiki
metallodomiki
 
FN for none accountants
FN for none accountantsFN for none accountants
FN for none accountants
 
Claude Langlois Resume 2016
Claude Langlois Resume 2016Claude Langlois Resume 2016
Claude Langlois Resume 2016
 
Taller práctico 10 claves para la implementación de tendencias y enfoques inn...
Taller práctico 10 claves para la implementación de tendencias y enfoques inn...Taller práctico 10 claves para la implementación de tendencias y enfoques inn...
Taller práctico 10 claves para la implementación de tendencias y enfoques inn...
 
Presentación de250
Presentación de250Presentación de250
Presentación de250
 
Sistemas operativos
Sistemas operativosSistemas operativos
Sistemas operativos
 
Preguntas matematicas y fisica alejandro
Preguntas matematicas y fisica alejandroPreguntas matematicas y fisica alejandro
Preguntas matematicas y fisica alejandro
 
TAREA UNIDAD II
TAREA UNIDAD IITAREA UNIDAD II
TAREA UNIDAD II
 

Semelhante a ConcordanceProject

Software architecture-patterns
Software architecture-patternsSoftware architecture-patterns
Software architecture-patternspedro
 
Software arquitectura patron diseño
Software arquitectura patron diseñoSoftware arquitectura patron diseño
Software arquitectura patron diseñopedro
 
software-architecture-patterns
software-architecture-patternssoftware-architecture-patterns
software-architecture-patternsPallav Kumar
 
If I Had a Hammer...
If I Had a Hammer...If I Had a Hammer...
If I Had a Hammer...Kevlin Henney
 
A C Frame Library User Manual And Implementation Notes
A C   Frame Library   User Manual And Implementation NotesA C   Frame Library   User Manual And Implementation Notes
A C Frame Library User Manual And Implementation NotesKate Campbell
 
Linked list basics
Linked list basicsLinked list basics
Linked list basicsRajesh Kumar
 
SchemaStudioTypeLandscape_Article.pdf
SchemaStudioTypeLandscape_Article.pdfSchemaStudioTypeLandscape_Article.pdf
SchemaStudioTypeLandscape_Article.pdfDavid Harrison
 
An Introduction to the C++ Standard Library
An Introduction to the C++ Standard LibraryAn Introduction to the C++ Standard Library
An Introduction to the C++ Standard LibraryJoyjit Choudhury
 
MBSE with Arcadia method step-by-step Logical Architecture.pdf
MBSE with Arcadia method step-by-step Logical Architecture.pdfMBSE with Arcadia method step-by-step Logical Architecture.pdf
MBSE with Arcadia method step-by-step Logical Architecture.pdfHelder Castro
 
CS8592 Object Oriented Analysis & Design - UNIT II
CS8592 Object Oriented Analysis & Design - UNIT IICS8592 Object Oriented Analysis & Design - UNIT II
CS8592 Object Oriented Analysis & Design - UNIT IIpkaviya
 
Reference Model for ISEB Certificates in Enterprise and Solution Architecture
Reference Model for ISEB  Certificates in Enterprise  and Solution ArchitectureReference Model for ISEB  Certificates in Enterprise  and Solution Architecture
Reference Model for ISEB Certificates in Enterprise and Solution ArchitectureAryashree Pritikrishna
 
Recipes 8 of Data Warehouse and Business Intelligence - Naming convention tec...
Recipes 8 of Data Warehouse and Business Intelligence - Naming convention tec...Recipes 8 of Data Warehouse and Business Intelligence - Naming convention tec...
Recipes 8 of Data Warehouse and Business Intelligence - Naming convention tec...Massimo Cenci
 
Object Oriented Analysis and Design
Object Oriented Analysis and DesignObject Oriented Analysis and Design
Object Oriented Analysis and DesignDr. C.V. Suresh Babu
 
Trunk and branches for database configuration management
Trunk and branches for database configuration managementTrunk and branches for database configuration management
Trunk and branches for database configuration managementscmsupport
 

Semelhante a ConcordanceProject (20)

The Perfect Couple
The Perfect CoupleThe Perfect Couple
The Perfect Couple
 
Software architecture-patterns
Software architecture-patternsSoftware architecture-patterns
Software architecture-patterns
 
Software arquitectura patron diseño
Software arquitectura patron diseñoSoftware arquitectura patron diseño
Software arquitectura patron diseño
 
software-architecture-patterns
software-architecture-patternssoftware-architecture-patterns
software-architecture-patterns
 
5 transition to design
5 transition to design5 transition to design
5 transition to design
 
If I Had a Hammer...
If I Had a Hammer...If I Had a Hammer...
If I Had a Hammer...
 
Stl
StlStl
Stl
 
A C Frame Library User Manual And Implementation Notes
A C   Frame Library   User Manual And Implementation NotesA C   Frame Library   User Manual And Implementation Notes
A C Frame Library User Manual And Implementation Notes
 
Stl dich
Stl dichStl dich
Stl dich
 
Linked list basics
Linked list basicsLinked list basics
Linked list basics
 
SchemaStudioTypeLandscape_Article.pdf
SchemaStudioTypeLandscape_Article.pdfSchemaStudioTypeLandscape_Article.pdf
SchemaStudioTypeLandscape_Article.pdf
 
An Introduction to the C++ Standard Library
An Introduction to the C++ Standard LibraryAn Introduction to the C++ Standard Library
An Introduction to the C++ Standard Library
 
MBSE with Arcadia method step-by-step Logical Architecture.pdf
MBSE with Arcadia method step-by-step Logical Architecture.pdfMBSE with Arcadia method step-by-step Logical Architecture.pdf
MBSE with Arcadia method step-by-step Logical Architecture.pdf
 
CS8592 Object Oriented Analysis & Design - UNIT II
CS8592 Object Oriented Analysis & Design - UNIT IICS8592 Object Oriented Analysis & Design - UNIT II
CS8592 Object Oriented Analysis & Design - UNIT II
 
Reference Model for ISEB Certificates in Enterprise and Solution Architecture
Reference Model for ISEB  Certificates in Enterprise  and Solution ArchitectureReference Model for ISEB  Certificates in Enterprise  and Solution Architecture
Reference Model for ISEB Certificates in Enterprise and Solution Architecture
 
Recipes 8 of Data Warehouse and Business Intelligence - Naming convention tec...
Recipes 8 of Data Warehouse and Business Intelligence - Naming convention tec...Recipes 8 of Data Warehouse and Business Intelligence - Naming convention tec...
Recipes 8 of Data Warehouse and Business Intelligence - Naming convention tec...
 
Object Oriented Analysis and Design
Object Oriented Analysis and DesignObject Oriented Analysis and Design
Object Oriented Analysis and Design
 
Stl
StlStl
Stl
 
Trunk and branches for database configuration management
Trunk and branches for database configuration managementTrunk and branches for database configuration management
Trunk and branches for database configuration management
 
Bound and Checked
Bound and CheckedBound and Checked
Bound and Checked
 

ConcordanceProject

  • 1. i Concordance Project Mark L. Short Version 1 11/12/2014 2:24:00 PM
  • 2. ii
  • 3. iii Table of Contents Main Page......................................................................................................................................................................2 Class Index ....................................................................................................................................................................4 File Index.......................................................................................................................................................................5 Class Documentation.....................................................................................................................................................6 sorted_list< _Ty >......................................................................................................................................................6 File Documentation .....................................................................................................................................................11 Concordance/Concordance.cpp ...............................................................................................................................11 Concordance/SortedList.h .......................................................................................................................................16 Concordance/stdafx.cpp...........................................................................................................................................17 Concordance/stdafx.h ..............................................................................................................................................18 Concordance/targetver.h..........................................................................................................................................20 Index............................................................................................................................................................................21
  • 4. 1
  • 5. 2 Main Page Author: Mark L. Short Date: November 11, 2014 Cite: Introduction to Algorithms, Thomas H. Cormen, Charles E. Leiserson, Ronald L. Rivest, Clifford Stein Course: CMPS Algorithm Analysis (graduate level) Instructor: Dr. Timothy Donovan Assignment: “Write a program to maintain an alphabetical list of strings. Use a linked list class to insert and delete strings into an ordered linked list. Your application program should read a list of strings and place them in your linked list and then print the strings out in alphabetical order. It should read a second list of strings and delete them from the list. Finally it should print the items remaining in the list in alpha order. Echo the input strings.” Analysis: 'Concordance' - A Concordance is an alphabetical list of the principal words used in a book or body of work, with their immediate contexts. http://en.wikipedia.org/wiki/Concordance_(publishing) 'Linked List' - In computer science, a linked list is a data structure consisting of a group of nodes which together represent a sequence. Under the simplest form, each node is composed of a data and a reference (in other words, a link) to the next node in the sequence; more complex variants add additional links. http://en.wikipedia.org/wiki/Linked_list 'Ordered Linked List' - is a subset of 'Linked Lists' where each element is inserted into the data structure at a specific location to maintain some ordering property of the overall collection of elements. Brief comparison of data-structures Operation Linked List 'Ordered' Linked List Array Dynamic Array Balanced Tree Searching O(n) O(n) O(1) O(1) O(log n) Insert/Delete (Begin/End) O(1) O(n) na O(1) + copy O(log n) Insert/Delete (middle) O(n) O(n) na O(1) + copy O(log n) On review of the various data-structures and related algorithms available and previously covered, an 'ordered' linked-list is most likely the worst performing one to use for the implementation of a 'Concordance'.
  • 6. 3 Enhancements: 1. Heavy reliance and proper use of a standardize set of template classes and the extension of the STL list template class, in a manner that would meet industry coding standards. 2. Project documentation that exceeds any academic documentation standard. 3. Use of consistent coding standards that exceed typical academic standards. Commentary: The topic of 'algorithm analysis' is not without criticism in the professional computing community, especially the kind of analysis covered in this course that focuses on a very narrow spectrum of analysis based primarily on mathematical models involving "big-O notation". http://en.wikipedia.org/wiki/Big_O_notation This brand of analysis feels more appropriate to those insulated in an academic environment with little urgency to address real-world performance issues involving multi-threading, cache-awareness, concurrency, or application scalability. In this context, 'algorithm analysis' is merely theoretical. According to Dr. Ian Sommerville, author of the core text used in this department's software engineering courses: "University courses should aim to develop student's ability to think in abstractions, to develop reliable and robust programs and to understand the often complex relationships between hardware, software and the organizations that use software-intensive systems." “if we [universities] can’t recruit the most able software engineers, it will become increasingly theoretical and out of touch with what is going on in the world" While the topic of implementation of a 'Concordance' is one of probable value in terms of 'algorithm analysis', the dictates of this assignment actually forbids any actual 'algorithm analysis' activity from being performed by the student and instead, reduces it to a mundane undergraduate-level exercise of coding an ordered linked-list; an implementation that would never survive any level of scrutiny of a formal source- code review or walk-through in the professional community in terms of providing respectable application performance. Additionally, it goes further by invalidating the course through a complete disregard of any algorithm performance analysis on the project and mandating the implementation and use of possibly the very worst performing data-structure in this instance. This assignment is not only "out of touch" with the world, but is "out of touch" with the course text, the course lectures and very essence of the course instruction it was meant to reinforce. While I am extremely critical of this assignment, I equally bear the burden of a failure to 'read the fine- print' and catching the details in time to raise my objections earlier.
  • 7. 4 Class Index Class List Here are the classes, structs, unions and interfaces with brief descriptions: sorted_list< _Ty > (The sorted_list class template is an extension of the STL list class template to provide a mechanism to allow an 'ordered' insert and maintain its sorted property ) .................................6
  • 8. 5 File Index File List Here is a list of all files with brief descriptions: Concordance/Concordance.cpp (Implementation of Concordance Project ) ................................11 Concordance/SortedList.h (Implementation of Sorted List ) ..........................................................16 Concordance/stdafx.cpp (Source file that includes just the standard includes ) ...........................17 Concordance/stdafx.h (Application header file ) ..............................................................................18 Concordance/targetver.h (Windows OS platform header file ) ......................................................20
  • 9. 6 Class Documentation sorted_list< _Ty > Class Template Reference The sorted_list class template is an extension of the STL list class template to provide a mechanism to allow an 'ordered' insert and maintain its sorted property. #include <SortedList.h> Public Member Functions  sorted_list () Default constructor.  bool empty (void) const Time complexity is O(1).  size_type size (void) const throw () Time complexity is O(1).  iterator begin () throw ()  const_iterator begin () const throw ()  iterator end () throw ()  const_iterator end () const throw ()  bool ordered_insert (const _Ty &_Val) ordered_insert performs a linear search of the list for the _Val and inserts at the correct location if not found.  bool remove (const _Ty &_Val) remove performs a linear search of list for _Val and removes it if found. Detailed Description template<class _Ty>class sorted_list< _Ty > The sorted_list class template is an extension of the STL list class template to provide a mechanism to allow an 'ordered' insert and maintain its sorted property. It is not generally a good idea to inherit from an STL class template, which requires containment in the alternative. Constructor & Destructor Documentation template<class _Ty> sorted_list< _Ty >::sorted_list ()[inline] Default constructor. Definition at line 43 of file SortedList.h. 44 : m_list() 45 { };
  • 10. 7 Member Function Documentation template<class _Ty> iterator sorted_list< _Ty >::begin () throw ) [inline] Return values: returns iterator for beginning of mutable sequence Definition at line 67 of file SortedList.h. Referenced by _tmain(). 68 { return m_list.begin(); }; template<class _Ty> const_iterator sorted_list< _Ty >::begin () const throw ) [inline] Return values: returns iterator for beginning of nonmutable sequence Definition at line 74 of file SortedList.h. 75 { return m_list.begin(); }; template<class _Ty> bool sorted_list< _Ty >::empty (void ) const[inline] Time complexity is O(1). Return values: returns true if container is empty Definition at line 52 of file SortedList.h. Referenced by sorted_list< _Ty >::ordered_insert(). 53 { return m_list.empty(); }; template<class _Ty> iterator sorted_list< _Ty >::end () throw ) [inline] Return values: returns iterator for end of mutable sequence Definition at line 81 of file SortedList.h. Referenced by _tmain(). 82 { return m_list.end(); }; template<class _Ty> const_iterator sorted_list< _Ty >::end () const throw ) [inline] Return values: returns iterator for end of nonmutable sequence Definition at line 88 of file SortedList.h. 89 { return m_list.end(); };
  • 11. 8 template<class _Ty> bool sorted_list< _Ty >::ordered_insert (const _Ty & _Val)[inline] ordered_insert performs a linear search of the list for the _Val and inserts at the correct location if not found. Time complexity is O(n). Parameters: in _Val data item to be inserted Return values: returns true if _Val was inserted Definition at line 100 of file SortedList.h. References sorted_list< _Ty >::empty(). Referenced by _tmain(). 101 { 102 bool bResult = false; 103 104 if ( empty ( ) ) 105 { 106 m_list.push_back ( _Val ); 107 bResult = true; 108 } 109 else 110 { // now we get to traverse the list to see if we find _Val 111 bool bFound = false; 112 for ( iterator it = m_list.begin ( ); it != m_list.end ( ); ++it ) 113 { 114 if ( _Val == *it ) 115 { // item found, cannot insert a duplicate 116 bFound = true; 117 break; 118 } 119 else if ( _Val < *it ) 120 { 121 m_list.insert(it, _Val); 122 bResult = true; 123 break; 124 } 125 } 126 // has item been found or inserted yet? 127 if ((bFound == false) && (bResult == false)) 128 { // if not then push it on the end of the ordered_list 129 m_list.push_back(_Val); 130 bResult = true; 131 } 132 } 133 134 return bResult; 135 }; Here is the call graph for this function:
  • 12. 9 template<class _Ty> bool sorted_list< _Ty >::remove (const _Ty & _Val)[inline] remove performs a linear search of list for _Val and removes it if found. Time complexity is O(n). Parameters: in _Val data item to be removed Return values: returns true if _Val was found and removed Definition at line 145 of file SortedList.h. Referenced by _tmain(). 146 { 147 bool bReturn = false; 148 // erase each element matching _Val 149 iterator _Val_it = m_list.end ( ); 150 151 for ( iterator _First = m_list.begin ( ); _First != m_list.end ( ); ) 152 { 153 if ( *_First == _Val ) 154 { 155 if ( std::addressof ( *_First ) == std::addressof ( _Val ) ) 156 { 157 _Val_it = _First++; 158 } 159 else 160 { 161 _First = m_list.erase ( _First ); 162 bReturn = true; 163 } 164 } 165 else 166 { 167 ++_First; 168 } 169 } 170 171 if ( _Val_it != m_list.end ( ) ) 172 { 173 m_list.erase ( _Val_it ); 174 bReturn = true; 175 } 176 177 return bReturn; 178 }
  • 13. 10 template<class _Ty> size_type sorted_list< _Ty >::size (void ) const throw ) [inline] Time complexity is O(1). Return values: returns number of elements in the sequence Definition at line 60 of file SortedList.h. 61 { return m_list.size(); }; The documentation for this class was generated from the following file:  Concordance/SortedList.h
  • 14. 11 File Documentation Concordance/Concordance.cpp File Reference Implementation of Concordance Project. #include "stdafx.h" #include "SortedList.h" #include <fstream> #include <vector> #include <string> #include <cctype> Include dependency graph for Concordance.cpp: Typedefs  typedef sorted_list< std::string > sortedStringList Functions  size_t LoadData (const TCHAR *szFileName, std::vector< std::string > &vArray) LoadData reads input data from text file and returns contents in an STL vector.  template<class _FwdIt > void printMembers (_FwdIt _itBegin, _FwdIt _itEnd) printMembers outputs the contents of a range of STL iterators to standard out.  int _tmain (int argc, _TCHAR *argv[]) _tmain is the main entry point for the application. Variables  const TCHAR g_szDataFileName_1 [] = _T ( "passage1.txt" )  const TCHAR g_szDataFileName_2 [] = _T ( "passage2.txt" ) Detailed Description Implementation of Concordance Project. Definition in file Concordance.cpp.
  • 15. 12 Typedef Documentation typedef sorted_list<std::string> sortedStringList Definition at line 116 of file Concordance.cpp. Function Documentation int _tmain (int argc, _TCHAR * argv[]) _tmain is the main entry point for the application. Definition at line 180 of file Concordance.cpp. References sorted_list< _Ty >::begin(), sorted_list< _Ty >::end(), g_szDataFileName_1, g_szDataFileName_2, LoadData(), sorted_list< _Ty >::ordered_insert(), printMembers(), sorted_list< _Ty >::remove(), and tcout. 181 { 182 typedef std::vector<std::string>::iterator itDataSet; 183 184 sortedStringList lstConcordance; 185 186 std::vector<std::string> vDataSet_1; 187 std::vector<std::string> vDataSet_2; 188 189 // have the vectors pre-allocate enough storage for 256 elements 190 // in order to minimize any reallocations needed as for the subsequent 191 // 'LoadData' methods. 192 vDataSet_1.reserve ( 256 ); 193 vDataSet_2.reserve ( 256 ); 194 195 // lets read in the program data from the text files 196 size_t nStringsLoaded_1 = LoadData ( g_szDataFileName_1, vDataSet_1 ); 197 size_t nStringsLoaded_2 = LoadData ( g_szDataFileName_2, vDataSet_2 ); 198 199 // print content of Data Set 1 200 tcout << _T ( "S1: (unordered) set of input strings" ) << std::endl; 201 tcout << _T ( "-----------------------------------------------------" ) << std::endl; 202 printMembers ( vDataSet_1.begin ( ), vDataSet_1.end ( ) ); 203 tcout << std::endl; 204 205 // begin processing data from 1st input file and insert loaded strings into the Concordance 206 for ( itDataSet it = vDataSet_1.begin ( ); it != vDataSet_1.end ( ); ++it ) 207 { 208 lstConcordance.ordered_insert ( *it ); 209 } 210 211 // print the sorted, filtered content of the Concordance 212 tcout << _T ( "Concordance listing of sorted, unique strings" ) << std::endl; 213 tcout << _T ( "-----------------------------------------------------" ) << std::endl; 214 printMembers ( lstConcordance.begin ( ), lstConcordance.end ( ) ); 215 tcout << std::endl; 216 217 // print content of Data Set 2 218 tcout << _T ( "S2:(unordered) set of input strings" ) << std::endl; 219 tcout << _T ( " (to be removed from Concordance)" ) << std::endl; 220 tcout << _T ( "-----------------------------------------------------" ) << std::endl; 221 printMembers ( vDataSet_2.begin ( ), vDataSet_2.end ( ) ); 222 tcout << std::endl; 223 224 // begin processing data from 2nd input file and remove strings from the lstConcordance 225 for ( itDataSet it = vDataSet_2.begin(); it != vDataSet_2.end(); ++it ) 226 { 227 lstConcordance.remove ( *it );
  • 16. 13 228 } 229 230 // print the final content of the Concordance 231 tcout << _T ( "Concordance (updated) listing of sorted, unique strings" ) << std::endl; 232 tcout << _T ( " (after removal of S2)" ) << std::endl; 233 tcout << _T ( "-----------------------------------------------------" ) << std::endl; 234 printMembers ( lstConcordance.begin ( ), lstConcordance.end ( ) ); 235 tcout << std::endl; 236 237 return 0; 238 } Here is the call graph for this function:
  • 17. 14 size_t LoadData (const TCHAR * szFileName, std::vector< std::string > & vArray) LoadData reads input data from text file and returns contents in an STL vector. Parameters: in szFileName name of the data file to be loaded out vArray reference to an STL vector of strings Return values: returns the number of items read into the vector Definition at line 129 of file Concordance.cpp. References tcout. Referenced by _tmain(). 130 { 131 size_t nReturn = 0; 132 133 std::ifstream infile; 134 135 infile.open ( szFileName ); 136 137 if ( infile.bad ( ) ) 138 { 139 tcout << _T ( "Error opening data file:" ) << szFileName << std::endl; 140 } 141 else 142 { 143 std::string stringData; 144 // process the data 145 while ( infile >> stringData ) 146 { 147 // check last char for trailing punctuation to remove 148 size_t nLen = stringData.length(); 149 if ( (nLen > 1) && (std::ispunct(stringData[nLen - 1])) ) 150 stringData.resize(nLen - 1); 151 152 vArray.push_back ( stringData ); 153 nReturn++; 154 } 155 156 infile.close ( ); 157 } 158 159 return nReturn; 160 }
  • 18. 15 template<class _FwdIt > void printMembers (_FwdIt _itBegin, _FwdIt _itEnd) printMembers outputs the contents of a range of STL iterators to standard out. Definition at line 167 of file Concordance.cpp. References tcout. Referenced by _tmain(). 168 { 169 int iLineCtr = 1; 170 for ( _FwdIt it = _itBegin; it != _itEnd; ++it ) 171 { 172 std::string& str = *it; 173 tcout << std::setw(4) << iLineCtr++ << _T(") ") << str.c_str() << std::endl; 174 } 175 } Variable Documentation const TCHAR g_szDataFileName_1[] = _T ( "passage1.txt" ) Definition at line 118 of file Concordance.cpp. Referenced by _tmain(). const TCHAR g_szDataFileName_2[] = _T ( "passage2.txt" ) Definition at line 119 of file Concordance.cpp. Referenced by _tmain().
  • 19. 16 Concordance/SortedList.h File Reference Implementation of Sorted List. #include <list> Include dependency graph for SortedList.h: This graph shows which files directly or indirectly include this file: Classes  class sorted_list< _Ty > The sorted_list class template is an extension of the STL list class template to provide a mechanism to allow an 'ordered' insert and maintain its sorted property. Detailed Description Implementation of Sorted List. Author: Mark L. Short Date: November 11, 2014 Definition in file SortedList.h.
  • 20. 17 Concordance/stdafx.cpp File Reference Source file that includes just the standard includes. #include "stdafx.h" Include dependency graph for stdafx.cpp: Detailed Description Source file that includes just the standard includes. Concordance.pch will be the pre-compiled header stdafx.obj will contain the pre-compiled type information Author: Mark L. Short Date: November 11, 2014 Definition in file stdafx.cpp.
  • 21. 18 Concordance/stdafx.h File Reference Application header file. #include "targetver.h" #include <stdio.h> #include <tchar.h> #include <string> #include <iostream> #include <iomanip> Include dependency graph for stdafx.h: This graph shows which files directly or indirectly include this file: Macros  #define _CRT_SECURE_NO_WARNINGS  #define tcout std::cout  #define tstring std::string Detailed Description Application header file. Include file for standard system include files, or project specific include files that are used frequently, but are changed infrequently Author: Mark L. Short Date: November 11, 2014
  • 22. 19 Definition in file stdafx.h. Macro Definition Documentation #define _CRT_SECURE_NO_WARNINGS Definition at line 17 of file stdafx.h. #define tcout std::cout Definition at line 38 of file stdafx.h. Referenced by _tmain(), LoadData(), and printMembers(). #define tstring std::string Definition at line 39 of file stdafx.h.
  • 23. 20 Concordance/targetver.h File Reference Windows OS platform header file. #include <SDKDDKVer.h> Include dependency graph for targetver.h: This graph shows which files directly or indirectly include this file: Detailed Description Windows OS platform header file. Author: Mark L. Short Date: November 11, 2014 Definition in file targetver.h.
  • 24. 21 Index _CRT_SECURE_NO_WARNINGS stdafx.h, 19 _tmain Concordance.cpp, 12 begin sorted_list, 7 Concordance.cpp _tmain, 12 g_szDataFileName_1, 15 g_szDataFileName_2, 15 LoadData, 14 printMembers, 15 sortedStringList, 12 Concordance/Concordance.cpp, 11 Concordance/SortedList.h, 16 Concordance/stdafx.cpp, 17 Concordance/stdafx.h, 18 Concordance/targetver.h, 20 empty sorted_list, 7 end sorted_list, 7 g_szDataFileName_1 Concordance.cpp, 15 g_szDataFileName_2 Concordance.cpp, 15 LoadData Concordance.cpp, 14 ordered_insert sorted_list, 8 printMembers Concordance.cpp, 15 remove sorted_list, 9 size sorted_list, 10 sorted_list begin, 7 empty, 7 end, 7 ordered_insert, 8 remove, 9 size, 10 sorted_list, 6 sorted_list< _Ty >, 6 sortedStringList Concordance.cpp, 12 stdafx.h _CRT_SECURE_NO_WARNINGS, 19 tcout, 19 tstring, 19 tcout stdafx.h, 19 tstring stdafx.h, 19