slices

package module
v0.0.0-...-2933d81 Latest Latest
Warning

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

Go to latest
Published: Dec 27, 2023 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

slices package

Generic Class base implementation for golang.org/x/exp/slices

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CompareFunc

func CompareFunc[E1, E2 any](s1 ISlice[E1], s2 ISlice[E2], cmp func(E1, E2) int) int

func EqualFunc

func EqualFunc[E1, E2 any](s1 ISlice[E1], s2 ISlice[E2], eq func(E1, E2) bool) bool

Types

type ComparableSlice

type ComparableSlice[E comparable] struct {
	Slice[E]
}

func (*ComparableSlice[E]) Clone

func (s *ComparableSlice[E]) Clone() ISlice[E]

func (*ComparableSlice[E]) Compact

func (s *ComparableSlice[E]) Compact()

func (*ComparableSlice[E]) Contains

func (s *ComparableSlice[E]) Contains(e E) bool

func (*ComparableSlice[E]) Equal

func (s *ComparableSlice[E]) Equal(o IComparableSlice[E]) bool

func (*ComparableSlice[E]) Index

func (s *ComparableSlice[E]) Index(e E) int

func (*ComparableSlice[E]) TryComparable

func (s *ComparableSlice[E]) TryComparable() (IComparableSlice[E], bool)

func (*ComparableSlice[E]) TryOrdered

func (s *ComparableSlice[E]) TryOrdered() (IOrderedSlice[E], bool)

type IComparableSlice

type IComparableSlice[E any] interface {
	ISlice[E]
	Compact()
	Contains(E) bool
	Equal(IComparableSlice[E]) bool
	Index(E) int
}

func NewComparableSlice

func NewComparableSlice[E comparable]() IComparableSlice[E]

func NewComparableSliceFrom

func NewComparableSliceFrom[E comparable, S []E](s S) IComparableSlice[E]

type IOrderedSlice

type IOrderedSlice[E any] interface {
	IComparableSlice[E]
	BinarySearch(E) (int, bool)
	Compare(IOrderedSlice[E]) int
	IsSorted() bool
	Sort()
}

func NewOrderedSlice

func NewOrderedSlice[E ordered]() IOrderedSlice[E]

func NewOrderedSliceFrom

func NewOrderedSliceFrom[E ordered, S []E](s S) IOrderedSlice[E]

type ISlice

type ISlice[E any] interface {
	// Get value at specified index
	//
	// # Arguments
	// * `i`: `int` - Index
	//
	// # Returns
	// * `E` - Internal value
	Get(i int) E

	// Set value at specified index
	//
	// # Arguments
	// * `i`: `int` - Index
	// * `e`: `E` - Value to be set
	Set(i int, e E)

	// Append element(s)
	//
	// # Arguments
	// `elems`: `...E` - Elements to be added
	Append(elems ...E)
	Size() int
	BinarySearchFunc(E, func(E, E) int) (int, bool)
	Clip()
	Clone() ISlice[E]
	CompactFunc(func(E, E) bool)
	CompareFunc(ISlice[E], func(E, E) int) int
	ContainsFunc(func(E) bool) bool
	Delete(int, int)
	EqualFunc(ISlice[E], func(E, E) bool) bool
	Grow(int)
	IndexFunc(func(E) bool) int
	Insert(int, ...E)
	IsSortedFunc(func(E, E) bool) bool
	Replace(int, int, ...E)
	SortFunc(func(E, E) bool)
	SortStableFunc(func(E, E) bool)
	TryComparable() (IComparableSlice[E], bool)
	TryOrdered() (IOrderedSlice[E], bool)
}

func NewSlice

func NewSlice[E any]() ISlice[E]

func NewSliceFrom

func NewSliceFrom[E any, S []E](s S) ISlice[E]

type OrderedSlice

type OrderedSlice[E ordered] struct {
	ComparableSlice[E]
}

func (*OrderedSlice[E]) BinarySearch

func (s *OrderedSlice[E]) BinarySearch(target E) (int, bool)

func (*OrderedSlice[E]) Clone

func (s *OrderedSlice[E]) Clone() ISlice[E]

func (*OrderedSlice[E]) Compare

func (s *OrderedSlice[E]) Compare(o IOrderedSlice[E]) int

func (*OrderedSlice[E]) IsSorted

func (s *OrderedSlice[E]) IsSorted() bool

func (*OrderedSlice[E]) Sort

func (s *OrderedSlice[E]) Sort()

func (*OrderedSlice[E]) TryComparable

func (s *OrderedSlice[E]) TryComparable() (IComparableSlice[E], bool)

func (*OrderedSlice[E]) TryOrdered

func (s *OrderedSlice[E]) TryOrdered() (IOrderedSlice[E], bool)

type Slice

type Slice[E any] struct {
	// contains filtered or unexported fields
}

func (*Slice[E]) Append

func (s *Slice[E]) Append(elems ...E)

func (*Slice[E]) BinarySearchFunc

func (s *Slice[E]) BinarySearchFunc(target E, cmp func(E, E) int) (int, bool)

func (*Slice[E]) Clip

func (s *Slice[E]) Clip()

func (*Slice[E]) Clone

func (s *Slice[E]) Clone() ISlice[E]

func (*Slice[E]) CompactFunc

func (s *Slice[E]) CompactFunc(eq func(E, E) bool)

func (*Slice[E]) CompareFunc

func (s *Slice[E]) CompareFunc(o ISlice[E], cmp func(E, E) int) int

func (*Slice[E]) ContainsFunc

func (s *Slice[E]) ContainsFunc(cond func(E) bool) bool

func (*Slice[E]) Delete

func (s *Slice[E]) Delete(delStart, delEnd int)

func (*Slice[E]) EqualFunc

func (s *Slice[E]) EqualFunc(o ISlice[E], eq func(E, E) bool) bool

func (*Slice[E]) Get

func (s *Slice[E]) Get(i int) E

func (*Slice[E]) Grow

func (s *Slice[E]) Grow(n int)

func (*Slice[E]) IndexFunc

func (s *Slice[E]) IndexFunc(cond func(E) bool) int

func (*Slice[E]) Insert

func (s *Slice[E]) Insert(i int, elems ...E)

func (*Slice[E]) IsSortedFunc

func (s *Slice[E]) IsSortedFunc(less func(E, E) bool) bool

func (*Slice[E]) Replace

func (s *Slice[E]) Replace(start, end int, elems ...E)

func (*Slice[E]) Set

func (s *Slice[E]) Set(i int, e E)

func (*Slice[E]) Size

func (s *Slice[E]) Size() int

func (*Slice[E]) SortFunc

func (s *Slice[E]) SortFunc(less func(E, E) bool)

func (*Slice[E]) SortStableFunc

func (s *Slice[E]) SortStableFunc(less func(E, E) bool)

func (*Slice[E]) TryComparable

func (s *Slice[E]) TryComparable() (IComparableSlice[E], bool)

func (*Slice[E]) TryOrdered

func (s *Slice[E]) TryOrdered() (IOrderedSlice[E], bool)

Jump to

Keyboard shortcuts

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