File Structure Fundamentals (D.H.)1 Learning Objectives Field and record organization Index file C++ code that deals with field and record organization.

Slides:



Advertisements
Similar presentations
Introduction to C Programming
Advertisements

Pointers.
ICDL Software Applications - Database Concepts. Unit 6 Data and Data Representation Database Concepts –File Structure –Relationships Database Design –Data.
INSTRUCTION SET ARCHITECTURES
Dr. Kalpakis CMSC 661, Principles of Database Systems Representing Data Elements [12]
SEMINAR ON FILE SLACK AND DISK SLACK
File Organizations Sept. 2012Yangjun Chen ACS-3902/31 Outline: File Organization Hardware Description of Disk Devices Buffering of Blocks File Records.
Memory Management Design & Implementation Segmentation Chapter 4.
Chapter 10.
File Organizations March 2007R McFadyen ACS File Organization Hardware Description of Disk Devices Buffering of Blocks File Records on Disk Review.
CPSC 231 Organizing Files for Performance (D.H.) 1 LEARNING OBJECTIVES Data compression. Reclaiming space in files. Compaction. Searching. Sorting, Keysorting.
Variable Length Data and Records Eswara Satya Pavan Rajesh Pinapala CS 257 ID: 221.
Fundamental File Structure Concepts
Fundamental File Structure Concepts
Recap of Feb 27: Disk-Block Access and Buffer Management Major concepts in Disk-Block Access covered: –Disk-arm Scheduling –Non-volatile write buffers.
1 File Structure n File as a stream of characters l No structure l Consider students registered in a course Joe SmithSC Kathy LeeEN Albert.
CPSC 231 Managing Files of Records (D.H.) 1 Learning Objectives Concept of key - primary and secondary keys. Sequential versus direct access. RRN Use of.
METU Department of Computer Eng Ceng 302 Introduction to DBMS Disk Storage, Basic File Structures, and Hashing by Pinar Senkul resources: mostly froom.
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Chapter 13 Disk Storage, Basic File Structures, and Hashing.
Folk/Zoellick/Riccardi, File Structures 1 Objectives: To get familiar with Alternatives in field and record organizations Object-oriented approach to buffered.
Chapter 7 Indexing Objectives: To get familiar with: Indexing
DISK STORAGE INDEX STRUCTURES FOR FILES Lecture 12.
Streams, Files. 2 Stream Stream is a sequence of bytes Input stream In input operations, the bytes are transferred from a device to the main memory Output.
1 Rizwan Rehman Centre for Computer Studies Dibrugarh University.
1.A file is organized logically as a sequence of records. 2. These records are mapped onto disk blocks. 3. Files are provided as a basic construct in operating.
CHP - 9 File Structures. INTRODUCTION In some of the previous chapters, we have discussed representations of and operations on data structures. These.
File Organization Techniques
File StructuresSNU-OOPSLA Lab.1 Chap4. Fundamental File Structure Concepts 서울대학교 컴퓨터공학부 객체지향시스템연구실 SNU-OOPSLA-LAB 김 형 주 교수 File Structures by Folk, Zoellick,
Disk Storage Copyright © 2004 Pearson Education, Inc.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 17 Disk Storage, Basic File Structures, and Hashing.
February 1 & 31 Csci 2111: Data and File Structures Week4, Lectures 1 & 2 Fundamental File Structure Concepts & Managing Files of Records.
Fundamental File Structure Concepts & Managing Files of Records
Prof. Yousef B. Mahdy , Assuit University, Egypt File Organization Prof. Yousef B. Mahdy Chapter -4 Data Management in Files.
March 16 & 21, Csci 2111: Data and File Structures Week 9, Lectures 1 & 2 Indexed Sequential File Access and Prefix B+ Trees.
1 Chap4. Fundamental File Structure Concepts. 2 Chapter Objectives  Introduce file structure concepts dealing with Stream files Reading and writing fields.
©Silberschatz, Korth and Sudarshan11.1Database System Concepts Chapter 11: Storage and File Structure File Organization Organization of Records in Files.
CS4432: Database Systems II Record Representation 1.
Introduction to Programming Using C Files. 2 Contents Files Working with files Sequential files Records.
Course Title: Object Oriented Programming with C++ instructor ADEEL ANJUM Chapter No: 03 Conditional statement 1 BY ADEEL ANJUM (MSc-cs, CCNA,WEB DEVELOPER)
Chapter 13 Disk Storage, Basic File Structures, and Hashing. Copyright © 2004 Pearson Education, Inc.
SQL Fundamentals  SQL: Structured Query Language is a simple and powerful language used to create, access, and manipulate data and structure in the database.
File Processing - Fundamental concepts MVNC1 Fundamental File Structure Concepts Chapter 4.
File Structures. 2 Chapter - Objectives Disk Storage Devices Files of Records Operations on Files Unordered Files Ordered Files Hashed Files Dynamic and.
Chapter 5: Hashing Part I - Hash Tables. Hashing  What is Hashing?  Direct Access Tables  Hash Tables 2.
Files Tutor: You will need ….
Programming Fundamentals. Overview of Previous Lecture Phases of C++ Environment Program statement Vs Preprocessor directive Whitespaces Comments.
Programming Fundamentals. Summary of previous lectures Programming Language Phases of C++ Environment Variables and Data Types.
Copyright © 2000, Department of Systems and Computer Engineering, Carleton University 1 Introduction An array is a collection of identical boxes.
1 CSC103: Introduction to Computer and Programming Lecture No 28.
C++ Programming Lecture 14 Arrays – Part I The Hashemite University Computer Engineering Department (Adapted from the textbook slides)
Comp 335 File Structures Fundamental File Structure Concepts.
Programming Fundamentals. Today’s Lecture Array Fundamentals Arrays as Class Member Data Arrays of Objects C-Strings The Standard C++ string Class.
Chapter 5 Record Storage and Primary File Organizations
Madhuri Gollu Id: 207. Agenda Agenda  Records with Variable Length Fields  Records with Repeating Fields  Variable Format Records  Records that do.
SVBIT SUBJECT:- Operating System TOPICS:- File Management
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Lec 5 part1 Disk Storage, Basic File Structures, and Hashing.
Introduction Every program takes some data as input and generate processed data as out put . It is important to know how to provide the input data and.
Fundamental File Structure Concepts
CPSC 231 Organizing Files for Performance (D.H.)
CHP - 9 File Structures.
Fundamental File Structure Concepts
9/12/2018.
Section 3.2c Strings and Method Signatures
Disk Storage, Basic File Structures, and Hashing
Disk Storage, Basic File Structures, and Buffer Management
Variable Length Data and Records
Chap4. Fundamental File Structure Concepts
CS222/CS122C: Principles of Data Management Lecture #2 Storing Data: Disks and Files Instructor: Chen Li.
VIJAYA PAMIDI CS 257- Sec 01 ID:102
Lecture Topics: 11/20 HW 7 What happens on a memory reference Traps
Presentation transcript:

