SlideShare a Scribd company logo
1 of 16
Download to read offline
Storing collection of records.
Reading collection of records.
Writing collection of records.
Buffering Algorithm.
Dr. Hussien M.
Sharaf
2
Company info class only
represents single record.
A collection of records
needs to be stored into a
dynamic array.
The collection of records
can be encapsulated into a
class that maps to a file.
Dr. Hussien M.
Sharaf
3
Company1
Company2
…..
Company N
Dr. Hussien M.
Sharaf
4
CompanyInfoCollection
Structure
Record 3 Record 4Record 1 Record 2210 250 180 190
1. Store collection of records in a dynamic array
2. Store file full path name.
3. Store and manage the indexing of records.
Dr. Hussien M.
Sharaf
5
CompanyInfoCollection
Functionalities
Record 3 Record 4Record 1 Record 2210 250 180 190
1. Responsible for opening and closing of the file
stream.
2. Calling read or write of companyInfo without
knowing the details of read/write single line.
3. Manage the buffering of records while reading or
writing.
4. Count the number of records in a file.
Dr. Hussien M.
Sharaf
6
Algorithm#1 Writing collection of
records
Record 3 Record 4Record 1 Record 2210 250 180 190
While (len(Buffer) < bufferingSize)
{
companyInfo[i].writeIntoStream( stringStream)
stringStream<<recordDelimiter
i++
}
Stringstream>>Buffer
FileStream.write(Buffer)
Dr. Hussien M.
Sharaf
7
Algorithm#2 Reading collection
of records
Record 3 Record 4Record 1 Record 2210 250 180 190
FileStream.read(Buffer, BufferingSize+1)
Stringstream<<Buffer;
While (! Stringstream.EOF)
{
companyInfo[i].ReadFromStream(Stringstream)
i++
}
1. Read x MB into memory buffer (i.e.
char array).
2. Make sure to stop reading at the end of
a record. How can this be done?
3. Put the buffered data into a string
stream.
Dr. Hussien M.
Sharaf
8
4. Pass the string stream to an instance of
companyInfo which extracts fields.
5. Add the new companyInfo to the array
of records.
6. Manage the index by adding an entry
with the correct offset.
7. Repeat steps 1-6 until EOF
Dr. Hussien M.
Sharaf
9
Dr. Hussien M.
Sharaf
10
Store the byte offset of each record into a list stored in
another file.
Dr. Hussien M.
Sharaf
11
Remember Indexing
Problems:
1. Two files are used: one for the data and another for
CompanyName offset
IBM 0Record1
n
n
Google 211Record2 n
Microsoft 462Record3 n
ITE 643Record4 n
Dr. Hussien M.
Sharaf
12
class CompanyInfoCollection
{
private:
vector<CompanyInfo> Records;
RecordIndex recordIndexes;
public:
//read delimited fields
bool WriteDelimRecords(ostream& ,char);
//read delimited fields
bool readDelimRecords(istream&);
};
Dr. Hussien M.
Sharaf
13
Read/write from
streamBuffer
Single
companyInfo
RecordsCollection
File stream
Read/write from
streamBuffer
Single
companyInfo
Records Indexes
Record 2211 Record 3462
Continue using the CompanyInfo program:
1) Where would you put the following
functionalities:
a. Read the multiple records into a buffer.
b. Split a single record into fields.
c. Append a single record into a collection of
records.
d. Search for a record given a company
name.
Dr. Hussien M.
Sharaf
14
Continue using the CompanyInfo program:
2) Implement Algorithm#1 into the
CompanyInfo program.
3) Implement Algorithm#2 into the
CompanyInfo program.
Dr. Hussien M.
Sharaf
15
CS215 - Lec 7  managing records collection

More Related Content

Viewers also liked

Viewers also liked (20)

CS215 - Lec 10 b trees and hashing
CS215 - Lec 10   b trees and hashingCS215 - Lec 10   b trees and hashing
CS215 - Lec 10 b trees and hashing
 
Setup python with eclipse
Setup python with eclipseSetup python with eclipse
Setup python with eclipse
 
