HTTP://WWW.COMPUTER-WORLD1.COM

Computer World
Computer World
Computer World
Computer World
Computer World
Computer World
Computer World
Computer World
Computer World
Computer World
Computer World
Computer World
Computer World
Computer World
Computer World
Computer World
Computer World
Computer World
Computer World
Computer World
Computer World
Computer World
Computer World
Computer World
Computer World
Computer World
Computer World
Computer World
Computer World
Computer World


The Web Ask
 


 
Computer Information
MENU  
  COMPUTER HELP
  Computing Notes
  => 1 Introduction To Computing
  => 1.1 Computer Hardware
  => 1.2 Computer Software
  => 1.3 The Human-Computer Interface
  => 1.4 Business Information Systems
  => 1.5 Batch Processing
  => 2 Word Processing
  => 2.1 Introduction
  => 2.2 Editing Facilities
  => 2.3 Bullets And Numbering
  => 2.4 Layout Facilities
  => 2.5 Headers And Footers
  => 2.6 Style Controls
  => 2.7 Spelling And Grammar Checking
  => 2.8 Inserting Columns
  => 2.9 Borders And Shading
  => 2.10 Tables
  => 2.11 Inserting Graphics
  => 2.12 Mail Merging
  => 2.13 Macros
  => 3 Programming In QuickBASIC
  => 3.1 Introduction
  => 3.2 Variables, Input And Output
  => 3.3 Arithmetic Operators
  => 3.4 Iteration
  => 3.5 Selection
  => 3.6 Functions
  => 3.7 Subprograms
  => 3.8 Recursion
  => 3.9 Arrays
  => 3.10 Program Structure
  => 3.11 Jackson Structure Diagrams
  => 3.12 String Processing
  => 4 Data Representation
  => 4.1 Different Computer Codes
  => 4.2 Binary Integers
  => 4.3 Higher Number Bases
  => 4.4 Graphics, Sounds And Other Interpretations
  => 4.5 Fixed Point Binary Numbers
  => 4.6 Floating Point Binary Numbers
  => 4.7 Range And Accuracy
  => 5 Spreadsheets
  => 5.1 Introduction
  => 5.2 General Features
  => 5.3 "What If" Calculations
  => 5.4 Changing The Workbook's Appearance
  => 5.5 Relative And Absolute Reference
  => 5.6 Sorting And Filters
  => 5.7 Charts
  => 5.8 Lookup
  => 5.9 The IF Function
  => 5.10 Goal Seeker
  => 5.11 Solver
  => 5.12 Macros
  => 6 Files
  => 6.1 File Concepts
  => 6.2 Serial & Sequential Files
  => 6.3 Indexed Sequential Files
  => 6.4 Random Access Files
  => 6.5 Overview of File Processing
  => 7 Standard Algorithms
  => 7.1 Linear Searches
  => 7.2 Binary Search
  => 7.3 Internal Sorting
  => 7.4 External Sorting
  => 8 Legal Issues And Data Security
  => 8.1 The Computer Missuse Act 1990
  => 8.2 The Data Protection Act 1984
  => 8.3 Computer Fraud
  => 8.4 Software Copyright
  => 8.5 Viruses And Trojans
  => 8.6 Security Of Data
  => 8.7 Data Integrity
  => 9 Databases
  => 9.1 Flat-file Databases
  => 9.2 Introduction To Relational Databases
  => 9.3 The Aims Of Database Normalisation
  => 9.4 Security And Integrity Issues
  => 9.5 Database Management
  => 10 Data Structures
  => 10.1 Introduction
  => 10.2 Linear Lists
  => 10.3 Linked Lists
  => 10.4 Queues
  => 10.5 Stacks
  => 10.6 Binary Trees
  => 11 Systems Development
  => 11.1 Introduction
  => 11.2 Analysis
  => 11.3 Design
  => 11.4 Graphical System Representation
  => 11.5 Development
  => 11.6 Testing
  => 11.7 Implementation
  => 11.8 Maintenance
  => 11.9 System Documentation
  => 12 Peripherals
  => 12.1 Input Devices
  => 12.2 Output Devices
  => 12.3 Storage Devices
  => 13 Computer Architecture
  => 13.1 The Processor And Memory
  => 13.2 The Fetch-Execute Cycle
  => 13.3 Data Buses
  => 13.4 Processing Architectures
  => 13.5 Assembly Language
  => 14 Translation
  => 14.1 Interpreters
  => 14.2 Compilers
  => 14.3 Compilation Phases
  => 14.4 Assemblers
  => 15 Operating Systems
  => 15.1 Operating System Functions
  => 15.2 Different OS Modes
  => 15.3 Job Control Language
  => 15.4 The Scheduler And Dispatcher
  => 15.5 Memory Management
  => 15.6 Peripheral Control
  => 15.7 Backing Store Management
  => 16 High Level Programming
  => 16.1 High And Low Level Languages
  => 16.2 Language Classification
  => 16.3 Language Generations
  => 16.4 Logic Programming
  => 16.5 Choosing A Programming Language
  => 17 Computers & Communication
  => 17.1 Data Transmission
  => 17.2 Local Area Networks
  => 17.3 Wide Area Networks
  => 17.4 The Internet
  बातमी वाचु शकता
  जनरल नॉलेज
  HELPLINE
  GALLERY
  Calculators and Converters
  Zoo Animal Photos
  Short form list
  LOGIN
  HOME
  CONTACT
  CHAT ME !!!
  INTRODUCTION
  SUBMIT URLs
  ADD OWN LINK
  Banner Exchange
  IPL T20 Live Scores
  NATIONAL ANTHEM OF INDIA
  Birthday Reminder
  FUNNY PAGE
  TOP LIST
  MAP AND SATELLITE IMAGE
  Your IP Address
  MOBILE WAP SETTINGS
  INDEX



