1 / 17

B+ Tree  프로그램활용 및 소스 코드 분석 ,  변경

B+ Tree  프로그램활용 및 소스 코드 분석 ,  변경. Database Laboratory. 차례. 1. 검 색 2. 삽 입. A-100. A-101. 검색. procedure find ( value V) set C = root node while C is not a leaf node begin Let K i = smallest search-key value, if any, greater than V if there is no such value then begin

xantha-buck
Download Presentation

B+ Tree  프로그램활용 및 소스 코드 분석 ,  변경

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. B+ Tree 프로그램활용 및소스 코드 분석, 변경 Database Laboratory

  2. 차례 1. 검 색 2. 삽 입

  3. A-100 A-101 검색 procedure find (value V) set C = root node while C is not a leaf node begin Let Ki = smallest search-key value, if any, greater than V if there is no such value then begin Let m = the number of pointers in the node set C = node pointed to by Pm end else set C = the node pointed to by Pi end if there is a key value Ki in C such that Ki = V then pointer Pi directs us to the desired record or bucket else no record with key value k exists end procedure

  4. B+tree의 삽입 알고리즘 • B+ 트리의 삽입 알고리즘 • (1)새로운 키를 삽입 할 리프(leaf)노드를 찾는다 • (2)찾은 노드에 키를 삽입한다. • (3)새로 키를 삽입한 노드가 오버플로우 였는가 살펴보고, 오버플로우가 발생했으면 분열 시킨다. • (4)변경된 내용을 디스크에 기록시킨다.

  5. 삽입에 사용되는 중요 함수 • bt_inspg() • 키와 파일포인터 삽입 • bt_newpage(), bt_rpage() • 새로운 노드의 생성을 위한 메모리 할당함수 • bt_splpg() • 분할될 노드의 정보를 저장 • bt_pagesize() • 노드의 크기를 계산 • bt_clearerr() • 변경된 노드의 정보를 디스크에 반영하는 함수

  6. 소스코드 설명 부분 • bt_insert() 를 구성하는 파라미터 • 삽입 시에 에러 처리 부분 • 삽입 공간이 충분한 경우의 처리방법 • 삽입 공간이 충분하지 않는 경우의 처리방법 • 노드의 분할 • 분할되는 노드가 루트노드 일 경우 처리방법 • 변경된 노드의 상태를 디스크에 기록

  7. bt_insert(b, key, len, rrn, dupflg) • bt_insert( b ,key, len, rrn, dupflg){ BT_INDEX *b; bt_chrpkey; intlen; off_trrn; intdupflg; …

  8. bt_insert(…) 에러 처리 if(len > BT_MAXK(b)) { bt_errno(b) = BT_KTOOBIG; return(BT_ERR); } if(len <= 0) { bt_errno(b) = BT_ZEROKEY; return(BT_ERR); } if(bt_seekdown(b, key, len) == BT_ERR) return(BT_ERR);

  9. 삽 입 /* this loop should be comfortably repeated until we perform a */ /* simple insert without a split, which will clean everything up */ /* and return correctly. breaking out indicates a fatal problem */ while(1) { /* here is where we figure out if we need to split, or */ /* if we can just perform a simple insert instead */ 1. if((int)KEYUSE(op->p) + len + sizeof(int) + sizeof(off_t) < bt_pagesiz(b)) { structbt_cache *tp; if((tp = bt_rpage(b,BT_NULL)) == NULL) gotobombout; 2. bt_inspg(kp, len, &ival, keyat, op->p, tp->p); /* swap the page numbers, invalidate the old, */ /* mark the new as dirty to force a write */ tp->num = op->num; tp->flags = BT_CHE_DIRTY; op->num = BT_NULL;

  10. 삽 입 [Split] else { struct bt_cache *lp; /* new page to hold low keys */ struct bt_cache *hp; /* new page to hold hi keys */ off_t savlft; /* saved left sib page # */ off_t npag; /* new page # */ /* allocate new page for low keys */ if((npag = bt_newpage(b)) == BT_NULL) goto bombout; /* allocate new scratch page for low keys */ if((lp = bt_rpage(b,BT_NULL)) == NULL) goto bombout; /* allocate new scratch page for low keys */ if((hp = bt_rpage(b,BT_NULL)) == NULL) goto bombout;

  11. Cont’ bt_splpg(kp1,len,&ival,keyat,bt_pagesiz(b)/2,op->p, lp->p, hp->p, kp2,&len); /* patch sibs */ LSIB(hp->p) = npag; RSIB(hp->p) = RSIB(op->p); LSIB(lp->p) = LSIB(op->p); savlft = LSIB(op->p); RSIB(lp->p) = ipag; /* mark newly split pages as real */ lp->num = npag; lp->flags = BT_CHE_DIRTY; hp->num = ipag; hp->flags = BT_CHE_DIRTY; op->num = BT_NULL; if(bt_wpage(b,op) == BT_ERR || bt_wpage(b,lp) == BT_ERR || bt_wpage(b,hp) == BT_ERR) goto bombout;

  12. 삽 입 /* if current page was root, make new root */ if(ipag == b->sblk.root) { off_t nr; /* get new page # */ 1. if((nr = bt_newpage(b)) == BT_NULL) goto bombout; /* two scratch pages */ 2. if((op = bt_rpage(b,BT_NULL)) == NULL) goto bombout; 3. if((lp = bt_rpage(b,BT_NULL)) == NULL) goto bombout;

  13. 삽 입 /* prime empty root page */ LSIB(op->p) = RSIB(op->p) = BT_NULL; KEYCNT(op->p) = 0; KEYLEN(op->p) = 0; HIPT(op->p) = ipag;

  14. 삽 입 /* we already know where to insert */ bt_inspg(kp2, len, &npag, 0, op->p,lp->p);

  15. 삽 입 /* finally, sync up root */ b->sblk.root = nr; b->sblk.levs++; b->dirt++; if(bt_wsuper(b) == BT_ERR) goto bombout; /* mark all as well with tree */ bt_clearerr(b); /* return - we are done */ return(BT_OK); } }

  16. 요약 • 이번 시간에는 B+Tree의 검색 알고리즘과 삽입 알고리즘을 공부하였습니다.

  17. Report • 여러분은 개별적으로 데이터를 구하여, 데이터의 키와 파일포인터를 추출하고, 그것을 이용하여 B+Tree를 구성한 다음, 삽입, 검색하는 프로그램을 작성하십시오. • 여러분이 사용한 데이터와 프로그램, 그리고 삽입, 검색하는 과정을 메뉴얼 형식으로 자세히 작성하고, 사용된 파일(데이터파일, 키와 파일포인터 추출파일, B+Tree 삽입, 검색 프로그램)에 대한 보고서를 제출 • Btree 프로그램에서 btlib/bt_insert() 함수가 넘겨받은 파라미터 5개와 bt_insert() 함수에서 사용된 함수에 대하여 조사하고 각 함수를 설명한 다음 레포트로 제출

More Related