De presentatie wordt gedownload. Even geduld aub

De presentatie wordt gedownload. Even geduld aub

Basiscursus Informatica, 98-99 College 8, H 8 1 Basiscursus Informatica 98/991 Basiscursus Informatica College 8, File Structures Brookshear H8 Richard.

Verwante presentaties


Presentatie over: "Basiscursus Informatica, 98-99 College 8, H 8 1 Basiscursus Informatica 98/991 Basiscursus Informatica College 8, File Structures Brookshear H8 Richard."— Transcript van de presentatie:

1 Basiscursus Informatica, 98-99 College 8, H 8 1 Basiscursus Informatica 98/991 Basiscursus Informatica College 8, File Structures Brookshear H8 Richard Benjamins

2 Basiscursus Informatica, 98-99 College 8, H 8 2 Basiscursus Informatica 98/992 Overzicht college 8 n Sequentiele files n Text files (sequentieel) n Indexed files n Hashed files n Rol van besturingsysteem n Gebruiker denkt in conceptuele data structuren n Implementatie in massa opslag (disk) n Waarom massaopslag? ä ruimte ä permanent ä backups

3 Basiscursus Informatica, 98-99 College 8, H 8 3 Basiscursus Informatica 98/993 Sequential files, opbouw n Stel: studenten-administratie-systeem ä studiesituatie van alle studenten bepalen ä loop een voor een af en reken studiepunten uit ä sequentiele file n File = Record1, Record2,..., Recordn, EOF ä Andersen, Benjamins, Brouwer,... n Record = Field1, Field2,..., Fieldn ä Achternaam, adres, collegekrtno, studiepunten

4 Basiscursus Informatica, 98-99 College 8, H 8 4 Basiscursus Informatica 98/994 Sequentiele files n Conceptueel ä toegang tot informatie in file is sequentieel n Fysiek ä records kunnen verspreid over disk zijn Rec #1 Rec #2 Rec #3 Rec #4 EOF......... disk sector 1: rec#1, #2 sector 2: rec#3, #4 FILE INFO 1-2 sector1 3-4 sector2......

5 Basiscursus Informatica, 98-99 College 8, H 8 5 Basiscursus Informatica 98/995 Sequentiele files: bewerken n Studenten-adm. updaten: ä zoek student in de file ä werk gegevens bij ä zoek volgende student n Niet erg efficient ä elke keer opnieuw zoeken vanaf scratch n Beter: bij te werken gegevens in zelfde volgorde als records in sequentiele file

6 Basiscursus Informatica, 98-99 College 8, H 8 6 Basiscursus Informatica 98/996 Keyfield n Sequentiele files zijn geordend volgens een keyfield ä alphabetisch ä numeriek (bv. collegekrtno) n Sorteer bij te werken gegevens volgens zelfde keyfield ä Gegevens bijgewerkt zonder telkens te zoeken ä maar een voor een in juiste volgorde

7 Basiscursus Informatica, 98-99 College 8, H 8 7 Basiscursus Informatica 98/997 Toegang sequentiele files n Elke programmeertaal komt met primitieven voor sequentiele files ä Pascal: read(File, Record), write(File, Record) n Lokatieinformatie is impliciet ä record dat gelezen wordt, is het volgende record n eof(File) is “true” als: Rec #1 Rec #2 Rec #3 Rec #4 EOF.........

8 Basiscursus Informatica, 98-99 College 8, H 8 8 Basiscursus Informatica 98/998 Merging van seq. files n Gegeven: studenten file (master file), sorted sorted nieuwe studenten (transaction file) Keyfield: collegekrtno n Gevraagd: nieuwe studenten-file merge 940104 941113 961304 eof 952111 981206 eof 940104 941113 952111 961304 981206 eof mastertransaction

9 Basiscursus Informatica, 98-99 College 8, H 8 9 Basiscursus Informatica 98/999 Overzicht college 8 n Sequentiele files n Text files (sequentieel) n Indexed files n Hashed files n Rol van besturingsysteem

10 Basiscursus Informatica, 98-99 College 8, H 8 10 Basiscursus Informatica 98/9910 Text files n Sequent. file met max lengte record van 1 byte n Record = 1 Field = 1 Byte ä 1 byte = 1 symbool of 1 controle teken (^m) n Alternatieve conceptualisatie: 1 record=1 regel (eol) A B C ….. eol

