Documentation ¶
Overview ¶
Package paging contains functions and constants necessary for paging of records.
NOTE: Operations in this code are expected to either fail completely or succeed. Errors in the middle of an operation may leave the datastructures in an inconsistent state.
PageCursor ¶
PageCursor is a pointer into a PagedStorageFile and can be used to traverse a linked list of pages (see also PagedStorageFileHeader which stores the entry points).
PagedStorageFile ¶
PagedStorageFile is a wrapper object for a StorageFile which views the file records as a linked list of pages.
PagedStorageFileHeader ¶
PagedStorageFileHeader is a wrapper object for the header record of a StorageFile. The header record stores information about linked lists and root values.
Index ¶
- Constants
- Variables
- func CountPages(pager *PagedStorageFile, pagetype int16) (int, error)
- type PageCursor
- type PagedStorageFile
- func (psf *PagedStorageFile) AllocatePage(pagetype int16) (uint64, error)
- func (psf *PagedStorageFile) Close() error
- func (psf *PagedStorageFile) First(pagetype int16) uint64
- func (psf *PagedStorageFile) Flush() error
- func (psf *PagedStorageFile) FreePage(id uint64) error
- func (psf *PagedStorageFile) Header() *PagedStorageFileHeader
- func (psf *PagedStorageFile) Last(pagetype int16) uint64
- func (psf *PagedStorageFile) Next(id uint64) (uint64, error)
- func (psf *PagedStorageFile) Prev(id uint64) (uint64, error)
- func (psf *PagedStorageFile) Rollback() error
- func (psf *PagedStorageFile) StorageFile() *file.StorageFile
- type PagedStorageFileHeader
- func (psfh *PagedStorageFileHeader) CheckMagic()
- func (psfh *PagedStorageFileHeader) FirstListElement(list int16) uint64
- func (psfh *PagedStorageFileHeader) LastListElement(list int16) uint64
- func (psfh *PagedStorageFileHeader) Root(root int) uint64
- func (psfh *PagedStorageFileHeader) Roots() int
- func (psfh *PagedStorageFileHeader) SetFirstListElement(list int16, val uint64)
- func (psfh *PagedStorageFileHeader) SetLastListElement(list int16, val uint64)
- func (psfh *PagedStorageFileHeader) SetRoot(root int, val uint64)
Constants ¶
const OffsetLists = 2
OffsetLists is the offset for list entries in this header
const OffsetRoots = OffsetLists + (2 * TotalLists * file.SizeLong)
OffsetRoots is the number of lists which can be stored in this header
const PageHeader = 0x1980
PageHeader is the magic number to identify page headers
const TotalLists = 5
TotalLists is the number of lists which can be stored in this header
Variables ¶
var ( ErrFreePage = errors.New("Cannot allocate/free a free page") ErrHeader = errors.New("Cannot modify header record") )
Common paged storage file related errors
Functions ¶
func CountPages ¶
func CountPages(pager *PagedStorageFile, pagetype int16) (int, error)
CountPages counts the number of pages of a certain type of a given PagedStorageFile.
Types ¶
type PageCursor ¶
type PageCursor struct {
// contains filtered or unexported fields
}
PageCursor data structure
func NewPageCursor ¶
func NewPageCursor(psf *PagedStorageFile, ptype int16, current uint64) *PageCursor
NewPageCursor creates a new cursor object which can be used to traverse a set of pages.
func (*PageCursor) Current ¶
func (pc *PageCursor) Current() uint64
Current gets the page this cursor currently points at.
func (*PageCursor) Next ¶
func (pc *PageCursor) Next() (uint64, error)
Next moves the PageCursor to the next page and returns it.
func (*PageCursor) Prev ¶
func (pc *PageCursor) Prev() (uint64, error)
Prev moves the PageCursor to the previous page and returns it.
type PagedStorageFile ¶
type PagedStorageFile struct {
// contains filtered or unexported fields
}
PagedStorageFile data structure
func NewPagedStorageFile ¶
func NewPagedStorageFile(storagefile *file.StorageFile) (*PagedStorageFile, error)
NewPagedStorageFile wraps a given StorageFile and returns a PagedStorageFile.
func (*PagedStorageFile) AllocatePage ¶
func (psf *PagedStorageFile) AllocatePage(pagetype int16) (uint64, error)
AllocatePage allocates a new page of a specific type.
func (*PagedStorageFile) Close ¶
func (psf *PagedStorageFile) Close() error
Close commits all data and closes all physical files.
func (*PagedStorageFile) First ¶
func (psf *PagedStorageFile) First(pagetype int16) uint64
First returns the first page of a list of a given type.
func (*PagedStorageFile) Flush ¶
func (psf *PagedStorageFile) Flush() error
Flush writes all pending data to disk.
func (*PagedStorageFile) FreePage ¶
func (psf *PagedStorageFile) FreePage(id uint64) error
FreePage frees a given page and adds it to the free list.
func (*PagedStorageFile) Header ¶
func (psf *PagedStorageFile) Header() *PagedStorageFileHeader
Header returns the header object of this PagedStorageFile.
func (*PagedStorageFile) Last ¶
func (psf *PagedStorageFile) Last(pagetype int16) uint64
Last returns the first page of a list of a given type.
func (*PagedStorageFile) Next ¶
func (psf *PagedStorageFile) Next(id uint64) (uint64, error)
Next returns the next page of a given page in a list.
func (*PagedStorageFile) Prev ¶
func (psf *PagedStorageFile) Prev(id uint64) (uint64, error)
Prev returns the previous page of a given page in a list.
func (*PagedStorageFile) Rollback ¶
func (psf *PagedStorageFile) Rollback() error
Rollback discards all changes which were done after the last flush. The PageStorageFile object should be discarded if something goes wrong during a rollback operation.
func (*PagedStorageFile) StorageFile ¶
func (psf *PagedStorageFile) StorageFile() *file.StorageFile
StorageFile returns the wrapped StorageFile.
type PagedStorageFileHeader ¶
type PagedStorageFileHeader struct {
// contains filtered or unexported fields
}
PagedStorageFileHeader data structure
func NewPagedStorageFileHeader ¶
func NewPagedStorageFileHeader(record *file.Record, isnew bool) *PagedStorageFileHeader
NewPagedStorageFileHeader creates a new NewPagedStorageFileHeader.
func (*PagedStorageFileHeader) CheckMagic ¶
func (psfh *PagedStorageFileHeader) CheckMagic()
CheckMagic checks the header magic value of this header.
func (*PagedStorageFileHeader) FirstListElement ¶
func (psfh *PagedStorageFileHeader) FirstListElement(list int16) uint64
FirstListElement returns the first element of a list.
func (*PagedStorageFileHeader) LastListElement ¶
func (psfh *PagedStorageFileHeader) LastListElement(list int16) uint64
LastListElement returns the last element of a list.
func (*PagedStorageFileHeader) Root ¶
func (psfh *PagedStorageFileHeader) Root(root int) uint64
Root returns a root value.
func (*PagedStorageFileHeader) Roots ¶
func (psfh *PagedStorageFileHeader) Roots() int
Roots returns the number of possible root values which can be set.
func (*PagedStorageFileHeader) SetFirstListElement ¶
func (psfh *PagedStorageFileHeader) SetFirstListElement(list int16, val uint64)
SetFirstListElement sets the first element of a list.
func (*PagedStorageFileHeader) SetLastListElement ¶
func (psfh *PagedStorageFileHeader) SetLastListElement(list int16, val uint64)
SetLastListElement sets the last element of a list.
func (*PagedStorageFileHeader) SetRoot ¶
func (psfh *PagedStorageFileHeader) SetRoot(root int, val uint64)
SetRoot sets a root value.