Microsoft PowerPoint - 알고리즘_4주차_1차시.pptx

Similar documents
슬라이드 1

Microsoft PowerPoint - 알고리즘_1주차_2차시.pptx

13주-14주proc.PDF

6주차.key

chap7.key

untitled

Chapter 4. LISTS

PowerPoint 프레젠테이션

歯9장.PDF

5.스택(강의자료).key

untitled

Microsoft PowerPoint - 알고리즘_11주차_2차시.pptx

_KF_Bulletin webcopy

10주차.key

Microsoft PowerPoint - ch09 - 연결형리스트, Stack, Queue와 응용 pm0100

C++-¿Ïº®Çؼ³10Àå

chap 5: Trees

Microsoft PowerPoint - a10.ppt [호환 모드]

03장.스택.key

<32B1B3BDC32E687770>

제1장 Unix란 무엇인가?

歯7장.PDF

chap7.PDF

강의10

제12장 파일 입출력

Columns 8 through while expression {commands} 예제 1.2 (While 반복문의이용 ) >> num=0

해양모델링 2장5~ :26 AM 페이지6 6 오픈소스 소프트웨어를 이용한 해양 모델링 물리적 해석 식 (2.1)의 좌변은 어떤 물질의 단위 시간당 변화율을 나타내며, 우변은 그 양을 나타낸 다. k 5 0이면 C는 처음 값 그대로 농

Page 2 of 5 아니다 means to not be, and is therefore the opposite of 이다. While English simply turns words like to be or to exist negative by adding not,

Microsoft PowerPoint - 3ÀÏ°_º¯¼ö¿Í »ó¼ö.ppt

하나님의 선한 손의 도우심 이세상에서 가장 큰 축복은 하나님이 나와 함께 하시는 것입니다. 그 이 유는 하나님이 모든 축복의 근원이시기 때문입니다. 에스라서에 보면 하나님의 선한 손의 도우심이 함께 했던 사람의 이야기 가 나와 있는데 에스라 7장은 거듭해서 그 비결을

step 1-1

휠세미나3 ver0.4

제1장 Unix란 무엇인가?

K&R2 Reference Manual 번역본

PowerPoint Presentation

Microsoft Word - FunctionCall

2014 HSC Korean Continuers

BMP 파일 처리

PowerPoint Presentation

Microsoft PowerPoint - 알고리즘_5주차_1차시.pptx

PowerPoint 프레젠테이션

Microsoft PowerPoint - 알고리즘_2주차_1차시.pptx


PowerPoint 프레젠테이션

강의 개요

SRC PLUS 제어기 MANUAL

Chap06(Interprocess Communication).PDF

Chapter 4. LISTS

Motor

6자료집최종(6.8))

chap01_time_complexity.key

10.


Page 2 of 6 Here are the rules for conjugating Whether (or not) and If when using a Descriptive Verb. The only difference here from Action Verbs is wh

12-file.key

PowerPoint 프레젠테이션

Something that can be seen, touched or otherwise sensed

4. #include <stdio.h> #include <stdlib.h> int main() { functiona(); } void functiona() { printf("hihi\n"); } warning: conflicting types for functiona

chap8.PDF

Modern Javascript

Chapter 4. LISTS

슬라이드 제목 없음

프로그램을 학교 등지에서 조금이라도 배운 사람들을 위한 프로그래밍 노트 입니다. 저 역시 그 사람들 중 하나 입니다. 중고등학교 시절 학교 도서관, 새로 생긴 시립 도서관 등을 다니며 책을 보 고 정리하며 어느정도 독학으르 공부하긴 했지만, 자주 안하다 보면 금방 잊어

T100MD+

No Slide Title

목차 BUG 문법에맞지않는질의문수행시, 에러메시지에질의문의일부만보여주는문제를수정합니다... 3 BUG ROUND, TRUNC 함수에서 DATE 포맷 IW 를추가지원합니다... 5 BUG ROLLUP/CUBE 절을포함하는질의는 SUBQUE

