containers

package
v0.0.0-...-512269d Latest Latest
Warning

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

Go to latest
Published: May 29, 2023 License: MIT Imports: 2 Imported by: 0

README

提供增强的容器

安装

特性 features

注意事项

注意事项

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetSortedValues

func GetSortedValues(container Container, comparator algorithm.Comparator) []interface{}

func NewxStack

func NewxStack() *xStack

Types

type Container

type Container interface {
	Empty() bool
	Size() int
	Clear()
	Values() []interface{}
	String() string
}

Container is base interface that all data structures implement.

type IteratorWithIndex

type IteratorWithIndex interface {
	// Next moves the iterator to the next element and returns true if there was a next element in the container.
	// If Next() returns true, then next element's index and value can be retrieved by Index() and Value().
	// If Next() was called for the first time, then it will point the iterator to the first element if it exists.
	// Modifies the state of the iterator.
	Next() bool

	// Value returns the current element's value.
	// Does not modify the state of the iterator.
	Value() interface{}

	// Index returns the current element's index.
	// Does not modify the state of the iterator.
	Index() int

	// Begin resets the iterator to its initial state (one-before-first)
	// Call Next() to fetch the first element if any.
	Begin()
	// First moves the iterator to the first element and returns true if there was a first element in the container
	First() bool

	// NextTo moves the iterator to the next element from current position that satisfies the condition given by the
	// passed function, and returns true if there was a next element in the container.
	// If NextTo() returns true, then next element's index and value can be retrieved by Index() and Value().
	// Modifies the state of the iterator.
	NextTo(func(index int, value interface{}) bool) bool
}

IteratorWithIndex is stateful iterator for ordered containers whose values can be fetched by an index.

type JSONDeserializer

type JSONDeserializer interface {
	// FromJSON populates containers's elements from the input JSON representation.
	FromJSON([]byte) error
	// UnmarshalJSON @implements json.Unmarshaler
	UnmarshalJSON([]byte) error
}

JSONDeserializer provides JSON deserialization

type JSONSerializer

type JSONSerializer interface {
	// ToJSON output the JSON representation of container's element
	ToJSON() ([]byte, error)
	// MarshalJSON @implements json.Marshaler
	MarshalJSON() ([]byte, error)
}

type Stack

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

Stack 栈

func NewStack

func NewStack() *Stack

NewStack 创建栈

func (*Stack) IsEmpty

func (s *Stack) IsEmpty() bool

IsEmpty 栈是否为空

func (*Stack) Pop

func (s *Stack) Pop() (interface{}, error)

Pop 出栈

func (*Stack) Push

func (s *Stack) Push(v interface{})

Push 入栈

func (*Stack) Size

func (s *Stack) Size() int

Size 栈的大小

func (*Stack) Top

func (s *Stack) Top() (interface{}, error)

Top 返回栈顶元素

Jump to

Keyboard shortcuts

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