Skip to content

Commit

Permalink
Additional Lab 1 Mismatched Files
Browse files Browse the repository at this point in the history
  • Loading branch information
Valerie Kwek authored and Valerie Kwek committed Oct 13, 2024
1 parent b35bb77 commit 5359545
Showing 1 changed file with 2 additions and 7 deletions.
9 changes: 2 additions & 7 deletions godb/buffer_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ const (
type BufferPool struct {
// TODO: some code goes here
pages map[any]Page
keyOrder []any
numPages int
currPage int
}
Expand All @@ -29,7 +28,6 @@ type BufferPool struct {
func NewBufferPool(numPages int) (*BufferPool, error) {
return &BufferPool{
pages: make(map[any]Page),
keyOrder: []any{},
numPages: numPages,
currPage: 0,
}, nil
Expand All @@ -46,7 +44,6 @@ func (bp *BufferPool) FlushAllPages() {
page.setDirty(0, false)
}
bp.pages = make(map[any]Page)
bp.keyOrder = []any{}
bp.currPage = 0
}

Expand Down Expand Up @@ -108,9 +105,8 @@ func (bp *BufferPool) GetPage(file DBFile, pageNo int, tid TransactionID, perm R
return nil, fmt.Errorf("could not read page")
}
if bp.currPage == bp.numPages {
for i, pageKey := range bp.keyOrder {
if !bp.pages[pageKey].isDirty() {
bp.keyOrder = append(bp.keyOrder[:i], bp.keyOrder[i+1:]...)
for _, page := range bp.pages {
if !page.isDirty() {
bp.currPage--
break
}
Expand All @@ -120,7 +116,6 @@ func (bp *BufferPool) GetPage(file DBFile, pageNo int, tid TransactionID, perm R
}
}
bp.pages[pageKey] = page
bp.keyOrder = append(bp.keyOrder, file.(*HeapFile).pageKey(pageNo))
bp.currPage++
return page, nil
}

0 comments on commit 5359545

Please sign in to comment.