CS215 - Lec 9 indexing and reclaiming space in files
CS215 - Lec 9  indexing and reclaiming space in filesCS215 - Lec 9  indexing and reclaiming space in files
CS215 - Lec 9 indexing and reclaiming space in files
 
CS215 - Lec 8 searching records
CS215 - Lec 8  searching recordsCS215 - Lec 8  searching records
CS215 - Lec 8 searching records
 
CS215 Lec 1 introduction
CS215 Lec 1   introductionCS215 Lec 1   introduction
CS215 Lec 1 introduction
 
Compilers Final spring 2013 model answer
 Compilers Final spring 2013 model answer Compilers Final spring 2013 model answer
Compilers Final spring 2013 model answer
 
Model answer of compilers june spring 2013
Model answer of compilers june spring 2013Model answer of compilers june spring 2013
Model answer of compilers june spring 2013
 
File Organization & processing Mid term summer 2014 - modelanswer
File Organization & processing Mid term summer 2014 - modelanswerFile Organization & processing Mid term summer 2014 - modelanswer
File Organization & processing Mid term summer 2014 - modelanswer
 
CS215 - Lec 2 file organization
CS215 - Lec 2   file organizationCS215 - Lec 2   file organization
CS215 - Lec 2 file organization
 
CS215 - Lec 3 single record operations
CS215 - Lec 3  single record operationsCS215 - Lec 3  single record operations
CS215 - Lec 3 single record operations
 
Model answer of exam TC_spring 2013
Model answer of exam TC_spring 2013Model answer of exam TC_spring 2013
Model answer of exam TC_spring 2013
 
Compilers midterm spring 2013 model answer
Compilers midterm spring 2013   model answerCompilers midterm spring 2013   model answer
Compilers midterm spring 2013 model answer
 
CS215 - Lec 4 single record organization
CS215 - Lec 4  single record organizationCS215 - Lec 4  single record organization
CS215 - Lec 4 single record organization
 
Lec4
Lec4Lec4
Lec4
 
Cs419 lec4 lexical analysis using re
Cs419 lec4   lexical analysis using reCs419 lec4   lexical analysis using re
Cs419 lec4 lexical analysis using re
 
Theory of computation Lec6
Theory of computation Lec6Theory of computation Lec6
Theory of computation Lec6
 
Theory of computation Lec1
Theory of computation Lec1Theory of computation Lec1
Theory of computation Lec1
 
Theory of computation Lec7 pda
Theory of computation Lec7 pdaTheory of computation Lec7 pda
Theory of computation Lec7 pda
 
Theory of computation Lec3 dfa
Theory of computation Lec3 dfaTheory of computation Lec3 dfa
Theory of computation Lec3 dfa
 
Infos2014
Infos2014Infos2014
Infos2014
 

Similar to CS215 - Lec 7 managing records collection

Good (enough) research data management practices
Good (enough) research data management practicesGood (enough) research data management practices
Good (enough) research data management practicesLeon Osinski
 
Ch 17 disk storage, basic files structure, and hashing
Ch 17 disk storage, basic files structure, and hashingCh 17 disk storage, basic files structure, and hashing
Ch 17 disk storage, basic files structure, and hashingZainab Almugbel
 
MARUTHI_INVERTED_SEARCH_presentation.pptx
MARUTHI_INVERTED_SEARCH_presentation.pptxMARUTHI_INVERTED_SEARCH_presentation.pptx
MARUTHI_INVERTED_SEARCH_presentation.pptxMaruthiRock
 
Impetus White Paper- Handling Data Corruption in Elasticsearch
Impetus White Paper- Handling  Data Corruption  in ElasticsearchImpetus White Paper- Handling  Data Corruption  in Elasticsearch
Impetus White Paper- Handling Data Corruption in ElasticsearchImpetus Technologies
 
Log into your netlab workstation then ssh to server.cnt1015.local wi.docx
Log into your netlab workstation then ssh to server.cnt1015.local wi.docxLog into your netlab workstation then ssh to server.cnt1015.local wi.docx
Log into your netlab workstation then ssh to server.cnt1015.local wi.docxdesteinbrook
 
