tree

package
v0.0.0-...-cac0241 Latest Latest
Warning

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

Go to latest
Published: Dec 14, 2022 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ExtensionEntry

type ExtensionEntry struct {
	Name  string `json:"name"`
	Size  int64  `json:"size"`
	Count int    `json:"count"`
}

ExtensionEntry is a file tree entry for extensions

func (*ExtensionEntry) AddMulti

func (e *ExtensionEntry) AddMulti(size int64, count int)

AddMulti adds size and a count

func (ExtensionEntry) String

func (e ExtensionEntry) String() string

type FileEntry

type FileEntry struct {
	Name       string                     `json:"name"`
	IsDir      bool                       `json:"is_dir"`
	Size       int64                      `json:"size"`
	Count      int                        `json:"count"`
	Extensions map[string]*ExtensionEntry `json:"extensions"`
}

FileEntry is a file tree entry

func NewFileEntry

func NewFileEntry(name string, size int64, isDir bool) FileEntry

NewFileEntry creates a new FileEntry

func (*FileEntry) Add

func (e *FileEntry) Add(size int64)

Add adds size and a count of one

func (*FileEntry) AddExtensions

func (e *FileEntry) AddExtensions(ext map[string]*ExtensionEntry)

AddExtensions adds extensions

func (*FileEntry) AddMulti

func (e *FileEntry) AddMulti(size int64, count int)

AddMulti adds size and a count

func (FileEntry) String

func (e FileEntry) String() string

type FileTree

type FileTree = Tree[*FileEntry]

FileTree is a tree with TreeEntry data

func Deserialize

func Deserialize(bytes []byte) (*FileTree, error)

Deserialize a FileTree from a JSON byte slice

func NewDir

func NewDir(name string) *FileTree

NewDir creates a new FileTree with a directory entry

func NewFile

func NewFile(name string, size int64) *FileTree

NewFile creates a new FileTree with a file entry

type JSONPrinter

type JSONPrinter[T any] struct{}

JSONPrinter prints a tree in JSON format

func (JSONPrinter[T]) Print

func (p JSONPrinter[T]) Print(t *Tree[T]) string

type PlainPrinter

type PlainPrinter[T any] struct{}

PlainPrinter prints a tree in plain text format

func (PlainPrinter[T]) Print

func (p PlainPrinter[T]) Print(t *Tree[T]) string

type Printer

type Printer[T any] interface {
	Print(t *Tree[T]) string
}

Printer interface

type Tree

type Tree[T any] struct {
	Children []*Tree[T] `json:"children"`
	Value    T          `json:"value"`
}

Tree is a tree data structure

func New

func New[T any](value T) *Tree[T]

New creates a new tree

func (*Tree[T]) Add

func (t *Tree[T]) Add(child T)

AddTree adds a sub-tree without children

func (*Tree[T]) AddTree

func (t *Tree[T]) AddTree(child *Tree[T])

AddTree adds a sub-tree

func (*Tree[T]) Aggregate

func (t *Tree[T]) Aggregate(fn func(parent, child T))

Aggregate aggregates tree branches

func (*Tree[T]) String

func (t *Tree[T]) String() string

String converts the tree to a multiline string

type TreemapPrinter

type TreemapPrinter struct {
	ByExtension bool
	ByCount     bool
}

TreemapPrinter prints a tree in treemap CSV format

func (TreemapPrinter) Print

func (p TreemapPrinter) Print(t *FileTree) string

Print prints a FileTree

Jump to

Keyboard shortcuts

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