collections

package
v0.0.0-...-2e562ea Latest Latest
Warning

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

Go to latest
Published: Dec 18, 2023 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Overview

copied from https://github.com/Tufin/asciitree; Apache 2

stack of strings

stack of integers

Index

Constants

View Source
const (
	Regular boxType = iota
	Last
	AfterLast
	Between
)

Variables

This section is empty.

Functions

func CollectFiles

func CollectFiles(dir string) (files []string, err error)

CollectFiles is a convenience function to gather files under a directory.

func FileSha256

func FileSha256(filename string) (string, error)

FileSha256 computes the sha256 hash of a file

func ListFiles

func ListFiles(dir string) error

ListFiles is a convenience debugging function to log the files under a given dir.

func Sha256

func Sha256(in io.Reader) (string, error)

Sha256 computes the sha256 of the given reader

func WaitForConnectionAvailable

func WaitForConnectionAvailable(host string, port int, timeout time.Duration) bool

WaitForConnectionAvailable pings a tcp connection every 250 milliseconds until it connects and returns true. If it fails to connect by the timeout deadline, returns false.

Types

type Intent

type Intent struct {
	Value string
	Want  bool
}

Intent represents an action for an attribute name or "value" optionally prefixed by a '+' or '-'. If the prefix is missing, the Intent is not negative.

func ParseIntent

func ParseIntent(value string) *Intent

type PathTrie

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

PathTrie is a trie of string keys and interface{} values. Internal nodes have nil values so stored nil values cannot be distinguished and are excluded from walks. By default, PathTrie will segment keys by forward slashes with PathSegmenter (e.g. "/a/b/c" -> "/a", "/b", "/c"). A custom StringSegmenter may be used to customize how strings are segmented into nodes. A classic trie might segment keys by rune (i.e. unicode points).

func NewPathTrieWithConfig

func NewPathTrieWithConfig(config *PathTrieConfig) *PathTrie

NewPathTrieWithConfig allocates and returns a new *PathTrie with the given *PathTrieConfig

func (*PathTrie) Delete

func (trie *PathTrie) Delete(key string) bool

Delete removes the value associated with the given key. Returns true if a node was found for the given key. If the node or any of its ancestors becomes childless as a result, it is removed from the trie.

func (*PathTrie) Fprint

func (trie *PathTrie) Fprint(w io.Writer, root bool, padding string)

Fprint prints a tree structure to the given writer.

func (*PathTrie) Get

func (trie *PathTrie) Get(key string) *PathTrie

Get returns the value stored at the given key. Returns nil for internal nodes or for nodes with a value of nil.

func (*PathTrie) Put

func (trie *PathTrie) Put(key string, value interface{}) (*PathTrie, bool)

Put inserts the value into the trie at the given key, replacing any existing items. It returns true if the put adds a new value, false if it replaces an existing value. Note that internal nodes have nil values so a stored nil value will not be distinguishable and will not be included in Walks.

func (*PathTrie) String

func (trie *PathTrie) String() string

String implements the fmt.Stringer interface.

func (*PathTrie) Walk

func (trie *PathTrie) Walk(walker trie.WalkFunc) error

Walk iterates over each key/value stored in the trie and calls the given walker function with the key and value. If the walker function returns an error, the walk is aborted. The traversal is depth first with no guaranteed order.

func (*PathTrie) WalkPath

func (trie *PathTrie) WalkPath(key string, wantRootValue bool, walker trie.WalkFunc) error

WalkPath iterates over each key/value in the path in trie from the root to the node at the given key, calling the given walker function for each key/value. If the walker function returns an error, the walk is aborted.

type PathTrieConfig

type PathTrieConfig struct {
	Segmenter trie.StringSegmenter
	Separator string
}

PathTrieConfig for building a path trie with different segmenter

type StringSlice

type StringSlice []string

func (*StringSlice) Set

func (i *StringSlice) Set(value string) error

Set implements the flag.Value interface.

func (*StringSlice) String

func (i *StringSlice) String() string

type StringStack

type StringStack []string

func (*StringStack) IsEmpty

func (s *StringStack) IsEmpty() bool

IsEmpty checks if the stack is empty

func (*StringStack) Peek

func (s *StringStack) Peek() (string, bool)

Peek: return top element of stack, return false if stack is empty

func (*StringStack) Pop

func (s *StringStack) Pop() (string, bool)

Pop: remove and return top element of stack, return false if stack is empty

func (*StringStack) Push

func (s *StringStack) Push(x string)

Push a new string onto the stack

type UInt32Stack

type UInt32Stack []uint32

func (*UInt32Stack) IsEmpty

func (s *UInt32Stack) IsEmpty() bool

IsEmpty checks if the stack is empty

func (*UInt32Stack) Peek

func (s *UInt32Stack) Peek() (uint32, bool)

Peek: return top element of stack, return false if stack is empty

func (*UInt32Stack) Pop

func (s *UInt32Stack) Pop() (uint32, bool)

Pop: remove and return top element of stack, return false if stack is empty

func (*UInt32Stack) Push

func (s *UInt32Stack) Push(x uint32)

Push a new integer onto the stack

Jump to

Keyboard shortcuts

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