overlay

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Dec 7, 2018 License: AGPL-3.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Interval

type Interval interface {
	// Range returns the minimum and maximum of the interval.
	// Minimum value is inclusive, maximum value exclusive.
	// In other notation: [min, max)
	Range() (int64, int64)

	// Merge merges the interval `i` to this interval.
	// The range borders should be fixed accordingly,
	// so that [min(i.min, self.min), max(i.max, self.max)] applies.
	Merge(i Interval)
}

Interval represents a 2er set of integers modelling a range.

type IntervalIndex

type IntervalIndex struct {

	// Max is the maximum interval offset given to Add()
	Max int64
	// contains filtered or unexported fields
}

IntervalIndex represents a continuous array of sorted intervals. When adding intervals to the index, it will merge them overlapping areas. Holes between the intervals are allowed.

func (*IntervalIndex) Add

func (ivl *IntervalIndex) Add(n Interval)

Add inserts a single interval to the index. If it overlaps with existing intervals, it's data will take priority over other intervals.

func (*IntervalIndex) Overlays

func (ivl *IntervalIndex) Overlays(start, end int64) []Interval

Overlays returns all intervals that intersect with [start, end)

type Layer

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

Layer is a io.ReadWriter that takes an underlying Reader and caches Writes on top of it. To the outside it delivers a zipped stream of the recent writes and the underlying stream.

func NewLayer

func NewLayer(r io.ReadSeeker) *Layer

NewLayer returns a new in memory layer. No IO is performed on creation.

func (*Layer) Close

func (l *Layer) Close() error

Close tries to close the underlying stream (if supported).

func (*Layer) Limit

func (l *Layer) Limit() int64

Limit returns the current truncation limit or a number < 0 if no truncation is done.

func (*Layer) MinSize

func (l *Layer) MinSize() int64

MinSize returns the minimum size that the layer will have. Underlying stream might be larger, so caller needs to check that.

func (*Layer) Read

func (l *Layer) Read(buf []byte) (int, error)

Read will read from the underlying stream and overlay with the relevant write chunks on it's way, possibly extending the underlying stream.

func (*Layer) Seek

func (l *Layer) Seek(offset int64, whence int) (int64, error)

Seek remembers the new position and delegates the seek down. Note: if the file was truncated before, a seek after the limit

will extend the truncation again and NOT return io.EOF.
This might be surprising, but is convenient for first
truncating to zero and then writing to the file.

func (*Layer) SetSize added in v0.2.0

func (l *Layer) SetSize(size int64)

SetSize sets the size of the absolute layer.

func (*Layer) Truncate

func (l *Layer) Truncate(size int64)

Truncate cuts off the stream at `size` bytes. After hitting the limit, io.EOF is returned. A value < 0 disables truncation.

func (*Layer) Write

func (l *Layer) Write(buf []byte) (int, error)

Write caches the buffer in memory or on disk until the file is closed. If the file was truncated before, the truncate limit is raised again if the write extended the limit.

type Modification

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

Modification represents a single write

func (*Modification) Merge

func (n *Modification) Merge(i Interval)

Merge adds the data of another interval where they intersect. The overlapping parts are taken from `n` always. Note: `i` shall not be used after calling Merge.

func (*Modification) Range

func (n *Modification) Range() (int64, int64)

Range returns the fitting integer interval

Jump to

Keyboard shortcuts

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