Documentation ¶
Index ¶
- func LinkNodes(origin, dest *Node) error
- func SortNodesByID(nodes []*Node)
- func SortNodesByName(nodes []*Node)
- func UnlinkNodes(origin, dest *Node) error
- func ValidateDateNodeName(name string) error
- func ValidateNodeAlias(alias string) error
- func ValidateNodeName(name string) error
- type Link
- type Node
- func (n *Node) All() []*Node
- func (n *Node) Ancestors() []*Node
- func (n *Node) Children() []*Node
- func (n *Node) Copy() *Node
- func (n *Node) DeepCopy() *Node
- func (n *Node) DepthFirstSearch(f func(*Node, SearchState, func()))
- func (n *Node) DepthFirstSearchUndirected(f func(*Node, SearchState, func()))
- func (n *Node) Descendants() []*Node
- func (n *Node) Get(id int64) *Node
- func (n *Node) GetByAlias(alias string) *Node
- func (n *Node) GetByName(name string) *Node
- func (n *Node) HasChild(node *Node) bool
- func (n *Node) HasChildren() bool
- func (n *Node) HasParent(node *Node) bool
- func (n *Node) HasParents() bool
- func (n *Node) IsCompleted() bool
- func (n *Node) IsCompletedOnDate(date string, offset int) bool
- func (n *Node) IsDateNode() bool
- func (n *Node) IsInProgress() bool
- func (n *Node) IsInactive() bool
- func (n *Node) IsLeaf() bool
- func (n *Node) IsRoot() bool
- func (n *Node) Leaves() []*Node
- func (n *Node) LeavesAll() []*Node
- func (n *Node) New(name string) *Node
- func (n *Node) Parents() []*Node
- func (n *Node) Roots() []*Node
- func (n *Node) RootsAll() []*Node
- func (n *Node) Status() TaskStatus
- func (n *Node) String() string
- func (n *Node) StringNeighbors() string
- func (n *Node) StringTree() string
- func (n *Node) TimeCompleted() time.Time
- func (n *Node) TraverseAncestors(f func(*Node, func()))
- func (n *Node) TraverseDescendants(f func(*Node, func()))
- func (n *Node) Tree() *Node
- type SearchState
- type TaskStatus
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func LinkNodes ¶
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 ¶
LinkNodes removes an existing directed link between origin and dest. It returns an error if the link doesn't exist.
func ValidateDateNodeName ¶
func ValidateNodeAlias ¶
func ValidateNodeName ¶
Types ¶
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
ImportTrees reads a sequence of tab-indented lines and builds trees out of them. It returns pointers to the roots.
func (*Node) All ¶
All returns a flat list of all nodes in the multitree. The nodes are sorted by ID in ascending order.
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 ¶
Descendants returns a flat list of the node's descendants.
func (*Node) GetByAlias ¶
Get returns the first node matching the alias, or nil, if no match is found.
func (*Node) GetByName ¶
Get returns the first node matching the name, or nil, if no match is found.
func (*Node) HasChildren ¶ added in v0.2.0
func (*Node) HasParents ¶ added in v0.2.0
func (*Node) IsCompleted ¶
func (*Node) IsCompletedOnDate ¶ added in v0.3.0
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 (*Node) IsInProgress ¶
func (*Node) IsInactive ¶
func (*Node) IsLeaf ¶
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) LeavesAll ¶
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 ¶
New creates a new node with the ID set to 1 more than the highest ID in the multitree.
func (*Node) Roots ¶
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 ¶
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 ¶
String returns a basic string representation of the node. Color is automatically disabled when in non-tty output mode.
func (*Node) StringNeighbors ¶
StringNeighbors returns a string representation of the node's neighborhood, e.g.:
(45) ──┐ (150) ──┴── (123) ──┬── (124) └── (125)
func (*Node) StringTree ¶
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
TimeCompleted returns the task completion time as local time.Time.
func (*Node) TraverseAncestors ¶
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 ¶
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.
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