From 9fcf49888be6e0c6190172a83c2a2514ec47c47b Mon Sep 17 00:00:00 2001 From: anthony4m Date: Fri, 3 Jan 2025 21:13:09 +0000 Subject: [PATCH] added page dirty flag --- kfile/Page.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/kfile/Page.go b/kfile/Page.go index 1b0e585..90306fd 100644 --- a/kfile/Page.go +++ b/kfile/Page.go @@ -14,6 +14,7 @@ type Page struct { pageId uint64 mu sync.RWMutex IsCompressed bool + isDirty bool } const ( @@ -52,6 +53,7 @@ func (p *Page) SetInt(offset int, val int) error { return fmt.Errorf("%s: setting int", ErrOutOfBounds) } binary.BigEndian.PutUint32(p.data[offset:], uint32(val)) + p.SetIsDirty(true) return nil } @@ -110,6 +112,7 @@ func (p *Page) SetBytes(offset int, val []byte) error { copy(p.data[offset:], val) p.data[offset+length] = 0 + p.SetIsDirty(true) } return nil @@ -154,6 +157,7 @@ func (p *Page) SetString(offset int, val string) error { strBytes := append([]byte(val)) p.SetBytes(offset, strBytes) + p.SetIsDirty(true) return nil } @@ -168,6 +172,7 @@ func (p *Page) SetBool(offset int, val bool) error { } else { p.data[offset] = 0 } + p.SetIsDirty(true) return nil } @@ -191,6 +196,7 @@ func (p *Page) SetDate(offset int, val time.Time) error { } convertedVal := uint64(val.Unix()) binary.BigEndian.PutUint64(p.data[offset:], convertedVal) + p.SetIsDirty(true) return nil } @@ -204,6 +210,14 @@ func (p *Page) GetDate(offset int) (time.Time, error) { return time.Unix(int64(timestamp), 0), nil } +func (p *Page) SetIsDirty(dirt bool) { + p.isDirty = dirt +} + +func (p *Page) GetIsDirty() bool { + return p.isDirty +} + func (p *Page) Contents() []byte { return p.data }