11 Basiscursus Informatica, 98-99 College 8, H 8 11 Basiscursus Informatica 98/9911 Manupulatie van text files n In massa-opslag: tekstfile verdeeld in multiple-byte eenheden die fysieke records vormen n Manipulatie (read/write) door software dmv buffer in centrale geheugen ä read van bytes: -retrieve aantal fysieke records -stop in buffer ä write van text file: -verzamel bytes in buffer - als fysiek record gevuld - schrijf weg naar disk

12 Basiscursus Informatica, 98-99 College 8, H 8 12 Basiscursus Informatica 98/9912 Buffer disk read write programma buffer File Info..... sector1..... sector2...... Wat gebeurt er als we om een character vragen en - zit al in buffer? - zit niet in buffer? Wat gebeurt er als er meedere pagina’s worden gevraagd op de monitor?

13 Basiscursus Informatica, 98-99 College 8, H 8 13 Basiscursus Informatica 98/9913 Overzicht college 8 n Sequentiele files n Text files (sequentieel) n Indexed files n Hashed files n Rol van besturingsysteem

14 Basiscursus Informatica, 98-99 College 8, H 8 14 Basiscursus Informatica 98/9914 Geindexeerde files n Als je een willekeurig record wilt, is het erg kostbaar om records een voor een af te lopen ä voor elke retrieval, sequential search: traag ä interactieve systemen (resultaat bepaald student) n Idee geindexeerde files: n Aanname: keyfield waarde is altijd bekend key lokatie record op disk

15 Basiscursus Informatica, 98-99 College 8, H 8 15 Basiscursus Informatica 98/9915 (Multiple) index disk key: collegekrtno 940104 941113 952111 961304..... File met twee indexen: inverted file secondary key: naam Andersen Brouwer Colijn Fortuin..... primary

16 Basiscursus Informatica, 98-99 College 8, H 8 16 Basiscursus Informatica 98/9916 Andere kant medaille n Geindexeerde files hebben directe (en sequentiele) toegang, maar... n Als records toegevoegd en verwijderd worden ä updaten index, kost tijd ä multiple indexes kost nog meer tijd n Merk op: directory structuur in OS is ook index

17 Basiscursus Informatica, 98-99 College 8, H 8 17 Basiscursus Informatica 98/9917 Index organisatie n Index komt in centraal geheugen (vanaf disk) n Moet niet te groot zijn, anders past er niet in n Als te grote index ä partial index –keyfield wijs naar segment met aantal records ipv naar 1 record ä hierarchische index –keyfield verwijst naar andere index (vgl directory stucture in OS)

18 Basiscursus Informatica, 98-99 College 8, H 8 18 Basiscursus Informatica 98/9918 Partial index 10 20 3010 20...... Waarom gebruik je de grootste key om een segment te repre- senteren? Index keysegment locatie File opgedeeld in segmenten 9 8 18 19

19 Basiscursus Informatica, 98-99 College 8, H 8 19 Basiscursus Informatica 98/9919 Hierarchische index K U Z key subindex File opgedeeld in segmenten D G K O R U X Y Z key subindex Index B C D E F G H I J K L M N O

20 Basiscursus Informatica, 98-99 College 8, H 8 20 Basiscursus Informatica 98/9920 Overzicht college 8 n Sequentiele files n Text files (sequentieel) n Indexed files n Hashed files n Rol van besturingsysteem

21 Basiscursus Informatica, 98-99 College 8, H 8 21 Basiscursus Informatica 98/9921 Hashed files n Sequential files hebben sequentiele toegang n Indexed files hebben zowel directe (random) als sequentiele toegang ä overhead van bijhouden index n Hashed files hebben alleen directe toegang (random access) ä zonder overhead van index ä mbv hash algoritme

22 Basiscursus Informatica, 98-99 College 8, H 8 22 Basiscursus Informatica 98/9922 Hash techniek n Deel de te gebruiken massa opslag op in secties, “buckets” n Kies keyfield n Verdeel keys over buckets n Basisidee: Key Hash algoritme {0,..., n} bucket#0 bucket#1 bucket#n.....

