burndown

package
v1.0.0-rc.1 Latest Latest
Warning

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

Go to latest
Published: May 13, 2026 License: Apache-2.0, Apache-2.0 Imports: 3 Imported by: 0

Documentation

Overview

Package burndown provides file-level line interval tracking for burndown analysis.

Index

Constants

View Source
const TreeEnd = math.MaxUint32

TreeEnd denotes the value of the last leaf in the tree.

View Source
const TreeMaxBinPower = 14

TreeMaxBinPower is the binary power value which corresponds to the maximum tick which can be stored in the tree.

View Source
const TreeMergeMark = (1 << TreeMaxBinPower) - 1

TreeMergeMark is the special day which disables the status updates and is used in File.Merge().

Variables

This section is empty.

Functions

func NewTreapTimeline

func NewTreapTimeline(time, length int) *treapTimeline

NewTreapTimeline creates a Timeline backed by an implicit treap with initial [0, length) at time t.

Types

type DeltaReport

type DeltaReport struct {
	Current  int
	Previous int
	Delta    int
}

DeltaReport is a single (currentTime, previousTime, delta) for updater callbacks.

type File

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

File encapsulates a Timeline (line-interval storage) and cumulative length counters via updaters. Users should call NewFile(); Len() returns line count; Update() mutates via the timeline and updaters. Dump() writes the tree to a string and Validate() checks integrity.

func NewFile

func NewFile(time, length int, updaters ...Updater) *File

NewFile initializes a new instance of File struct using the default treap timeline.

The time parameter is the starting value of the first node. The length parameter is the starting length of the tree (the key of the second and the last node). The updaters parameter lists the attached interval length mappings.

func NewFileFromSegments

func NewFileFromSegments(segs []Segment, updaters ...Updater) *File

NewFileFromSegments creates a File from serialized segments without triggering updaters.

func (*File) CloneDeep

func (file *File) CloneDeep() *File

CloneDeep copies the file (deep copy of the timeline).

func (*File) CloneShallow

func (file *File) CloneShallow() *File

CloneShallow copies the file (shallow copy of the timeline).

func (*File) Delete

func (file *File) Delete()

Delete deallocates the file.

func (*File) Dump

func (file *File) Dump() string

Dump formats the underlying line interval tree into a string. Useful for error messages, panic()-s and debugging.

func (*File) ForEach

func (file *File) ForEach(callback func(line, value int))

ForEach visits each segment start in the timeline in order (line, value); value is -1 for TreeEnd.

func (*File) InvalidateIndex

func (file *File) InvalidateIndex()

InvalidateIndex marks the interval tree index as needing a rebuild. Called automatically by Update.

func (*File) Len

func (file *File) Len() int

Len returns the number of lines in the file.

func (*File) Merge

func (file *File) Merge(day int, others ...*File)

Merge combines several prepared File-s together.

func (*File) MergeAdjacentSameValue

func (file *File) MergeAdjacentSameValue()

MergeAdjacentSameValue coalesces consecutive segments with the same time (reduces node count).

func (*File) Nodes

func (file *File) Nodes() int

Nodes returns the number of segments/nodes in the file.

func (*File) QueryRange

func (file *File) QueryRange(startLine, endLine int) []OwnershipSegment

QueryRange returns all ownership segments that overlap the line range [startLine, endLine). The interval tree index is rebuilt lazily when the timeline has been modified. TreeEnd sentinel segments are excluded from results.

func (*File) ReconstructFromSegments

func (file *File) ReconstructFromSegments(segs []Segment)

ReconstructFromSegments rebuilds the file's timeline from a compact segment slice.

func (*File) ReplaceUpdaters

func (file *File) ReplaceUpdaters(updaters []Updater)

ReplaceUpdaters replaces the file's updaters with a new set.

func (*File) Segments

func (file *File) Segments() []Segment

Segments returns the file's timeline segments as a compact slice.

func (*File) ShrinkPool

func (file *File) ShrinkPool(keep int)

ShrinkPool trims the timeline's internal node pool to retain at most keep free nodes. Call between chunks to release excess pool memory to the GC.

func (*File) Update

func (file *File) Update(time, pos, insLength, delLength int)

Update modifies the timeline to reflect line changes and notifies updaters (deletions and insertions).

func (*File) Validate

func (file *File) Validate()

Validate checks the timeline integrity (starts at 0, ends with TreeEnd, no duplicates/merge marks).

type OwnershipSegment

type OwnershipSegment struct {
	StartLine int
	EndLine   int
	Owner     int
}

OwnershipSegment represents a line range with a single owner (time value).

type Segment

type Segment struct {
	Length int
	Value  TimeKey
}

Segment represents a contiguous run of lines with the same time value. Used for compact serialization of treap state (segments vs per-line expansion).

type TimeKey

type TimeKey = uint32

TimeKey is the time (tick) associated with a line interval. Same semantics as tree Value.

type Timeline

type Timeline interface {
	// Replace applies delete [pos, pos+delLines) then insert insLines at pos with time t.
	// Returns delta reports for the caller to apply to updaters (e.g. from deleted intervals).
	Replace(pos, delLines, insLines int, t TimeKey) []DeltaReport
	// Iterate calls fn(offset, length, timeKey) for each segment in order; return false to stop.
	Iterate(fn func(offset int, length int, t TimeKey) bool)
	// Len returns total line count (file length).
	Len() int
	// Nodes returns the number of segments/nodes (for diagnostics).
	Nodes() int
	// Validate panics if invariants are violated.
	Validate()
	// CloneShallow returns a shallow copy of the timeline.
	CloneShallow() *treapTimeline
	// CloneDeep returns a deep copy of the timeline.
	CloneDeep() *treapTimeline
	// Erase clears all nodes (for Delete).
	Erase()
	// Flatten returns line→time as a slice (for Merge).
	Flatten() []int
	// Reconstruct rebuilds from line→time slice (for Merge).
	Reconstruct(lines []int)
	// MergeAdjacentSameValue coalesces consecutive segments with the same time (reduces node count).
	// No-op for implementations that do not benefit (e.g. implicit treap).
	MergeAdjacentSameValue()
	// Segments returns the treap's segments as a compact slice (excludes TreeEnd sentinel).
	Segments() []Segment
	// ReconstructFromSegments rebuilds from a compact segment slice (inverse of Segments).
	ReconstructFromSegments(segs []Segment)
}

Timeline stores line intervals by (implicit or explicit) position and supports Replace without O(N) key shifting. Default implementation: implicit treap.

type Updater

type Updater = func(currentTime, previousTime, delta int)

Updater is the function which is called back on File.Update().

Jump to

Keyboard shortcuts

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