util

package
v1.4.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 14, 2022 License: MPL-2.0 Imports: 2 Imported by: 0

Documentation

Overview

Package util contains utility functions for slot headers.

Packing and unpacking of slot sizes

The package contains functions to pack/unpack sizes for physical slots and logical buckets. The size info is a 4 byte value which allocates 2 bytes for current size and 2 bytes for available size.

CCCC CCCC CCCC CCCC AAAA AAAA AAAA AAAA

The allocated size value is a packed integer using a 2 bit multiplier in the beginning - using these packed values a slot can grow up to 138681822 bytes (138 MB). The space allocation becomes more and more wasteful with increasing slot size. The current size is stored as a difference to the allocated size. The maximum difference between alloacted and current space is 65534 bytes.

Packing and unpacking locations

The package contains utility functions to pack and unpack location information in an uint64. A location is a pointer which identifies a specific record and within the record a specific offset.

The 8 byte uint64 value is split into a 6 byte (48 bits) record address and 2 byte offset.

RRRR RRRR RRRR RRRR RRRR RRRR RRRR RRRR RRRR RRRR RRRR RRRR OOOO OOOO OOOO OOOO

We can address at maximum (having a record size of 32767 bytes):

(2^48 / 2 - 1) * 32767 = 4.61154528 * 10^18 which is around 4 exabyte

Considering a default page size of 4096 bytes we can address:

(2^48 / 2 - 1) * 4096 = 5.76460752 * 10^17 which is around 512 petabyte

Index

Constants

View Source
const LocationSize = file.SizeLong

LocationSize is the size of a location in bytes

View Source
const MaxAvailableSizeDifference = UnsignedShortMax - 1

MaxAvailableSizeDifference represents the maximal size of the difference between available size and current size

View Source
const MaxOffsetValue = 0xFFFF

MaxOffsetValue is the maximum offset value for a location (32767).

View Source
const MaxRecordValue = 0xFFFFFF

MaxRecordValue is the maximum record value (2^48 / 2 - 1)

6 byte = 48 bits

View Source
const OffetAvailableSize = file.SizeUnsignedShort

OffetAvailableSize is the offset for the available size on a slotsize header.

View Source
const OffsetCurrentSize = 0

OffsetCurrentSize is the offset for the size on a slotsize header.

SizeInfoSize represents the size of the size info

View Source
const UnsignedShortMax = 0xFFFF

UnsignedShortMax is the maximum value of an unsigned short as used for slotsizes.

Variables

This section is empty.

Functions

func AvailableSize

func AvailableSize(record *file.Record, offset int) uint32

AvailableSize returns the available size of a slot.

func CurrentSize

func CurrentSize(record *file.Record, offset int) uint32

CurrentSize returns the current size of a slot.

func LocationOffset

func LocationOffset(location uint64) uint16

LocationOffset returns the offset from a location.

func LocationRecord

func LocationRecord(location uint64) uint64

LocationRecord retirms the record id from a location.

func NormalizeSlotSize

func NormalizeSlotSize(value uint32) uint32

NormalizeSlotSize normalizes a given slot size.

func PackLocation

func PackLocation(recordID uint64, offset uint16) uint64

PackLocation packs location information into an uint64.

func SetAvailableSize

func SetAvailableSize(record *file.Record, offset int, value uint32)

SetAvailableSize sets the available size of a slot.

func SetCurrentSize

func SetCurrentSize(record *file.Record, offset int, value uint32)

SetCurrentSize sets the current size of a slot.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL