lists

package
v0.0.3 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Swap

func Swap[T any](list List[T], i, j int)

Swap swaps the two given elements of index in the give list

Types

type ArrayList

type ArrayList[T any] struct {
	// contains filtered or unexported fields
}

func NewArrayList

func NewArrayList[T any](capacity int) *ArrayList[T]

NewArrayList returns a new ArrayList with the given capacity

func (*ArrayList[T]) Add

func (a *ArrayList[T]) Add(elems ...T)

func (*ArrayList[T]) Clear

func (a *ArrayList[T]) Clear()

func (*ArrayList[T]) Clone

func (a *ArrayList[T]) Clone() List[T]

func (*ArrayList[T]) Contains

func (a *ArrayList[T]) Contains(elem T, equal containers.Equal[T]) bool

func (*ArrayList[T]) Get

func (a *ArrayList[T]) Get(i int) (_ T, _ bool)

func (*ArrayList[T]) IndexOf

func (a *ArrayList[T]) IndexOf(elem T, equal containers.Equal[T]) int

func (*ArrayList[T]) Insert

func (a *ArrayList[T]) Insert(i int, elem ...T)

func (*ArrayList[T]) Iterator

func (a *ArrayList[T]) Iterator() containers.IndexIterator[T]

func (*ArrayList[T]) Join

func (a *ArrayList[T]) Join(list List[T])

func (*ArrayList[T]) Remove

func (a *ArrayList[T]) Remove(i int)

func (*ArrayList[T]) RemoveElem

func (a *ArrayList[T]) RemoveElem(elem T, equal containers.Equal[T])

func (*ArrayList[T]) Set

func (a *ArrayList[T]) Set(i int, elem T)

func (*ArrayList[T]) Size

func (a *ArrayList[T]) Size() int

func (*ArrayList[T]) String

func (a *ArrayList[T]) String() string

func (*ArrayList[T]) Values

func (a *ArrayList[T]) Values() (_ []T)

type Iterator

type Iterator[T any] struct {
	// contains filtered or unexported fields
}

Iterator returns a basic list iterator

func (*Iterator[T]) Index

func (i *Iterator[T]) Index() int

func (*Iterator[T]) Next

func (i *Iterator[T]) Next()

func (*Iterator[T]) Reverse

func (i *Iterator[T]) Reverse()

func (*Iterator[T]) Rewind

func (i *Iterator[T]) Rewind()

func (*Iterator[T]) SeekTo

func (i *Iterator[T]) SeekTo(index int) bool

func (*Iterator[T]) Valid added in v0.0.2

func (i *Iterator[T]) Valid() bool

func (*Iterator[T]) Value

func (i *Iterator[T]) Value() (_ T)

type LinkedList added in v0.0.3

type LinkedList[T any] struct {
	// contains filtered or unexported fields
}

LinkedList implements the list interface by linked nodes which is more efficient to insert and remove nodes.

func NewLinkedList added in v0.0.3

func NewLinkedList[T any]() *LinkedList[T]

func (*LinkedList[T]) Add added in v0.0.3

func (l *LinkedList[T]) Add(elems ...T)

func (*LinkedList[T]) Clear added in v0.0.3

func (l *LinkedList[T]) Clear()

func (*LinkedList[T]) Clone added in v0.0.3

func (l *LinkedList[T]) Clone() List[T]

func (*LinkedList[T]) Contains added in v0.0.3

func (l *LinkedList[T]) Contains(elem T, equal containers.Equal[T]) bool

func (*LinkedList[T]) Get added in v0.0.3

func (l *LinkedList[T]) Get(i int) (val T, found bool)

func (*LinkedList[T]) IndexOf added in v0.0.3

func (l *LinkedList[T]) IndexOf(elem T, equal containers.Equal[T]) int

func (*LinkedList[T]) Insert added in v0.0.3

func (l *LinkedList[T]) Insert(i int, elems ...T)

func (*LinkedList[T]) Iterator added in v0.0.3

func (l *LinkedList[T]) Iterator() containers.IndexIterator[T]

func (*LinkedList[T]) Join added in v0.0.3

func (l *LinkedList[T]) Join(list List[T])

func (*LinkedList[T]) Remove added in v0.0.3

func (l *LinkedList[T]) Remove(i int)

func (*LinkedList[T]) RemoveElem added in v0.0.3

func (l *LinkedList[T]) RemoveElem(elem T, equal containers.Equal[T])

func (*LinkedList[T]) Set added in v0.0.3

func (l *LinkedList[T]) Set(i int, elem T)

func (*LinkedList[T]) Size added in v0.0.3

func (l *LinkedList[T]) Size() int

func (*LinkedList[T]) String added in v0.0.3

func (l *LinkedList[T]) String() string

func (*LinkedList[T]) Values added in v0.0.3

func (l *LinkedList[T]) Values() []T

type List

type List[T any] interface {
	// Get returns the elem at the given index
	Get(i int) (T, bool)
	// IndexOf returns the index of first element that matches the given element. if not found, return -1
	IndexOf(elem T, equal containers.Equal[T]) int
	// Set replaces the elem at the given index
	Set(i int, elem T)
	// Add appends the given element to the end of the list
	Add(elem ...T)
	// Insert inserts the given elems into the list at the given index
	Insert(i int, elem ...T)
	// Remove removes the elem match given index from the list
	Remove(i int)
	// RemoveElem removes the first element matches the given from the list,
	RemoveElem(elem T, equal containers.Equal[T])
	// Contains check if list contains the given elements
	Contains(elem T, equal containers.Equal[T]) bool
	// Clone returns a value-copy of the original list, not the deep-copy list
	Clone() List[T]
	// Join joins the given list into the original list
	Join(list List[T])

	containers.IndexIterable[T]

	containers.Container[T]
}

List is the base interface of all lists

Jump to

Keyboard shortcuts

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