ftree

package
v0.0.0-...-e662cb7 Latest Latest
Warning

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

Go to latest
Published: Oct 21, 2021 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	// The random source fo the generation
	Src rand.Source

	// Number of files to generate
	NumFiles uint64

	// The average depth of the folders.
	AvgDepth uint32

	// Chance of new folders, must be between 0 and 1
	NewRatio float64
}

A Config describes the parameters used to generate a filetree with the Generate call.

type Node

type Node struct {
	Children map[string]Node
}

Node represents a node in a file. If a node does not have any children, it is considered to be a file otherwise it's a directory. This matches the way object stores see the world as their folders are simply constructs.

func FromFiles

func FromFiles(files []string) Node

FromFiles returns a tree built on the files in the files tree.

func Generate

func Generate(c Config) Node

Generate a tree relationship.

func (Node) AvgDepth

func (n Node) AvgDepth() float64

AvgDepth returns the average depth of the files, as measured from this node. It is important to notice that files in the top level directory have a depth of 1.

func (Node) Files

func (n Node) Files() []string

Files returns the list of full files in the tree The files are returned in sortede order.

func (Node) IsFile

func (n Node) IsFile() bool

IsFile returns if the node is a file.

func (Node) MaxDepth

func (n Node) MaxDepth() uint64

MaxDepth returns the MaxDepth for node.

func (Node) Print

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

Print prints the tree for debugging. It's in lexograpihc order.

Jump to

Keyboard shortcuts

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