11

CS215 - Lec 6 record index

Embed Size (px)

Citation preview

Page 1: CS215 - Lec 6  record index
Page 2: CS215 - Lec 6  record index

}  Continue different methods for record organization.

}  Continue with the company class; }  Use length indicator, }  Use index. }  Buffering records into memory.

Dr. Hussien M. Sharaf 2

Page 3: CS215 - Lec 6  record index

Dr. Hussien M. Sharaf 3

Fixed length of

bytes Variable length

Length indicator Record

delimiter Record index

Page 4: CS215 - Lec 6  record index

}  To store the record length just ahead of the record.

Dr. Hussien M. Sharaf 4

4. Length indicator

Record 3 Record 4 Record 1 Record 2

}  Problems: 1.  The field length must not be too long (less than

256 bytes) to be stored in a single byte. 2.  Needs more programming effort. 3.  Requires at least two disk trips for each record.

210 250 180 190

Page 5: CS215 - Lec 6  record index

}  Store the byte offset of each record into a list stored in another file.

Dr. Hussien M. Sharaf 5

5. Index

}  Problems: 1.  Two files are used: one for the data and another for

Student_ID offset

20090172 1023 Record1

\n

\n

20090222 211 Record2 \n

20090343 62 Record3 \n

2009393 143 Record4 \n

Page 6: CS215 - Lec 6  record index

Ø The purpose is to read entire record into RAM then use string operations to split it into fields.

Ø Instead of accessing the disk many times to read each field, only one disk trip is needed for each record.

Ø String manipulations done in RAM is much faster than doing same number of disk trips.

Dr. Hussien M. Sharaf 6

Page 7: CS215 - Lec 6  record index

Ø It is another form of string variables. Ø A stream is built upon a string variable to give

the same functionalities and behavior of file streams.

Ø Since we have done a lot of coding on the basis of streams then we can make use of our code.

Ø The final target is to do fields splitting in RAM instead of doing it on disk.

Dr. Hussien M. Sharaf 7

Page 8: CS215 - Lec 6  record index

}  When overloading operators << and >> it is better to use ostream and istream which are the parents of ofstream and ifstream

Dr. Hussien M. Sharaf 8

ostream istream

iostream

fstream

ofstream cout

ifstream cin

ostringstring istringstream

stringstream

Page 9: CS215 - Lec 6  record index

http://www.cplusplus.com/reference/iostream/

Page 10: CS215 - Lec 6  record index

Ø Continue using the CompanyInfo class: Read the whole record into a stringstream. Then pass the stringStream to a method that extracts each field into its correct data-member inside the CompanyInfo class.

Dr. Hussien M. Sharaf 10

Page 11: CS215 - Lec 6  record index