intervalstore

package
v0.6.1 Latest Latest
Warning

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

Go to latest
Published: May 22, 2021 License: BSD-3-Clause Imports: 5 Imported by: 1

Documentation

Overview

Package intervalstore provides a persistence layer for intervals relating to a peer. The store provides basic operation such as adding intervals to existing ones and persisting the results, as well as getting next interval for a peer.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Intervals

type Intervals struct {
	// contains filtered or unexported fields
}

Intervals store a list of intervals. Its purpose is to provide methods to add new intervals and retrieve missing intervals that need to be added. It may be used in synchronization of streaming data to persist retrieved data ranges between sessions.

func NewIntervals

func NewIntervals(start uint64) *Intervals

New creates a new instance of Intervals. Start argument limits the lower bound of intervals. No range below start bound will be added by Add method or returned by Next method. This limit may be used for tracking "live" synchronization, where the sync session starts from a specific value, and if "live" sync intervals need to be merged with historical ones, it can be safely done.

func (*Intervals) Add

func (i *Intervals) Add(start, end uint64)

Add adds a new range to intervals. Range start and end are values are both inclusive.

func (*Intervals) Last

func (i *Intervals) Last() (end uint64)

Last returns the value that is at the end of the last interval.

func (*Intervals) MarshalBinary

func (i *Intervals) MarshalBinary() (data []byte, err error)

MarshalBinary encodes Intervals parameters into a semicolon separated list. The first element in the list is base36-encoded start value. The following elements are two base36-encoded value ranges separated by comma.

func (*Intervals) Merge

func (i *Intervals) Merge(m *Intervals)

Merge adds all the intervals from the m Interval to current one.

func (*Intervals) Next

func (i *Intervals) Next(ceiling uint64) (start, end uint64, empty bool)

Next returns the first range interval that is not fulfilled. Returned start and end values are both inclusive, meaning that the whole range including start and end need to be added in order to fill the gap in intervals. Returned value for end is 0 if the next interval is after the whole range that is stored in Intervals. Zero end value represents no limit on the next interval length. Argument ceiling is the upper bound for the returned range. Returned empty boolean indicates if both start and end values have reached the ceiling value which means that the returned range is empty, not containing a single element.

func (*Intervals) String

func (i *Intervals) String() string

String returns a descriptive representation of range intervals in [] notation, as a list of two element vectors.

func (*Intervals) UnmarshalBinary

func (i *Intervals) UnmarshalBinary(data []byte) (err error)

UnmarshalBinary decodes data according to the Intervals.MarshalBinary format.

Jump to

Keyboard shortcuts

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