Data files ? ? ? ?. Data processing: in main memory Economic problems -> big size data -> stored...

Post on 11-Jan-2016

215 views 0 download

Tags:

transcript

Algorithms and programing techniques

Data files

? ??

?

Data files

Data processing: in main memory Economic problems -> big size data -> stored in

external memory

Organization (identification, classification, description, representation etc.) internal external: logical / physical transformation (during I/E operations)

Concepts file and record organization methods and access types processing operations

Logical level File: external data structure

▪ linear, ordered, homogeneous (meaning and processing)▪ composed of records (equal or varied length)

Record: data structure concerning one entity▪ inhomogeneous, ordered▪ composed of fields

Physical level File: OS records, actual data: flow of bytes, no inherent

meaning Representation: text, binary

A0 A1 A2 A3 An......

FileFile

RecordRecord

End of record marker

End of record marker

End of file marker

End of file marker

File and record

Text files: CR/LF (13, 10)Binary files: nothing

Text files: EOF (27, CTRL-Z)Binary files: nothing

File and record

Transfer between external storage and internal memory read / write record level: adequate descriptions and operations

Internal record structure fixed structure struct variable structure union fixed part + variable part struct + union

Internal memory

/E

File buffer areaArt.i Art.i+1 Art.i+2 ... Art.i+kFile

I/

XInternal variableCurrent

position

Accesible memory

Organization methods and access types

Organization method Principles and rules protection and

retrieval▪ sequential▪ relative▪ indexed▪ etc. (selective, reversed, linked, multi-indexed …)

Access types A way of finding records inside a file▪ sequential▪ direct (by relative number / key)

Sequential access

Implemented in all languages ,

Detect the end of file?

A0 A1 ... Ak-1 Ak ... An EOF

P( Ak ) = f( P(Ak-1) )

Traversing

A0 A1 ... Ak-1 Ak ... An EOF

Pointer position after reading the last record

Direct access by relative number

Implemented in some languages (Pascal/Delphi, Cobol)

00 11 ...... k-1k-1 kk ...... nn

A0 A1 ... Ak-1 Ak ... An EOF

Direct access by relative number kP( Ak ) = k * lart

Relative number

Direct access by key

Implemented in some languages (Cobol)

A0 A1 ... Ak-1 Ak ... An EOF

Direct access by the key of record kP( Ak ) = f(cheiek)

Detection of end of file

Direct influence on design of algorithms

By reading (Fortran, Cobol, C) Depicted position IS NOT considered end of file

Read-independent (Basic, Pascal/Delphi) Depicted position IS considered end of file

A0 A1 ... Ak-1 Ak ... An EOF

Pointer position after reading last record

Sequential organization

Sequentially organized file same / varied length records records are stored in the order they were added access types: sequential, direct (depending on file support) examples: text file (varied length records), binary data files (same length

records)

Art.1 Art.2 Art.3 Art.4 ... Art.i ... Art.n

File starts here

Records

End of record markers (physical / logical)

End of file marker

0 1 2 3 4 5 6 7 8 9 10 11 12 13 14

Free spaces

Valid records

Relative organization

Relative organized file same length records relative key: numerical, domain of values records are stored at the position indicated by the key biunivocal

relationship▪ free spaces, valid records

access types: sequential, direct (relative key relative number) examples: binary data files

Indexed organization

Indexed file two physical files: index file, data file (sequential) same length records alphanumerical keys records are stored in the data file in the order they were added Access types: sequential, direct (key)

Index file

Data file0 1 2 3 4 5 6 7 8 9 10 11 12 13

3 - aaaa 6 - aaab 0 - aaac 12 - aaba 8 - abaa 13 - abba 4 - baaa 7 - baca

Processing operations

File level gain access (open) end acces (close) File must be closed delete rename etc.

Record level File must be open populate add record(s) retrieve record(s) modify record(s) delete record(s)

Basic operations read / write with / without conversion

Homework: subchapters 2.1,2.2,2.3, 2.4

Spor la învăţat!