170 likes | 218 Views
File Organization. Lec4 Dr Emad Nabil. File types. A file can be treated as a stream of bytes , ex: image file , sound files a collection of records with fields. Filed and Record organization. Field : a data value, smallest unit of data with logical meaning
E N D
File Organization Lec4 Dr Emad Nabil
File types A file can be treated as • a stream of bytes , ex: image file , sound files • a collection of records with fields ..
Filed and Record organization • Field: a data value, smallest unit of data with logical meaning ► Record: A group of fields that forms a logical unit ►Key: a subset of the fields in a record used to uniquely identify the record 87358CARROLLALICE IN WONDERLAND 03818FOLK FILE STRUCTURES 79733KNUTH THE ART OF COMPUTER PROGRAMMING 86683KNUTH SURREAL NUMBERS 18395TOLKIEN THE HOBITT Field Record key Each line of the file is a record. ►Fields in each record: – ISBN Number, – Author Name, – Book Title
Primary and secondary keys ►Primary Key : A key that uniquelyidentifies a record. ►Secondary Key: Other keys that may be used for search ►Note that • In general not every field is a key • Keys correspond to fields, or combinationof fields, that may be used in a search
Method of field organization • Fixed length • Begin each field with its Lengthindicator • Delimitersto separate fields • “keyword=value” identifies each field and its content
Methods of field organization 1- Fixed length fields • Like in our file of books (field lengths are 5,7, and25). • 87358CARROLL ALICE IN WONDERLAND--------- • 03818FOLK - - - FILE STRUCTURES------------------ • 86683KNUTH- - SURREAL NUMBERS--------------- • 18395TOLKIEN THE HOBITT-------------------------- spaces
Methods of field organization 2-Length indicator Filed length • 058735807CARROLL19ALICE IN WONDERLAND • 050381804FOLK15FILE STRUCTURES • 058668305KNUTH15SURREAL NUMBERS • 051839507TOLKIEN10THE HOBITT Record
Methods of field organization 3-using delimiters • Add delimiter at the end of each field • 87358|CARROLL|ALICE IN WONDERLAND| • 03818|FOLK|FILE STRUCTURES| • 86683|KNUTH|SURREAL NUMBERS| • 18395|TOLKIEN|THE HOBITT|
Methods of field organization 4-using (key=value) • ISBN=87358|AU=CARROLL|TI=ALICE IN WONDERLAND| • ISBN=03818|AU=FOLK|TI=FILE STRUCTURES| • ISBN=86683|AU=KNUTH|TI=SURREAL NUMBERS| • ISBN=18395|AU=TOLKIEN|TI=THE HOBITT|
Record Organization Fixed length record • Fixed length record • Records with fixed number of fields • Begin record field with its Length indicator • Using Delimiters to separate records • Use an indexto keep records addresses Variable length record
Record Organization1-Fixed length record • Internal organization may be • Fixed length field • Delimited fields • Using length indicator
Record Organization2-Fixed number of fields • Internal organization may be • Delimited fields • Using length indicator
Record Organization3-Begin record field with its Length indicator • Internal organization may be • Delimited fields • Using length indicator 33
Record Organization4- Using Delimiters to separate records * The common delimiter in the end of line, as it make the file readable *any other character can be used as a delimiter.
Record Organization5-using index to keep track of records. Keys are sorted