Unit ivos - file systems
Unit ivos - file systemsUnit ivos - file systems
Unit ivos - file systemsdonny101
 
File organization in database
File organization in databaseFile organization in database
File organization in databaseAfrasiyab Haider
 
File organization in database
File organization in databaseFile organization in database
File organization in databaseAfrasiyab Haider
 
IOD 2013 - Crunch Big Data in the Cloud with IBM BigInsights and Hadoop lab s...
IOD 2013 - Crunch Big Data in the Cloud with IBM BigInsights and Hadoop lab s...IOD 2013 - Crunch Big Data in the Cloud with IBM BigInsights and Hadoop lab s...
IOD 2013 - Crunch Big Data in the Cloud with IBM BigInsights and Hadoop lab s...Leons Petražickis
 
File Management in Operating System
File Management in Operating SystemFile Management in Operating System
File Management in Operating SystemJanki Shah
 
Application portfolio development.advadisadvan.pptx
Application portfolio development.advadisadvan.pptxApplication portfolio development.advadisadvan.pptx
Application portfolio development.advadisadvan.pptxAmanJain384694
 
File handling in qbasic
File handling in qbasicFile handling in qbasic
File handling in qbasicSmritiGurung4
 
СРС АКТ Малошов Нұралы ВМ-МҚБ-11-23.pptx
СРС АКТ Малошов Нұралы ВМ-МҚБ-11-23.pptxСРС АКТ Малошов Нұралы ВМ-МҚБ-11-23.pptx
СРС АКТ Малошов Нұралы ВМ-МҚБ-11-23.pptxssuser8719a6
 
Mesics lecture files in 'c'
Mesics lecture   files in 'c'Mesics lecture   files in 'c'
Mesics lecture files in 'c'eShikshak
 
Unit 4 data storage and querying
Unit 4   data storage and queryingUnit 4   data storage and querying
Unit 4 data storage and queryingRavindran Kannan
 
File Types in Data Structure
File Types in Data StructureFile Types in Data Structure
File Types in Data StructureProf Ansari
 

Similar to CS215 - Lec 7 managing records collection (20)

CS215 - Lec 6 record index
CS215 - Lec 6  record indexCS215 - Lec 6  record index
CS215 - Lec 6 record index
 
CS215 - Lec 5 record organization
CS215 - Lec 5  record organizationCS215 - Lec 5  record organization
CS215 - Lec 5 record organization
 
Good (enough) research data management practices
Good (enough) research data management practicesGood (enough) research data management practices
Good (enough) research data management practices
 
Ch 17 disk storage, basic files structure, and hashing
Ch 17 disk storage, basic files structure, and hashingCh 17 disk storage, basic files structure, and hashing
Ch 17 disk storage, basic files structure, and hashing
 
MARUTHI_INVERTED_SEARCH_presentation.pptx
MARUTHI_INVERTED_SEARCH_presentation.pptxMARUTHI_INVERTED_SEARCH_presentation.pptx
MARUTHI_INVERTED_SEARCH_presentation.pptx
 
Impetus White Paper- Handling Data Corruption in Elasticsearch
Impetus White Paper- Handling  Data Corruption  in ElasticsearchImpetus White Paper- Handling  Data Corruption  in Elasticsearch
Impetus White Paper- Handling Data Corruption in Elasticsearch
 
File structures
File structuresFile structures
File structures
 
File structures
File structuresFile structures
File structures
 
Log into your netlab workstation then ssh to server.cnt1015.local wi.docx
Log into your netlab workstation then ssh to server.cnt1015.local wi.docxLog into your netlab workstation then ssh to server.cnt1015.local wi.docx
Log into your netlab workstation then ssh to server.cnt1015.local wi.docx
 
Unit ivos - file systems
Unit ivos - file systemsUnit ivos - file systems
Unit ivos - file systems
 
File organization in database
File organization in databaseFile organization in database
File organization in database
 
File organization in database
File organization in databaseFile organization in database
File organization in database
 
