Documentation
¶
Overview ¶
Package page provides page management for XxSql storage engine.
Index ¶
- Constants
- type Header
- type Page
- func (p *Page) AppendSlot(offset, length uint16) int
- func (p *Page) ClearFlag(flag uint8)
- func (p *Page) DataRange() (start, end uint16)
- func (p *Page) DeleteRow(index int) error
- func (p *Page) FreeSpace() uint16
- func (p *Page) GetChecksum() uint16
- func (p *Page) GetFlags() uint8
- func (p *Page) GetFreeOffset() uint16
- func (p *Page) GetLSN() uint64
- func (p *Page) GetPageID() PageID
- func (p *Page) GetRow(index int) ([]byte, error)
- func (p *Page) GetSlot(index int) SlotEntry
- func (p *Page) GetSlotCount() uint16
- func (p *Page) GetType() PageType
- func (p *Page) HasFlag(flag uint8) bool
- func (p *Page) InsertRow(data []byte) (int, error)
- func (p *Page) IsLeaf() bool
- func (p *Page) IsRoot() bool
- func (p *Page) RowCount() int
- func (p *Page) SetChecksum(checksum uint16)
- func (p *Page) SetFlag(flag uint8)
- func (p *Page) SetFlags(flags uint8)
- func (p *Page) SetFreeOffset(offset uint16)
- func (p *Page) SetLSN(lsn uint64)
- func (p *Page) SetLeaf(leaf bool)
- func (p *Page) SetPageID(id PageID)
- func (p *Page) SetRoot(root bool)
- func (p *Page) SetSlot(index int, entry SlotEntry)
- func (p *Page) SetSlotCount(count uint16)
- func (p *Page) SetType(typ PageType)
- func (p *Page) ToBytes() []byte
- func (p *Page) UpdateRow(index int, data []byte) error
- type PageID
- type PageType
- type SlotEntry
Constants ¶
const ( // PageSize is the size of a page in bytes. PageSize = 4096 // PageHeaderSize is the size of the page header in bytes. PageHeaderSize = 24 // MaxDataSize is the maximum data size in a page. MaxDataSize = PageSize - PageHeaderSize )
const ( FlagLeaf uint8 = 0x01 // Leaf page (vs internal) FlagRoot uint8 = 0x02 // Root page of B+ tree FlagOverflow uint8 = 0x04 // Has overflow pages FlagDeleted uint8 = 0x08 // Page is deleted )
Page flags.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Header ¶
type Header struct {
PageID PageID
LSN uint64
Type PageType
Flags uint8
FreeOffset uint16
SlotCount uint16
Checksum uint16
}
Header represents the page header (24 bytes). Layout:
- Bytes 0-7: Page ID (8 bytes)
- Bytes 8-15: LSN (Log Sequence Number) (8 bytes)
- Bytes 16: Page Type (1 byte)
- Bytes 17: Flags (1 byte)
- Bytes 18-19: Free space offset (2 bytes)
- Bytes 20-21: Slot count (2 bytes)
- Bytes 22-23: Checksum (2 bytes)
type Page ¶
Page represents a database page.
func NewPageFromBytes ¶
NewPageFromBytes creates a page from bytes.
func (*Page) AppendSlot ¶
AppendSlot appends a new slot entry.
func (*Page) DeleteRow ¶
DeleteRow marks a row as deleted by setting its length to 0. This is a simple deletion - no compaction is performed.
func (*Page) GetFreeOffset ¶
GetFreeOffset returns the free space offset.
func (*Page) GetSlotCount ¶
GetSlotCount returns the slot count.
func (*Page) InsertRow ¶
InsertRow inserts a row at the end of the page. Returns the slot index or an error if there's not enough space.
func (*Page) SetChecksum ¶
SetChecksum sets the checksum.
func (*Page) SetFreeOffset ¶
SetFreeOffset sets the free space offset.
func (*Page) SetSlotCount ¶
SetSlotCount sets the slot count.
type PageID ¶
type PageID uint64
PageID represents a unique page identifier.
const InvalidPageID PageID = 0
InvalidPageID represents an invalid page ID.