Bookmark and Share



Online Reference
Dictionary, Encyclopedia & more
Word:
Look in: Dictionary & thesaurus
Medical Dictionary
Legal Dictionary
Financial Dictionary
Acronyms
Idioms
Encyclopedia
Wikipedia
Periodicals
Literature
Other languages:
by:


INDIA
6.4 Random Access Files
Section 6.4

6 Files

6.4 Random Access Files

Records are written and retrieved from disk in adirect or random way.

Random file organisation requires direct access storage (DAS) media.

The program that stores and retrieves the records has to specify the address of the record first of all.

A field is selected to be the key for each record.

An algorithm (a set of instructions) turns the value of the records key into an address for the record.

6.4.1 Address Generation

The simplest method uses the value of the key field as the record address.

Example

Record Address Customer Number Customer Name
1 1 <empty record>
2 2 <empty record>
104 104 Davis
208 208 Peterson
405 405 Franks
408 408 Black

However, with this method, records are often too spaced out.

6.4.2 Hashing Algorithms

Hashing algorithms convert a records key into an address for the records.

With numeric keys a common hashing algorithm is:

The Division-Remainder Method

  1. Estimate the number of records to store.
  2. Find the first prime number greater than the number of records.
  3. The key of the record to be stored is divided by this prime number and the remainder is used as the address.

For alpha-numeric key fields a common way of hashing the string to a record address is to add up the ASCII values of the characters and find the remainder on division of the sum.

Pseudocode

INPUT record details

sum = 0

FOR letter = 1 TO length of record's key
    extract character
    find ASCII code
    add it to sum
NEXT letter

address = sum MOD nearest prime

6.4.3 Synonyms

When two record keys are hashed to the same address, we say that they are synonyms.

Possible Solutions

  1. Put the second in the next avaliable space.
  2. Use a separate overflow area for such records.

As with indexed sequential files, at some point we may need to reorganise the file.

6.4.4 Composite Data Types

As well as the standard data types in QuickBASIC we can also define our own data types using the TYPE statement.

Example

TYPE MyRecord
    Aname AS STRING * 12
    Phone AS STRING * 12
    Units AS INTEGER
    Price AS SINGLE
    Amount AS DOUBLE
END TYPE

This is a composite data type.

