slice

package
v0.0.2-0...-db6250e Latest Latest
Warning

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

Go to latest
Published: Dec 17, 2020 License: CC0-1.0, CC0-1.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Hash

func Hash(S Interface) hash.Value

Hash returns a hash value for the given slice. If S satisfies the hash.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() []object.Element // ToElementSlice returns a copy
	   of the slice as an []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() hash.Value

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() int                   // Len returns the length of the slice.
	Entry(i int) object.Element // Entry returns the i-th element in the slice. This will panic if i is out of range.
}

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(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.
}

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