tree

package
v1.12.1 Latest Latest
Warning

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

Go to latest
Published: Feb 28, 2025 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package tree implements a tree data structure for representing a directory structure.

It provides methods for adding paths, checking for the presence of a path, generating a string representation of the tree, getting all paths in the tree, and retrieving a random path.

It leverages the github.com/xlab/treeprint package to generate the string representation. The implementation is concurrent-safe through the use of a sync.RWMutex.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddDirectoryPaths

func AddDirectoryPaths(tree Tree, dirPath, trimPrefix string) error

AddDirectoryPaths is a helper function that adds all paths in a directory to the tree you can optionally pass in a prefix to trim from the paths.

Types

type Node

type Node struct {
	Name     string `json:"name"`
	Children []Node `json:"children,omitempty"`
}

Node is a node in the tree.

type Tree

type Tree interface {
	// Add adds a path to the tree
	Add(paths ...string)
	// HasPath checks if any of the paths in the tree contain the given path
	HasPath(path string) bool
	// ToString gets a string representation of the tree
	ToString() string
	// AllPaths gets all paths in the tree. This will include paths that might not have been explicitly added
	// e.g. if you Add() a/b/c/d.go, AllPaths() will return a/b/c/d.go, a/b/c a/b/ and a/
	AllPaths() []string
}

Tree is a tree data structure for representing a directory structure.

func NewTree

func NewTree() Tree

NewTree creates a new tree.

Jump to

Keyboard shortcuts

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