slotinfopage.go 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. /*
  2. * EliasDB
  3. *
  4. * Copyright 2016 Matthias Ladkau. All rights reserved.
  5. *
  6. * This Source Code Form is subject to the terms of the Mozilla Public
  7. * License, v. 2.0. If a copy of the MPL was not distributed with this
  8. * file, You can obtain one at http://mozilla.org/MPL/2.0/.
  9. */
  10. package pageview
  11. import (
  12. "devt.de/krotik/eliasdb/storage/file"
  13. "devt.de/krotik/eliasdb/storage/paging/view"
  14. "devt.de/krotik/eliasdb/storage/util"
  15. )
  16. /*
  17. SlotInfoPage data structure
  18. */
  19. type SlotInfoPage struct {
  20. *view.PageView
  21. }
  22. /*
  23. NewSlotInfoPage creates a new SlotInfoPage object which can manage slotinfos.
  24. */
  25. func NewSlotInfoPage(record *file.Record) *SlotInfoPage {
  26. pv := view.GetPageView(record)
  27. return &SlotInfoPage{pv}
  28. }
  29. /*
  30. SlotInfoRecord gets record id of a stored slotinfo.
  31. */
  32. func (lm *SlotInfoPage) SlotInfoRecord(offset uint16) uint64 {
  33. return util.LocationRecord(lm.Record.ReadUInt64(int(offset)))
  34. }
  35. /*
  36. SlotInfoOffset gets the record offset of a stored slotinfo.
  37. */
  38. func (lm *SlotInfoPage) SlotInfoOffset(offset uint16) uint16 {
  39. return util.LocationOffset(lm.Record.ReadUInt64(int(offset)))
  40. }
  41. /*
  42. SetSlotInfo stores a slotinfo on the pageview's record.
  43. */
  44. func (lm *SlotInfoPage) SetSlotInfo(slotinfoOffset uint16, recordID uint64, offset uint16) {
  45. lm.Record.WriteUInt64(int(slotinfoOffset), util.PackLocation(recordID, offset))
  46. }