multitree

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Apr 11, 2021 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func LinkNodes

func LinkNodes(origin, dest *Node) error

LinkNodes creates a directed link from origin to dest, provided that the resulting graph will be a valid multitree. It returns an error otherwise. The given nodes are modified only if no error occurs.

func SortNodesByID added in v0.2.0

func SortNodesByID(nodes []*Node)

SortNodesByID sorts a slice of nodes in-place by Node.ID in ascending order.

func SortNodesByName added in v0.2.0

func SortNodesByName(nodes []*Node)

SortNodesByName uses natural sort to sort a slice of nodes in-place by Node.Name in ascending order.

func UnlinkNodes

func UnlinkNodes(origin, dest *Node) error

LinkNodes removes an existing directed link between origin and dest. It returns an error if the link doesn't exist.

func ValidateDateNodeName

func ValidateDateNodeName(name string) error

func ValidateNodeAlias

func ValidateNodeAlias(alias string) error

func ValidateNodeName

func ValidateNodeName(name string) error

Types

type Link struct {
	ID       int64
	OriginID int64
	DestID   int64
}
func NewLink(originID, destID int64) *Link

func (*Link) String

func (l *Link) String() string

type Node

type Node struct {
	ID   int64
	Name string

	// Alias is an optional secondary identifier of the node.
	Alias string

	// Created holds the Unix timestamp for the node's creation time.
	Created int64

	// Completed points to the Unix timestamp of when the node was marked as
	// completed, or nil, if the node hasn't been completed yet.
	Completed *int64
	// contains filtered or unexported fields
}

func ImportTrees added in v0.3.0

func ImportTrees(reader io.Reader) ([]*Node, error)

ImportTrees reads a sequence of tab-indented lines and builds trees out of them. It returns pointers to the roots.

func NewNode

func NewNode(name string) *Node

func (*Node) All

func (n *Node) All() []*Node

All returns a flat list of all nodes in the multitree. The nodes are sorted by ID in ascending order.

func (*Node) Ancestors

func (n *Node) Ancestors() []*Node

Ancestors returns a flat list of the node's ancestors.

func (*Node) Children

func (n *Node) Children() []*Node

func (*Node) Copy

func (n *Node) Copy() *Node

Copy returns a shallow, unlinked copy of the node.

func (*Node) DeepCopy

func (n *Node) DeepCopy() *Node

Copy returns a deep copy of the entire multitree that the node belongs to.

func (*Node) DepthFirstSearch

func (n *Node) DepthFirstSearch(f func(*Node, SearchState, func()))

DepthFirstSearch traverses the graph directionally starting from the node, calling f on each step forward. The function is passed a pointer to the current node, the node's search state, and a stop function that can be called to exit early.

func (*Node) DepthFirstSearchUndirected

func (n *Node) DepthFirstSearchUndirected(f func(*Node, SearchState, func()))

DepthFirstSearchUndirected traverses the entire graph, ignoring the direction, advancing through parents and children alike. It starts from n and calls f on each step forward. The function is passed a pointer to the current node, the node's search state, and a stop function that can be called to exit early.

func (*Node) Descendants

func (n *Node) Descendants() []*Node

Descendants returns a flat list of the node's descendants.

func (*Node) Get

func (n *Node) Get(id int64) *Node

Get returns the first node matching the ID, or nil, if no match is found.

func (*Node) GetByAlias

func (n *Node) GetByAlias(alias string) *Node

Get returns the first node matching the alias, or nil, if no match is found.

func (*Node) GetByName

func (n *Node) GetByName(name string) *Node

Get returns the first node matching the name, or nil, if no match is found.

func (*Node) HasChild

func (n *Node) HasChild(node *Node) bool

func (*Node) HasChildren added in v0.2.0

func (n *Node) HasChildren() bool

func (*Node) HasParent

func (n *Node) HasParent(node *Node) bool

func (*Node) HasParents added in v0.2.0