File Structure Fundamentals (D.H.)1 Learning Objectives Field and record organization Index file C++ code that deals with field and record organization.

File Structure Fundamentals (D.H.)2 Field and Record Organization Field is a basic unit of data organization. It is the smallest logically meaningful unit of information in a file. Each field contains a single data value: e.g. last name, or balance. Aggregates of a list of different fields are called records, e.g. last name, first name and balance.

File Structure Fundamentals (D.H.)3 A Stream File Files are written to a persistent storage (such as disks) as streams of bytes. Unless there is some special action done to avoid it, a record of data such as: Mary Ames 123 Maple Stillwater, OK Will be written (using << operator) to the disk as: Mary Ames123 MapleStillwater, OK 74075

File Structure Fundamentals (D.H.)4 A Stream File - cont. A single line of text such as: Mary Ames123 MapleStillwater, OK makes it impossible to extract and display correct information. What is the last name in the above line? Most systems would read Ames123 as the last name and MapleStillwater as a street address. This is obviously NOT correct.

File Structure Fundamentals (D.H.)5 Fields and Records Thus we need to organize the files in such way that lets us keep the information divided into fields. For example the above file should be kept as a set of records with the following fields: –first name –last name –street address –city –state –ZIP code

File Structure Fundamentals (D.H.)6 Field Structures Four most common ways of structuring files are: –force the fields into predicable (fixed) length –begin each field with the length indicator –place delimiter at the end of each field to separate the fields –use “keyword=value” expression to identify each field and its contents

File Structure Fundamentals (D.H.)7 Fixing the Length of Fields This method relies on creating fields of predictable fixed size. E.G. One may define the following class: class Person { public: char last[11]; char first[11]; char address[16]; char city[16]; char state[3]; char zip[10]; }

File Structure Fundamentals (D.H.)8 Fixing the Length of Fields-cont. The size of each character array in the above example is fixed. If the value of the data requires less space than reserved than characters representing spaces (‘ ‘) are added to fill the array. For example a string such as “Mary” would have to be padded with six blanks (and terminated with \0) to fill the array: char first[11]

File Structure Fundamentals (D.H.)9 Fixing the Length of Fields-cont. Disadvantages: a lot of wasted space due to “padding” of fields with “blanks” data values may not fit into the field sizes: »e.g. Michalopoulos is too long to fit in the array char last[11] Thus the fixed-size field approach is inappropriate for data that inherently contains a large amount of variability in the length of fields such as names or addresses.

File Structure Fundamentals (D.H.)10 Beginning Each Field with a Length Indicator This method requires that each field data be preceded with an indicator of its length (in bytes). E.G. 04Ames04Mary09123 Maple10StillWater02OK One of the disadvantages of this method is that it is more complex since it requires extracting of numbers and strings from a single string representing a record.

