SlideShare une entreprise Scribd logo
1  sur  16
Télécharger pour lire hors ligne
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

Contenu connexe

En vedette

En vedette (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
 

Similaire à CS215 - Lec 7 managing records collection

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
desteinbrook
 
СРС АКТ Малошов Нұралы ВМ-МҚБ-11-23.pptx
СРС АКТ Малошов Нұралы ВМ-МҚБ-11-23.pptxСРС АКТ Малошов Нұралы ВМ-МҚБ-11-23.pptx
СРС АКТ Малошов Нұралы ВМ-МҚБ-11-23.pptx
ssuser8719a6
 

Similaire à 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
 

Plus de 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
 

Dernier

1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
QucHHunhnh
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
ZurliaSoop
 

Dernier (20)

1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and Modifications
 
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17
 
psychiatric nursing HISTORY COLLECTION .docx
psychiatric  nursing HISTORY  COLLECTION  .docxpsychiatric  nursing HISTORY  COLLECTION  .docx
psychiatric nursing HISTORY COLLECTION .docx
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptx
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POS
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptxSKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdf
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
Dyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptxDyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptx
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 

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