0. 표지에이름과학번을적으시오. (6) 1. 변수 x, y 가 integer type 이라가정하고다음빈칸에 x 와 y 의계산결과값을적으시오. (5) x = (3 + 7) * 6; x = 60 x = (12 + 6) / 2 * 3; x = 27 x = 3 * (8 / 4

CD-RW_Advanced.PDF

À©µµ³×Æ®¿÷ÇÁ·Î±×·¡¹Ö4Àå_ÃÖÁ¾

The Pocket Guide to TCP/IP Sockets: C Version

Let G = (V, E) be a connected, undirected graph with a real-valued weight function w defined on E. Let A be a set of E, possibly empty, that is includ

MPLAB C18 C

PowerPoint 프레젠테이션


Microsoft PowerPoint - ch10 - 이진트리, AVL 트리, 트리 응용 pm0600

2007_2_project4

<C1DF3320BCF6BEF7B0E8C8B9BCAD2E687770>

<443A5C4C C4B48555C B3E25C32C7D0B1E25CBCB3B0E8C7C1B7CEC1A7C6AE425CBED0C3E0C7C1B7CEB1D7B7A55C4C656D70656C2D5A69762E637070>

<B1E2C8B9BEC828BFCFBCBAC1F7C0FC29322E687770>

2002년 2학기 자료구조


Chapter_06

Line (A) å j a k= i k #define max(a, b) (((a) >= (b))? (a) : (b)) long MaxSubseqSum0(int A[], unsigned Left, unsigned Right) { int Center, i; long Max

11장 포인터

Journal of Educational Innovation Research 2019, Vol. 29, No. 1, pp DOI: (LiD) - - * Way to

Microsoft PowerPoint - chap2

SIGPLwinterschool2012

MAX+plus II Getting Started - 무작정따라하기

Polly_with_Serverless_HOL_hyouk

퇴좈저널36호-4차-T.ps, page Preflight (2)

OCaml

(Humphery Kim) RAD Studio : h=p://tech.devgear.co.kr/ : h=p://blog.hjf.pe.kr/ Facebook : h=p://d.com/hjfactory :

Microsoft PowerPoint APUE(Intro).ppt

컴파일러

11 템플릿적용 - Java Program Performance Tuning (김명호기술이사)

Microsoft Word - KPMC-400,401 SW 사용 설명서

Microsoft PowerPoint APUE(File InO).ppt

Java

Microsoft PowerPoint - AC3.pptx

Transcription:

Chapter 4 Fundamental File Structure Concepts Reference: M. J. Folk and B. Zoellick, File Structures, Addison-Wesley (1992).

TABLE OF CONTENTSN Field and Record Organization Record Access More about Record Structures File Access and File Organization 영남대학교데이터베이스연구실 Algorithm: Chapter 4 (Page 1)

1. Field and Record Organization at 11 1.1 A Stream File 정의 File : Stream of byte 로구성 예 : 이름과주소정보를저장하는 File (Program 1) 실행예 John Ames Alan Mason 123 Maple 90 Eastgate Stillwater, OK 74075 Ada, OK 74820 AmesJohn123 MapleStillwaterOK74075MasonAlan90.. 영남대학교데이터베이스연구실 Algorithm: Chapter 4 (Page 2)

Stream File 의문제점 Information loss : 정보단위가불명확 Field 의개념필요 Field? Smallest logically meaningful unit of information in a file Conceptual tool 영남대학교데이터베이스연구실 Algorithm: Chapter 4 (Page 3)

Creates name and address file that is strictly a stream of bytes -- writstrm.c #include "fileio.h" #define out_str(fd,s) s) write((fd),(s),strlen(s)) (s) strlen(s)) main () { char first[30], last[30], address[30], city[20]; char state[15], zip[9], filename[15]; int fd; printf("enter the name of the file you wish to create: "); gets(filename); if ((fd = open(filename, O_WRONLY O_CREAT O_EXCL)) < 0) { printf("file opening error --- program stopped n"); exit(1); 영남대학교데이터베이스연구실 Algorithm: Chapter 4 (Page 4)

printf(" n ntype in a last name (surname), or <CR> to exit n"); gets(last); t(l t) while (strlen(last) > 0) { printf(" nfirst Name:"); gets(first); printf(" Address:"); gets(address); printf(" City:"); gets(city); printf(" State:"); gets(state); printf(" Zip:"); gets(zip); /* output the strings to the buffer and then to the file */ out_str(fd,last); t t) out_str(fd,first); t fi t) out_str(fd,address); t dd out_str(fd,city); out_str(fd,state); out_str(fd,zip); /* prepare for next entry */ printf(" n ntype in a last name, or <CR> to exit n"); gets(last); close(fd);

1.2 Field Structures File 내에서 field 표현방법 Force the field into a predictable length Begin each field with a length indicator 각 field 의끝에 delimiter 사용 "keyword = value" 사용 영남대학교데이터베이스연구실 Algorithm: Chapter 4 (Page 6)

