slice

package module
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Apr 14, 2021 License: CC0-1.0 Imports: 4 Imported by: 1

Documentation

Index

Constants

View Source
const (
	ErrSliceLengthMustBeNonNegative = objectError(iota)
)

Common errors.

Variables

This section is empty.

Functions

func Hash

func Hash(S Interface) uint32

Hash returns a hash value for the given slice. If S satisfies the object.Hasher interface then S's Hash method will be called.

func Index

func Index(cmp compare.CmpFunc, S Interface, x object.Element) (int, error)

Index uses the given comparison function cmp to search for x in a slice S, and return the index, or -1 if not present. Assumes that the slice is sorted in increasing order as determined by cmp.

func Search(cmp compare.CmpFunc, S Interface, x object.Element) (int, error)

Search uses the given comparison function cmp to search for x in a slice S, and return the index as specified by sort.Search. The return value is the index to insert x if x is not present (it could be S.Len()). Assumes that the slice is sorted in increasing order as determined by cmp.

func ToElementSlice

func ToElementSlice(S Interface) []object.Element

ToElementSlice returns a copy of S as an []object.Element. If S satisfies the interface:

type ToElementSlicer interface {
	// ToElementSlice returns a copy of the slice as
	// an []object.Element.
	ToElementSlice() []object.Element
}

then S's ToElementSlice method will be called.

Types

type ElementSlice

type ElementSlice []object.Element

ElementSlice wraps an []object.Element, implementing Interface.

func (ElementSlice) Entry

func (S ElementSlice) Entry(i int) object.Element

Entry returns the i-th element in the slice. This will panic if i is out of range.

func (ElementSlice) Hash

func (S ElementSlice) Hash() uint32

Hash returns a hash value for this slice.

func (ElementSlice) Len

func (S ElementSlice) Len() int

Len returns the length of the slice.

func (ElementSlice) Slice

func (S ElementSlice) Slice(k int, m int) Interface

Slice returns a subslice starting at index k and of length m - k. The returned subslice will be of the same underlying type. This will panic if the arguments are out of range.

func (ElementSlice) ToElementSlice

func (S ElementSlice) ToElementSlice() []object.Element

ToElementSlice returns a copy of the slice as an []object.Element.

type GeneratorFunc

type GeneratorFunc func(i int) object.Element

GeneratorFunc is used to dynamically generate the i-th entry in a slice.

type Interface

type Interface interface {
	// Len returns the length of the slice.
	Len() int
	// Entry returns the i-th element in the slice. This will panic
	// if i is out of range.
	Entry(i int) object.Element
}

Interface is a basic interface used to describe a slices of object.Elements.

func NewGenerator

func NewGenerator(size int, f GeneratorFunc) (Interface, error)

NewGenerator returns a new dynamic slice of length "size" using the given generator function.

func ReverseSlice

func ReverseSlice(S Interface) Interface

ReverseSlice wraps the slice S reversing the entries.

func Slice

func Slice(S Interface, k int, m int) Interface

Slice returns a subslice of S starting at index k and of length m - k. This will panic if the arguments are out of range. If S satisfies the interface:

type Slicer interface {
	// Slice returns a subslice starting at index k and of length
	// m - k. The returned subslice will be of the same underlying
	// type. This will panic if the arguments are out of range.
	Slice(k int, m int) Interface
}

then S's Slice method will be called.

Jump to

Keyboard shortcuts

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