IOD 2013 - Crunch Big Data in the Cloud with IBM BigInsights and Hadoop lab s...
IOD 2013 - Crunch Big Data in the Cloud with IBM BigInsights and Hadoop lab s...IOD 2013 - Crunch Big Data in the Cloud with IBM BigInsights and Hadoop lab s...
IOD 2013 - Crunch Big Data in the Cloud with IBM BigInsights and Hadoop lab s...
 
File Management in Operating System
File Management in Operating SystemFile Management in Operating System
File Management in Operating System
 
Application portfolio development.advadisadvan.pptx
Application portfolio development.advadisadvan.pptxApplication portfolio development.advadisadvan.pptx
Application portfolio development.advadisadvan.pptx
 
File handling in qbasic
File handling in qbasicFile handling in qbasic
File handling in qbasic
 
СРС АКТ Малошов Нұралы ВМ-МҚБ-11-23.pptx
СРС АКТ Малошов Нұралы ВМ-МҚБ-11-23.pptxСРС АКТ Малошов Нұралы ВМ-МҚБ-11-23.pptx
СРС АКТ Малошов Нұралы ВМ-МҚБ-11-23.pptx
 
Mesics lecture files in 'c'
Mesics lecture   files in 'c'Mesics lecture   files in 'c'
Mesics lecture files in 'c'
 
Unit 4 data storage and querying
Unit 4   data storage and queryingUnit 4   data storage and querying
Unit 4 data storage and querying
 
File Types in Data Structure
File Types in Data StructureFile Types in Data Structure
File Types in Data Structure
 

More from Arab Open University and Cairo University (12)

Theory of computation Lec2
Theory of computation Lec2Theory of computation Lec2
Theory of computation Lec2
 
Cs419 lec8 top-down parsing
Cs419 lec8    top-down parsingCs419 lec8    top-down parsing
Cs419 lec8 top-down parsing
 
Cs419 lec11 bottom-up parsing
Cs419 lec11   bottom-up parsingCs419 lec11   bottom-up parsing
Cs419 lec11 bottom-up parsing
 
Cs419 lec12 semantic analyzer
Cs419 lec12  semantic analyzerCs419 lec12  semantic analyzer
Cs419 lec12 semantic analyzer
 
Cs419 lec9 constructing parsing table ll1
Cs419 lec9   constructing parsing table ll1Cs419 lec9   constructing parsing table ll1
Cs419 lec9 constructing parsing table ll1
 
Cs419 lec10 left recursion and left factoring
Cs419 lec10   left recursion and left factoringCs419 lec10   left recursion and left factoring
Cs419 lec10 left recursion and left factoring
 
Cs419 lec7 cfg
Cs419 lec7   cfgCs419 lec7   cfg
Cs419 lec7 cfg
 
Cs419 lec6 lexical analysis using nfa
Cs419 lec6   lexical analysis using nfaCs419 lec6   lexical analysis using nfa
Cs419 lec6 lexical analysis using nfa
 
Cs419 lec5 lexical analysis using dfa
Cs419 lec5   lexical analysis using dfaCs419 lec5   lexical analysis using dfa
Cs419 lec5 lexical analysis using dfa
 
Cs419 lec3 lexical analysis using re
Cs419 lec3   lexical analysis using reCs419 lec3   lexical analysis using re
Cs419 lec3 lexical analysis using re
 
Cs419 Compiler lec1&2 introduction
Cs419 Compiler lec1&2  introductionCs419 Compiler lec1&2  introduction
Cs419 Compiler lec1&2 introduction
 
Final Exam OS fall 2012-2013 with answers
Final Exam OS fall 2012-2013 with answersFinal Exam OS fall 2012-2013 with answers
Final Exam OS fall 2012-2013 with answers
 

Recently uploaded

Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxmanuelaromero2013
 
Final demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxFinal demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxAvyJaneVismanos
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Celine George
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdfssuser54595a
 
Hierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementHierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementmkooblal
 
CELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptxCELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptxJiesonDelaCerna
 
Types of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxTypes of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxEyham Joco
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...jaredbarbolino94
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationnomboosow
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...Marc Dusseiller Dusjagr
 
internship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developerinternship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developerunnathinaik
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxiammrhaywood
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Celine George
 
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...M56BOOKSTORE PRODUCT/SERVICE
 