Force the Length of Fields 정의 struct { char last_name[10]; char first_name[10]; char address[15]; char city[15]; char state[2]; char zip[9]; set_of_fields; 장점 구현용이, 가장많이사용 단점 기억공간낭비 주어진공간보다큰데이터저장불가 가변길이 field가많이존재할경우, 사용곤란 영남대학교데이터베이스연구실 Algorithm: Chapter 4 (Page 7)

가변길이 Field 의구현방법 Begin Each Field with a Length Indicator 각 field 의시작시, 그 field 의길이저장 (Field 크기 < 256 Byte) : 1 Character 로크기표현 Separate the Field with Delimiters 특수문자로 Field 끝을표시 특수문자가 Field 내용중에나타날경우? "Keyword = Value" Expression to Identify Fields Self-describing structure ( 어떤 field? Missing field?) 기억공간낭비가매우크다. 영남대학교데이터베이스연구실 Algorithm: Chapter 4 (Page 8)

Ames John 123 Maple Stillwater OK74075377-1808 Mason Alan 90 Eastgate Ada OK74820 (a) Field lengths fixed. Place blanks in the spaces where the phone number would go. Ames John 123 Maple Stillwater OK 74075 377-1808 Mason Alan 90 Eastgate Ada OK 74820 (b) Delimiters are used to indicate the end of a field. Place the delimiter for the empty field immediately after the delimiter for the previous fields. Ames... Stillwater t OK 74075 377-1808 #Mason... 90 Eastgate t Ada OK 74820 #... (c) Place the field for business phone at the end of the record. If the end-of-record mark is encountered, assume that the field is missing. SURNAME=Ames FIRSTNAME=John STREET=123 Maple... ZIP=74075 PHONE=377-1808 #... (d) Use a keyword to identify each field. If the keyword is missing, the corresponding field is assumed to be missing. FIGURE 4.3 Four methods for organizing fields within records to account for possible missing fields. In the examples, the second record is missing the phone number.

1.3 Reading a Stream of Fields Program: readstrm.c Field 를 grouping 하는개념필요 Record set of fields 영남대학교데이터베이스연구실 Algorithm: Chapter 4 (Page 10)

readstrm.c : reads a stream of delimited fields #include "fileio.h" main() { int fd, n, fld_count; char s[30], filename[15]; printf("enter name of file to read: "); gets(filename); if ((fd = open(filename, O_RDONLY)) < 0) { printf("file opening error --- program stopped n"); exit(1); /* main program loop -- calls readfield() for as long as the function succeeds */ fld_count = 0; while ((n = readfield(fd, s)) > 0) printf(" tfield # %3d: %s n", ++fld_count, s); close(fd); 영남대학교데이터베이스연구실 Algorithm: Chapter 4 (Page 11)

int readfield(int fd, char s[]) { int i; char c; i= 0; while ( read(fd, &c, 1) > 0 && c!= DELIM_CHR) s[i++] = c; s[i] = ' 0'; /* append null to end string */ return (i); 영남대학교데이터베이스연구실 Algorithm: Chapter 4 (Page 12)

1.4 Record Structures Record 의정의 A set of fields that belong together when the file is viewed in terms of higher level of organization 영남대학교데이터베이스연구실 Algorithm: Chapter 4 (Page 13)

File 을 record 로구성하는방법 고정길이 record ( Figure 4.5 (a) (b) ) 각 record 는동일한크기 : 가장많이사용 고정길이 record & 가변길이 field 가능 고정된 field 수를갖는 record (Figure45(c)) 4.5 (c) ) counting fields modulo filed number 각 record 앞에 record 길이를표현 ( Figure 4.6 (a) ) Use Index ( Figure 4.6 (c) ) Data file 및 Index file 로구분 Self-describing structure 로표현가능 Delimiter 로 record 구분 ( Figure 4.6 (c) ) delimiter : 공백이나특수문자 영남대학교데이터베이스연구실 Algorithm: Chapter 4 (Page 14)

Ames John 123 Maple Stillwater OK74075 Mason Alan 90 Eastgate Ada OK74820 (a) Fixed-length fields Ames John 123 Maple Stillwater OK 74075 Unused space Mason Alan 90 Eastgate Ada OK 74820 Unused space (b) Fixed-length records with variable-length fields Ames John 123 Maple Stillwater OK 74075 Mason Alan 90 Eastgate Ada OK... (c) Fixed number of fields per record FIGURE 4.5 Three ways of marking the lengths of records constant and predictable. (a) Counting bytes : fixed-length records with fixed-length fields. (b) Counting bytes : fixed-length records with variable-length fields. (c) Counting fields : six fields per record.

40Ames John 123 Maple Stillwater OK 74075 36Mason Alan 90 Eastgate... (a) Length indicator Data file : Ames John 123 Maple Stillwater OK 74075 Mason Alan... Index file : 00 40... (b) Index file Ames John 123 Maple Stillwater t OK 74075 #Mason Al Alan 90E Eastgate t Ad Ada OK... (c) Delimiter FIGURE 4.6 Record structures for variable-length records. (a) Beginning each record with a length indicator. (b) Using an index file to keep track of record addresses. (c) Placing the delimiter i # at the end of each record.

1.5 A Record Structure using Length Indicator Writing Variable-length Records to File Record 앞에길이를어떻게저장할것인가? Buffering 을이용하여길이계산 길이표현방법 : binary or ASCII writrec.c Representing the Record Length Binary Space efficient ( 32,767 vs. 99 ) fixed length ASCII: portable & printable Reading Variable-length Records from File readrec.c 영남대학교데이터베이스연구실 Algorithm: Chapter 4 (Page 17)

writrec.c: creates name and address file using fixed length (2-byte) record length field ahead of each record #include "fileio.h" #define fld_to_recbf(rb, fld) strcat(rb, fld); strcat(rb, DELIM_STR) char recbf[max_rec_size + 1]; char *prompt[] p = { "Enter Last Name -- or <CR> to exit: ", " First name: ", " Address: ", " City: ", " State: ", " Zip: ", "" /* null string to terminate the prompt loop */ ; main () { char response[50], filename[15]; int fd, i; short rec_lgth; 영남대학교데이터베이스연구실 Algorithm: Chapter 4 (Page 18)

printf("enter the name of the file you wish to create: "); gets(filename); if ((fd = open(filename, O_WRONLY O_CREATE O_EXCL)) < 0) { printf("file opening error --- program stopped n"); exit(1); printf(" n n%s", prompt[0]); gets(response); t( while (strlen(response) > 0) { recbf[0] = ' 0'; fld_to_recbf(recbf, response); for (i=1; *prompt[i]!= ' 0' ; i++) { printf("%s" %s, prompt[i]); gets(response); fld_to_recbf(recbuff, response); 영남대학교데이터베이스연구실 Algorithm: Chapter 4 (Page 19)

/* write out the record length and buffer contents */ rec_ lgth = strlen(recbf); write(fd, &rec_lgth, sizeof(rec_lgth)); /* record의길이저장 */ write(fd, recbf, rec_lgth); /* record의내용저장 */ /* prepare for next entry */ printf(" n n%s", prompt[0]); gets(response); /* close the file before leaving */ close(fd); /* question: How does the termination condition work in the loop: for (i=1; *prompt[i]!= ' 0' ; i++) What does the "i" refer to? Why do we need the "*"? */ 영남대학교데이터베이스연구실 Algorithm: Chapter 4 (Page 20)

readrec.c ec.c #include "fileio.h" main() { int fd, rec_count, fld_count, scan_pos; short rec_lgth; char filename[15], e[ recbuff[max _ REC_S SIZE + 1]; char field[max_rec_size + 1]; printf("enter a file name to read: "); gets(filename); if ((fd = open(filename, O_RDONLY)) < 0) { printf("file opening error --- program stopped n"); exit(1); 영남대학교데이터베이스연구실 Algorithm: Chapter 4 (Page 21)

rec_count = scan_pos = 0; while ((rec _ lgth = get _ rec(fd, recbuff)) > 0) { printf ("Record %d n", ++rec_count); fld_count = 0; while ((scan_pos = get_fld(field, recbuff, scan_pos, rec_lgth)) > 0) printf (" tfield %d: %s n", ++fld_count, field); close(fd); /* Q: Why can I assign 0 to scan_pos just once, outside of the while loop for records? */ get_rec(int fd, char recbuff[]) { short rec_lgth; if (read(fd, &rec_lgth, sizeof(short)) == 0) /* get record length */ return(0); /* return 0 if EOF */ rec_lgth = read(fd, recbuff, rec_lgth); /* read record */ return(rec_lgth); th) 영남대학교데이터베이스연구실 Algorithm: Chapter 4 (Page 22)

get_fld(char field[], char recbuff[], short scan_pos, short rec_lgth) { short fpos = 0; /* position in "field" array */ if (scan_pos == rec_lgth) /* if no more fields to read, */ return(0); /* return scan_pos of 0. */ /* scanning loop */ while ( scan_pos < rec_lgth && (field[fpos++] = recbuff[scan_pos++])!= DELIM_CHR) ; if (field[fpos - 1] == DELIM_ CHR) /* if last character is a field */ field[--fpos] = ' 0'; /* delimiter, replace with null */ else field[fpos] = ' 0'; /* otherwise, just ensure that the field is null-terminated */ return(scan_pos); /* return position of start of next field */ 영남대학교데이터베이스연구실 Algorithm: Chapter 4 (Page 23)