23 Basiscursus Informatica, 98-99 College 8, H 8 23 Basiscursus Informatica 98/9923 Hashing systeem: key/40 Keys : 14, 54, 93, 94, 133, 335 14/40= 0+14 54/40= 1+14 93/40= 2+13 94/40= 2+14 133/40= 3+13 335/40= 8+15 remainders = buckets #12#13#14#15#16 9314 54 94 335 hash algoritme

24 Basiscursus Informatica, 98-99 College 8, H 8 24 Basiscursus Informatica 98/9924 Vb. hashing een student Key field waarde:9801 ASCII: 00111001001110000011000000110001 Equivalent in 10-basis: > 2 29 ~ 536870912 Remainder na /40: 32 Bucket nummer:32

25 Basiscursus Informatica, 98-99 College 8, H 8 25 Basiscursus Informatica 98/9925 Distributie-problemen n Als keys een bepaald patroon vertonen: ä bv. 5, 10, 20,... n En ze hebben een factor gemeenschappelijk met het aantal buckets ä bv. 5 n Dan worden alleen bepaalde buckets gevuld ä bucket 0 n Keys clusteren in bepaalde buckets ä retrieval binnen bucket is sequentieel

26 Basiscursus Informatica, 98-99 College 8, H 8 26 Basiscursus Informatica 98/9926 Vb. distributie-probleem Keys : 14, 54, 93, 94, 133, 335 14/40= 0+14 54/40= 1+14 93/40= 2+13 94/40= 2+14 133/40= 3+13 335/40= 8+15 remainders = buckets #12#13#14#15#16 9314 54 94 335 hash algoritme

27 Basiscursus Informatica, 98-99 College 8, H 8 27 Basiscursus Informatica 98/9927 Clusteren n Voorkomen: neem aantal buckets met minimaal aantal factoren: priemgetal ä deelbaar door zichzelf en 1 n Clusteren kan wel verminderd worden, maar niet voorkomen ä 41 buckets kans op 1 key per bucket: (41/41)(40/41)(39/40)...(34/41) =.482 ä dus: kans op twee keys in zelfde bucket is al groter dan 0.5 bij 8 keys ä twee keys naar zelfde bucket: collision

28 Basiscursus Informatica, 98-99 College 8, H 8 28 Basiscursus Informatica 98/9928 Section overflow n Grote kans op collisions ä dus altijd rekening houden met clustering ä maatregelen voor mogelijke problemen n Overflow: ä bucket is vol, maar er wordt nog een key bij gehashed n Oplossing: overflow sectie gelinked aan bucket n Nadeel: efficiente gaat naar beneden ä sequentiele toegang in overflow sectie

29 Basiscursus Informatica, 98-99 College 8, H 8 29 Basiscursus Informatica 98/9929 Overflow #0 #1 #2 #3 #4 NIL Overflow opslaggebied Overflow pointers Opslag buckets

30 Basiscursus Informatica, 98-99 College 8, H 8 30 Basiscursus Informatica 98/9930 Overzicht college 8 n Sequentiele files n Text files (sequentieel) n Indexed files n Hashed files n Rol van besturingsysteem

31 Basiscursus Informatica, 98-99 College 8, H 8 31 Basiscursus Informatica 98/9931 Besturingsysteem n Voor gebruiker zijn details van file niet nodig ä standaard procedures, commando’s n OS communiceert met proc. en moet weten waar het overgaat ä structuur van file, keyfield, huidige positie, soort toegang (read, write), etc. n File descriptor ä bevat alle info nodig voor het verwerken van een file ä manipuleerbaar en toegankelijk voor standaard procedures

32 Basiscursus Informatica, 98-99 College 8, H 8 32 Basiscursus Informatica 98/9932 Vanuit PL, vb. open(unit=10, file=‘filename’, status=old, access=sequential) vraagt aan OS om file descriptor te maken voor de file ‘filename’ om iets met de file te doen close(unit=10) file ‘10’ is bijgewerkt en wordt afgesloten Verschil interne en externe file naam: unit=10 versus filename Komt door verschillende syntax programmeertalen en OS


Download ppt "Basiscursus Informatica, 98-99 College 8, H 8 1 Basiscursus Informatica 98/991 Basiscursus Informatica College 8, File Structures Brookshear H8 Richard."

Verwante presentaties


Ads door Google