Your SlideShare is downloading. ×
0
CS215 - Lec 7  managing records collection
CS215 - Lec 7  managing records collection
CS215 - Lec 7  managing records collection
CS215 - Lec 7  managing records collection
CS215 - Lec 7  managing records collection
CS215 - Lec 7  managing records collection
CS215 - Lec 7  managing records collection
CS215 - Lec 7  managing records collection
CS215 - Lec 7  managing records collection
CS215 - Lec 7  managing records collection
CS215 - Lec 7  managing records collection
CS215 - Lec 7  managing records collection
CS215 - Lec 7  managing records collection
CS215 - Lec 7  managing records collection
CS215 - Lec 7  managing records collection
CS215 - Lec 7  managing records collection
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

CS215 - Lec 7 managing records collection

187

Published on

Buffering

Buffering

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
187
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
19
Comments
0
Likes
0
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. Storing collection of records. Reading collection of records. Writing collection of records. Buffering Algorithm. Dr. Hussien M. Sharaf 2
  • 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
  • 3. 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.
  • 4. 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.
  • 5. 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)
  • 6. 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++ }
  • 7. 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
  • 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
  • 9. Dr. Hussien M. Sharaf 10
  • 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
  • 11. 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&); };
  • 12. 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
  • 13. 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
  • 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

×