Recently uploaded (20)

Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptx
 
Final demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxFinal demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptx
 
9953330565 Low Rate Call Girls In Rohini Delhi NCR
9953330565 Low Rate Call Girls In Rohini  Delhi NCR9953330565 Low Rate Call Girls In Rohini  Delhi NCR
9953330565 Low Rate Call Girls In Rohini Delhi NCR
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17
 
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
 
Hierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementHierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of management
 
CELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptxCELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptx
 
Types of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxTypes of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptx
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communication
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
 
internship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developerinternship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developer
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
 
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
 
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
 

CS215 - Lec 7 managing records collection

  • 1.
  • 2. Storing collection of records. Reading collection of records. Writing collection of records. Buffering Algorithm. Dr. Hussien M. Sharaf 2
  • 3. Company info class only represents single record. A collection of records needs to be stored into a dynamic array. The collection of records can be encapsulated into a class that maps to a file. Dr. Hussien M. Sharaf 3 Company1 Company2 ….. Company N
  • 4. Dr. Hussien M. Sharaf 4 CompanyInfoCollection Structure Record 3 Record 4Record 1 Record 2210 250 180 190 1. Store collection of records in a dynamic array 2. Store file full path name. 3. Store and manage the indexing of records.
  • 5. Dr. Hussien M. Sharaf 5 CompanyInfoCollection Functionalities Record 3 Record 4Record 1 Record 2210 250 180 190 1. Responsible for opening and closing of the file stream. 2. Calling read or write of companyInfo without knowing the details of read/write single line. 3. Manage the buffering of records while reading or writing. 4. Count the number of records in a file.
  • 6. Dr. Hussien M. Sharaf 6 Algorithm#1 Writing collection of records Record 3 Record 4Record 1 Record 2210 250 180 190 While (len(Buffer) < bufferingSize) { companyInfo[i].writeIntoStream( stringStream) stringStream<<recordDelimiter i++ } Stringstream>>Buffer FileStream.write(Buffer)
  • 7. Dr. Hussien M. Sharaf 7 Algorithm#2 Reading collection of records Record 3 Record 4Record 1 Record 2210 250 180 190 FileStream.read(Buffer, BufferingSize+1) Stringstream<<Buffer; While (! Stringstream.EOF) { companyInfo[i].ReadFromStream(Stringstream) i++ }
  • 8. 1. Read x MB into memory buffer (i.e. char array). 2. Make sure to stop reading at the end of a record. How can this be done? 3. Put the buffered data into a string stream. Dr. Hussien M. Sharaf 8
  • 9. 4. Pass the string stream to an instance of companyInfo which extracts fields. 5. Add the new companyInfo to the array of records. 6. Manage the index by adding an entry with the correct offset. 7. Repeat steps 1-6 until EOF Dr. Hussien M. Sharaf 9
  • 11. Store the byte offset of each record into a list stored in another file. Dr. Hussien M. Sharaf 11 Remember Indexing Problems: 1. Two files are used: one for the data and another for CompanyName offset IBM 0Record1 n n Google 211Record2 n Microsoft 462Record3 n ITE 643Record4 n
  • 12. Dr. Hussien M. Sharaf 12 class CompanyInfoCollection { private: vector<CompanyInfo> Records; RecordIndex recordIndexes; public: //read delimited fields bool WriteDelimRecords(ostream& ,char); //read delimited fields bool readDelimRecords(istream&); };
  • 13. Dr. Hussien M. Sharaf 13 Read/write from streamBuffer Single companyInfo RecordsCollection File stream Read/write from streamBuffer Single companyInfo Records Indexes Record 2211 Record 3462
  • 14. Continue using the CompanyInfo program: 1) Where would you put the following functionalities: a. Read the multiple records into a buffer. b. Split a single record into fields. c. Append a single record into a collection of records. d. Search for a record given a company name. Dr. Hussien M. Sharaf 14
  • 15. Continue using the CompanyInfo program: 2) Implement Algorithm#1 into the CompanyInfo program. 3) Implement Algorithm#2 into the CompanyInfo program. Dr. Hussien M. Sharaf 15