tree

package
v0.0.1-beta6 Latest Latest
Warning

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

Go to latest
Published: Feb 14, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package tree is used to represent a file hierarchy tree.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DuplicateMap

type DuplicateMap map[file.PathHash][]*SignaturedNode

Map of signature to subtrees that have the same signature (i.e. duplicates).

func (DuplicateMap) Print

func (m DuplicateMap) Print(w io.Writer, printTree bool)

Display the map of duplicates.

type Node

type Node struct {
	Name        string
	Info        path.Info
	FirstChild  *Node
	NextSibling *Node
}

Node in the tree describing a path entry.

func (*Node) Print

func (n *Node) Print(w io.Writer)

Recursively display this node and children.

func (*Node) PrintWithLimit

func (n *Node) PrintWithLimit(w io.Writer, limit int)

type SignaturedNode

type SignaturedNode struct {
	Node      *Node
	Signature file.PathHash

	FirstChild  *SignaturedNode
	NextSibling *SignaturedNode
}

Node in the tree with a signature.

type SignaturedTree

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

SignaturedTree calculates a signature for each parent node. The signature is calculated based on the children node names. One use case is to use it to determine which sub-trees are the same (i.e. duplicates).

func NewSignaturedTree

func NewSignaturedTree(t Tree) SignaturedTree

Create a new signatured tree from an existing file tree.

func (*SignaturedTree) FindDuplicateSubtrees

func (t *SignaturedTree) FindDuplicateSubtrees() DuplicateMap

Find all the subtrees that share the same signatures.

func (*SignaturedTree) Print

func (t *SignaturedTree) Print(w io.Writer)

Display the entire tree.

func (*SignaturedTree) PrintDuplicateSubtrees

func (t *SignaturedTree) PrintDuplicateSubtrees(w io.Writer, printTree bool)

Find all the duplicate subtrees and display them.

func (*SignaturedTree) Root

func (t *SignaturedTree) Root() *SignaturedNode

Return the root node.

type Tree

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

Tree represents a file hierarchy.

func New

func New(rootPath string) Tree

Create a new Tree representing the file hierarchy at the specified root path. All paths are relative to this root path.

func (*Tree) Find

func (t *Tree) Find(path string) *Node

Find the node for the specified path.

func (*Tree) Insert

func (t *Tree) Insert(pi path.Info) *Node

Insert a new path info object into the tree and return the new node.

func (*Tree) Print

func (t *Tree) Print(w io.Writer)

Display the entire tree.

func (*Tree) PrintWithLimit

func (t *Tree) PrintWithLimit(w io.Writer, limit int)

Display the tree with a maximum specified depth.

func (*Tree) Root

func (t *Tree) Root() *Node

Return the root node.

func (*Tree) RootPath

func (t *Tree) RootPath() string

Return the path that represents the root of the file hierarchy.

Jump to

Keyboard shortcuts

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