tree

package
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: Dec 22, 2022 License: MIT Imports: 5 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"`
	Time  time.Time `json:"time"`
}

ExtensionEntry is a file tree entry for extensions

func (*ExtensionEntry) Add added in v0.2.0

func (e *ExtensionEntry) Add(size int64, count int, time tm.Time)

Add 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"`
	Time       time.Time                  `json:"time"`
	Extensions map[string]*ExtensionEntry `json:"extensions"`
}

FileEntry is a file tree entry

func NewFileEntry

func NewFileEntry(name string, size int64, time tm.Time, isDir bool) FileEntry

NewFileEntry creates a new FileEntry

func (*FileEntry) Add

func (e *FileEntry) Add(size int64, count int, time tm.Time)

Add adds size and a count

func (*FileEntry) AddExtensions

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

AddExtensions adds extensions

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, time tm.Time) *FileTree

NewFile creates a new FileTree with a file entry

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 SubTree added in v0.1.3

func SubTree[T any, P any](t *Tree[T], path []P, fn func(T, P) bool) (*Tree[T], error)

SubTree selects a sub-tree using a path

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]) Crop added in v0.1.1

func (t *Tree[T]) Crop(depth int, fn func(parent, child T))

Crop reduces the tree to a given depth

func (*Tree[T]) String

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

String converts the tree to a multiline string

Jump to

Keyboard shortcuts

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