Search Apps Documentation Source Content File Folder Download Copy Actions Download State String Boolean Number Struct Map Slice Pointer Function Closure Reference Nil Package Type Interface Unknown

v0 source pure

Package blocks encodes a radio rotation, an ordered list of slots (an id and a duration), as strings the caller store...

Overview

Package blocks encodes a radio rotation, an ordered list of slots (an id and a duration), as strings the caller stores under its own keys: a header (slot count, total, one total per group), one group string per Size² slots (one sum per block) and one block string per Size slots. Appending is O(1), changing a slot rewrites one block, one group and the header, and finding the slot at a position in the loop scans the group totals, one group's sums and a single block: O(n/Size² + Size), flat up to about two million slots. Inside a block, ids and durations are packed as fixed-width base-64 digits (4 per id, 2 per duration): 6 bytes of deposit per slot.

Constants 3

const MaxID, MaxDur

1const (
2	MaxID  = 1<<24 - 1 // 16,777,215
3	MaxDur = 1<<12 - 1 // 4095 seconds
4)
source

MaxID and MaxDur are what the packed digits hold.

const MaxSlots

1const MaxSlots = 1<<24 - 1
source

MaxSlots is the longest rotation a header counts.

const Size

1const Size = 128
source

Size is the number of slots per block.

Functions 10

func Append

1func Append(h, grp, blk string, id int, dur int64) (string, string, string, int)
source

Append adds a slot at the end. grp and blk are those of slot Len(h) (Where), "" when it starts a new one. It returns the three strings and the new slot's index.

func FindBlock

1func FindBlock(grp string, g int, rest int64) (b int, r int64)
source

FindBlock returns the block of group g playing at rest, and the position inside it.

func FindGroup

1func FindGroup(h string, pos int64) (g int, rest int64, ok bool)
source

Find is done in three steps, loading the group then the block between them: FindGroup, FindBlock, FindSlot. FindGroup returns the group playing at pos (0 <= pos < Total) and the position inside it; ok is false when pos is out of range.

func FindSlot

1func FindSlot(blk string, b int, rest int64) (slot, id int, offset int64)
source

FindSlot returns the slot of block b playing at rest, its id and the offset into it. Slots of duration 0 are never returned.

func Len

1func Len(h string) int
source

Len is the number of slots of a rotation ("" is empty).

func PrefixBefore

1func PrefixBefore(h, grp, blk string, i int) int64
source

PrefixBefore returns the total duration of slots 0..i-1 (0 <= i <= Len).

func Set

1func Set(h, grp, blk string, i, id int, dur int64) (string, string, string)
source

Set replaces slot i's id and duration (0 takes it out of the loop).

func Slot

1func Slot(blk string, i int) (int, int64)
source

Slot returns the id and duration of slot i, from its block.

func Total

1func Total(h string) int64
source

Total is the sum of all durations.

func Where

1func Where(i int) (g, b int)
source

Where returns the group and block (counted from the start of the rotation) that hold slot i.

Imports 1

Source Files 2