We can now dimension variables and arrays as this new data type.

DIM details AS MyRecord

We can now store several items of data in one variable.

details.Aname = "James Bond"
details.Amount = 0.07

Likewise, we can do the same for arrays.

Example

DIM detailsarray (1 TO 10) AS MyRecord

Each element of the 1D array would have the composite parts as defined in the TYPE statement.

detailsarray(1).Aname = "Another Person"
detailsarray(1).Amount = 0.95

6.4.5 Data Storage In Random Access Files

Although it is possible to have variable length records with random access files it is simpler to work with fixed length records.

Random access records are stored in a different way to sequential records.

Example

Field Name Data Type Example
Customer's Name $ Jones P.
Telephone Number $ 01503 123456
Phone Units Used % 428
Price Per Unit ! 8.0
Total To Pay # 3424.0

These data types are combined into a composite data type.

We need to decide how many characters to allow for each field.

The customer's name and telephone number are simple as they are strings. We decide that no customers have names over 20 characters long. We allow 12 characters for the phone number.

Storing Numeric Data

In sequential files numbers were stored as a series of ASCII characters. For example: 17,002 is stored using five bytes; one for each digit.

This is wasteful of memory, and in random access files, numbers are saved in a compressed binary format.

In general:

Integers take: 2 bytes
Long integers take: 4 bytes
Floating point (single precision): 4 bytes
Double precision floating point: 8 bytes

So we can now complete our example:

Field Name Data Type Bytes Required Example
Customer's Name $ 20 Jones P.
Telephone Number $ 12 01503 123456
Phone Units Used % 2 428
Price Per Unit ! 4 8.0
Total To Pay # 8 3424.0

6.4.6 Inserting Data Into A Random Access File

Step 1

First, the field structure of each record is defined by means of the TYPE - END TYPE statement.

TYPE MyRecord
    Aname AS STRING * 12
    Phone AS STRING * 12
    Units AS INTEGER
    Price AS SINGLE
    Amount AS DOUBLE

Step 2

An array or variable is explicity declared.

DIM Phonebill AS MyRecord

Step 3

Open our random file.

OPEN "G:Raphone.dat" FOR RANDOM AS #n LEN = L%

where n is the number and L% is the length of each record in bytes.

Note that random files are opened for input and output simultaneously.

Step 4

Now we assign data to our variable, phonebill.

phonebill.Aname = "Adams M"
phonebill.Phone = "01802 123456"

Step 5

We can now store this data into our file by

PUT #n, m, phonebill

where n is the channel number and m is the record address.

Step 6

Finally the file is closed.

CLOSE #n

As with inserting data we need to have declared a variable or array with a composite data type that matches the files field structure.

As before we open the file using

OPEN "G:Raphone.dat" FOR RANDOM AS #n LEN = L%

where n is the channel number and L% is the length of each record in bytes.

Now we can retrieve the data using

PUT #n, m, phonebill

where n is the channel number and m is the record address.

When we've finished retrieving data we close the channel.

CLOSE #n

6.4.7 Retrieving Data From A Random Access File

If we wish to find out how many bytes are in a random file we can use

LOF(n)

If this is divided by the byte length of each record, the number of records can be calculated.

6.4.8 Variable Length Records In A Random Access File

If the number of characters in a string field varies greatly or the number of fields in the record varies then the use of variable length records is appropriate.

There are two ways of implementing:

  1. Pick your own end of field and/or record markers.

  2. The first byte of each field is a character count.


< Previous Back To Topic Next >

COMPUTER-WORLD1  
 
Username:
Password:
 
SHOUTBOX  
 








 
SMS 160by2  
 
Forgot Password / Username

 
VISITS  
 
 
Time  
  free guide to setting up a website
 
Today, there have been 77 visitorson this page!
Matrimony Search Widgets
Matrimony Search


Home
SILICONINDIA FACEBOOK YOUTUBE MYSPACE

HOME :: :: INDEX :: :: COMPUTING NOTES :: ::COMPUTER HELP

This website was created for free with Own-Free-Website.com. Would you also like to have your own website?
Sign up for free