goutils

package module
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Apr 4, 2024 License: MIT Imports: 8 Imported by: 24

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrInfiniteLoop = errors.New("infinite loop detected")

Functions

func Deserialize

func Deserialize[T any](raw string) T

Deserialize deserialize a string to a type.

func DeserializeValue

func DeserializeValue(ty reflect.Type, raw string) (reflect.Value, error)

DeserializeValue deserialize a string to a reflect.Value

func JoinArray

func JoinArray(s []string) string

func MustSplitArray

func MustSplitArray(raw string) []string

MustSplitArray is a wrapper of Deserialize which panics if an error occurs.

func ReadLine

func ReadLine(r *bufio.Reader) string

func Serialize

func Serialize(v any) string

Serialize serialize a value to a string.

func SplitArray

func SplitArray(raw string) ([]string, error)

SplitArray splits a comma separated array string which may contain different types into a slice of strings.

Types

type ListNode

type ListNode struct {
	Val  int
	Next *ListNode
}

func DeserializeListNode

func DeserializeListNode(s string) (*ListNode, error)

func (*ListNode) Nodes

func (l *ListNode) Nodes() []*ListNode

func (*ListNode) String added in v0.2.1

func (l *ListNode) String() string

String returns a string representation of the linked list. It panics with ErrInfiniteLoop if a cycle is detected.

func (*ListNode) ToString

func (l *ListNode) ToString() string

ToString is deprecated, use String()

func (*ListNode) Values

func (l *ListNode) Values() []int

type NaryTreeNode

type NaryTreeNode struct {
	Val      int
	Children []*NaryTreeNode
}

func DeserializeNaryTreeNode

func DeserializeNaryTreeNode(s string) (*NaryTreeNode, error)

func (*NaryTreeNode) String added in v0.2.1

func (t *NaryTreeNode) String() string

String returns a string representation of the nary tree. It panics with ErrInfiniteLoop if a cycle is detected.

func (*NaryTreeNode) ToString

func (t *NaryTreeNode) ToString() string

ToString is deprecated, use String

type Node

type Node struct {
	Val   int
	Prev  *Node
	Next  *Node
	Child *Node
}

type TreeNode

type TreeNode struct {
	Val   int
	Left  *TreeNode
	Right *TreeNode
}

func DeserializeTreeNode

func DeserializeTreeNode(s string) (*TreeNode, error)

func (*TreeNode) String added in v0.2.1

func (t *TreeNode) String() string

String returns a string representation of the binary tree. It panics with ErrInfiniteLoop if a cycle is detected.

func (*TreeNode) ToString

func (t *TreeNode) ToString() string

ToString is deprecated, use String()

Jump to

Keyboard shortcuts

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