File Structure Fundamentals (D.H.)11 Separating Fields with Delimiters This method requires that the fields be separated by a selected special character or a sequence of characters called a delimiter. E.G. If “|” is used as a delimiter then a sample record would look like this: Ames|Mary|123Maple|StillWater|OK|574075|

File Structure Fundamentals (D.H.)12 The method of separating fields with a delimiter is often used. However choosing a right delimiter is very important. In many cases white-space characters (blanks) are excellent delimiters because they provide a clean separation between fields when we list them on the console. However, white spaces would not work as delimiters in our previous example. Why?

File Structure Fundamentals (D.H.)13 Overloading a stream extraction operator to read a file with delimiters istream & operator >> (istream & streamF, Person &p) {//read delimited fields from file streamF.getline(p.last, 30, ‘|’); if (strlen(p.last)==0) return streamF); streamF.getline(p.first,30,’|’); streamF.getline(p.address,30,’|’); streamF.getline(p.city,30,’|’); streamF,getline(p.state,15,’|’); streamF.getline(p.zip,10,’|’); return stream; }

File Structure Fundamentals (D.H.)14 Using a “keyword = value” expression This method requires that each field data be preceded with the field identifier (keyword). E.G. last=Amesfirst=Maryaddress=123 Maplecity=StillWaterstate=OKzip= Can be used with the delimiter method to mark the field ends. last=Ames|first=Mary|address=123 Maple|City=StillWater|state=OK|zip=574075

File Structure Fundamentals (D.H.)15 Using a “keyword = value” expression Advantages: each field provides information about itself good format for dealing with missing fields Disadvantages: In some application a lot of space may be wasted on field keywords (up 50%).

File Structure Fundamentals (D.H.)16 Record Structures Files may be viewed as collections of records which are sets of fields Some of the most often used methods for organizing the records of a file are: –require that the records be a predictable (fixed) number of bytes in length –require that the records be a predicable number of fields in length

File Structure Fundamentals (D.H.)17 Organizing the Records of a File –begin each record with its length indicator (count of the of bytes in the record) –use a second file to keep track of the beginning byte address for each record –place a delimiter at the end of each record to separate it from the next record

File Structure Fundamentals (D.H.)18 Fixed-Length Records This method is a counterpart of is analogous method for organizing files with fix length fields. Fixing the sizes of fields in a record will produce a fixed-size record.

File Structure Fundamentals (D.H.)19 Fixed-Length Records E.G. class Person { public: char last[11]; char first[11]; char address[16]; char city[16]; char state[3]; char zip[10]; } Will produce a fixed size record of size 67 bytes.

File Structure Fundamentals (D.H.)20 Fixed-Length Records The fixed length record structure, however, does NOT imply, the fixed -length field structure. Fixed-length records are frequently used as “containers” to hold variable numbers of variable-length fields. Fixed-length record structures are among the most commonly used methods for organizing files.

File Structure Fundamentals (D.H.)21 Records with a Predicable Number of Fields The method specifies the number of fields in each record. Regardless of the method for storing fields, this approach allows for relatively easy means for calculating record boundaries.

File Structure Fundamentals (D.H.)22 Records with a Length Indicator This method requires that each record begin with a length indicator. This method is commonly used for handling variable-length records.

File Structure Fundamentals (D.H.)23 Index File to Keep Track of Record Addresses This method uses an index file (or an index block) to keep a byte offset for each record in the original data file. The byte offsets (record addresses) allow us to find the beginning of each successive record and compute the length of each record.

File Structure Fundamentals (D.H.)24 Questions. What is the byte offset or just offset of a file? What C++ functions use the byte offset and what is their purpose?

File Structure Fundamentals (D.H.)25 Records Separated with Delimiters This method is analogous to the use of delimiters to separate fields. As with fields the delimiter must be well chosen and it cannot be a part of data. Common delimiter is the end-of-line character ‘\n’, since records often are read directly to the console.

File Structure Fundamentals (D.H.)26 A Record Structure that Uses a Length Indicator Use a memory buffer to store the data that is going to be written to the disk. Write down the size of the record at the beginning of it. Write down the buffer contents after writing the size.

File Structure Fundamentals (D.H.)27 A Sample C++ Code that Uses Records with a Length Indicator const int MaxBufferSize=200; int writePerson (ostream streamF, person &p) {char buffer[MaxBufferSize]; //create a buffer strcpy(buffer, p.last); strcat(buffer,’|’); strcat(buffer, p.first);strcat(buffer,’|’); strcat(buffer, p.address);strcat(buffer,’|’); strcat(buffer, p.city);strcat(buffer,’|’); strcat(buffer, p.state);strcat(buffer,’|’); short length=strlen(buffer); streamF.write(&length, sizeof(length); streamF.write(&buffer, length); }

File Structure Fundamentals (D.H.)28 Reading the Variable-Length Records from the File int readPerson (istream &streamF, Person &p) { short length; streamF.read(&length,sizeof(length); char *buffer = new char[length+1]; stream.F.read(buffer, length); buffer[length]=0; istrstream strbuff(buffer); strbuff >>p; return 1; }