func (n *Node) HasParents() bool

func (*Node) IsCompleted

func (n *Node) IsCompleted() bool

func (*Node) IsCompletedOnDate added in v0.3.0

func (n *Node) IsCompletedOnDate(date string, offset int) bool

IsCompletedOnDate returns true if n was completed on date given as a string in the format "YYYY-MM-DD". The start of day is determined by offset, e.g. if offset is 4, the day starts at 4 A.M.

func (*Node) IsDateNode

func (n *Node) IsDateNode() bool

func (*Node) IsInProgress

func (n *Node) IsInProgress() bool

func (*Node) IsInactive

func (n *Node) IsInactive() bool

func (*Node) IsLeaf

func (n *Node) IsLeaf() bool

Roots returns the local roots found by following the node's descendants all the way down. The nodes are sorted by ID in ascending order.

func (*Node) IsRoot

func (n *Node) IsRoot() bool

func (*Node) Leaves

func (n *Node) Leaves() []*Node

func (*Node) LeavesAll

func (n *Node) LeavesAll() []*Node

LeavesAll returns a list of all leaves in the multitree, not just the leaves local to the node. The nodes are sorted by ID in ascending order.

func (*Node) New

func (n *Node) New(name string) *Node

New creates a new node with the ID set to 1 more than the highest ID in the multitree.

func (*Node) Parents

func (n *Node) Parents() []*Node

func (*Node) Roots

func (n *Node) Roots() []*Node

Roots returns the local roots found by following the node's ancestors all the way up. The nodes are sorted by ID in ascending order.

func (*Node) RootsAll

func (n *Node) RootsAll() []*Node

RootsAll returns a list of all roots in the multitree, not just the roots local to the node. The nodes are sorted by ID in ascending order.

func (*Node) Status

func (n *Node) Status() TaskStatus

func (*Node) String

func (n *Node) String() string

String returns a basic string representation of the node. Color is automatically disabled when in non-tty output mode.

func (*Node) StringNeighbors

func (n *Node) StringNeighbors() string

StringNeighbors returns a string representation of the node's neighborhood, e.g.:

 (45) ──┐
(150) ──┴── (123) ──┬── (124)
                    └── (125)

func (*Node) StringTree

func (n *Node) StringTree() string

StringTree returns a string representation of a tree rooted at n.

[~] Clean up the house (234)
 ├──[~] Clean up the bedroom (235)
 │   ├──[x] Clean up the desk (236)
 │   ├──[ ] Clean up the floor (237)
 │   └──[ ] Make the bed (238)
 ├──[ ] Clean up the kitchen (239)
 └──[ ] ...

func (*Node) TimeCompleted added in v0.3.0

func (n *Node) TimeCompleted() time.Time

TimeCompleted returns the task completion time as local time.Time.

func (*Node) TraverseAncestors

func (n *Node) TraverseAncestors(f func(*Node, func()))

TraverseAncestors calls f for each ancestor of the node. The function is passed a pointer to the current node and a stop function that can be called to exit early.

func (*Node) TraverseDescendants

func (n *Node) TraverseDescendants(f func(*Node, func()))

TraverseDescendants calls f for each descendant of the node. The function is passed a pointer to the current node and a stop function that can be called to exit early.

func (*Node) Tree

func (n *Node) Tree() *Node

Tree returns a tree rooted at n, induced by following the children all the way down to the leaves. The tree nodes are guaranteed to only have one parent.

type SearchState

type SearchState int
const (
	SearchStateWhite SearchState = iota // undiscovered
	SearchStateGray                     // discovered, but not finished
	SearchStateBlack                    // finished
)

type TaskStatus

type TaskStatus int
const (
	TaskStatusCompleted TaskStatus = iota
	TaskStatusInProgress
	TaskStatusInactive
)

func (TaskStatus) String

func (s TaskStatus) String() string

Jump to

Keyboard shortcuts

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