arraylist

package
v1.0.25 Latest Latest
Warning

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

Go to latest
Published: Aug 16, 2024 License: MIT Imports: 8 Imported by: 1

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ArrayList

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

ArrayList implements a list holdes the item in a array. The zero value for ArrayList is an empty list ready to use.

To iterate over a list (where al is a *ArrayList):

it := al.Iterator()
for it.Next() {
	// do something with it.Value()
}
Example
list := NewArrayList[string]()
list.Add("a")                         // ["a"]
list.Adds("c", "b")                   // ["a","c","b"]
list.Sort(cmp.LessString)             // ["a","b","c"]
_ = list.Get(0)                       // "a"  //_ = list.Get(100)  --> panic
_ = list.Contain("a")                 // true
_ = list.Contains("a", "b", "c")      // true
_ = list.Contains("a", "b", "c", "d") // false
list.Swap(0, 1)                       // ["b","a",c"]
list.DeleteAt(2)                      // ["b","a"]
list.DeleteAt(1)                      // ["b"]
list.DeleteAt(0)                      // []
_ = list.IsEmpty()                    // true
_ = list.Len()                        // 0
list.Add("a")                         // ["a"]
list.Clear()                          // []
list.Insert(0, "b")                   // ["b"]
list.Insert(0, "a")                   // ["a","b"]
Output:

func AsArrayList

func AsArrayList[T any](vs []T) *ArrayList[T]

AsArrayList returns an initialized list. Example: AsArrayList([]T{1, 2, 3})

func NewArrayList

func NewArrayList[T any](vs ...T) *ArrayList[T]

NewArrayList returns an initialized list. Example: cog.NewArrayList(1, 2, 3)

func (*ArrayList[T]) Add

func (al *ArrayList[T]) Add(v T)

Add add the item v

func (*ArrayList[T]) AddCol

func (al *ArrayList[T]) AddCol(ac cog.Collection[T])

AddCol adds all items of another collection

func (*ArrayList[T]) Adds

func (al *ArrayList[T]) Adds(vs ...T)

Adds adds all items of vs

func (*ArrayList[T]) Cap

func (al *ArrayList[T]) Cap() int

Cap returns the capcity of the list.

func (*ArrayList[T]) Clear

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

Clear clears list al.

func (*ArrayList[T]) Contain

func (al *ArrayList[T]) Contain(v T) bool

Contain Test to see if the list contains the value v

func (*ArrayList[T]) ContainCol

func (al *ArrayList[T]) ContainCol(ac cog.Collection[T]) bool

ContainCol Test to see if the collection contains all items of another collection

func (*ArrayList[T]) ContainIter

func (al *ArrayList[T]) ContainIter(it cog.Iterator[T]) bool

ContainIter Test to see if the collection contains all items of iterator 'it'

func (*ArrayList[T]) Contains

func (al *ArrayList[T]) Contains(vs ...T) bool

Contains Test to see if the collection contains all items of vs

func (*ArrayList[T]) DeleteAt

func (al *ArrayList[T]) DeleteAt(index int)

DeleteAt remove the item at the specified position in this list.

func (*ArrayList[T]) Each

func (al *ArrayList[T]) Each(f func(int, T) bool)

Each call f for each item in the list

func (*ArrayList[T]) Get

func (al *ArrayList[T]) Get(index int) T

Get returns the item at the specified position in this list if i < -al.Len() or i >= al.Len(), panic if i < 0, returns al.Get(al.Len() + i)

func (*ArrayList[T]) Head

func (al *ArrayList[T]) Head() (v T)

Head get the first item of list.

func (*ArrayList[T]) Index

func (al *ArrayList[T]) Index(v T) int

Index returns the index of the first occurrence of the specified v in this list, or -1 if this list does not contain v.

func (*ArrayList[T]) IndexFunc

func (al *ArrayList[T]) IndexFunc(f func(T) bool) int

IndexFunc returns the index of the first true returned by function f in this list, or -1 if this list does not contain v.

func (*ArrayList[T]) Insert

func (al *ArrayList[T]) Insert(index int, v T)

Insert insert the item v at specified index position shifting the value at that position (if any) and any subsequent elements to the right. Panic if position is bigger than list's size Note: position equal to list's size is valid, i.e. append.

func (*ArrayList[T]) InsertCol

func (al *ArrayList[T]) InsertCol(index int, ac cog.Collection[T])

InsertCol inserts values of another collection ac at specified index position shifting the value at that position (if any) and any subsequent elements to the right. Panic if position is bigger than list's size Note: position equal to list's size is valid, i.e. append.

func (*ArrayList[T]) Inserts

func (al *ArrayList[T]) Inserts(index int, vs ...T)

Insert inserts values at specified index position shifting the value at that position (if any) and any subsequent elements to the right. Panic if position is bigger than list's size Note: position equal to list's size is valid, i.e. append.

func (*ArrayList[T]) IsEmpty

func (al *ArrayList[T]) IsEmpty() bool

IsEmpty returns true if the list length == 0

func (*ArrayList[T]) Iterator

func (al *ArrayList[T]) Iterator() cog.Iterator[T]

Iterator returns a iterator for the list

func (*ArrayList[T]) Len

func (al *ArrayList[T]) Len() int

Len returns the length of the list.

func (*ArrayList[T]) MarshalJSON

func (al *ArrayList[T]) MarshalJSON() ([]byte, error)

MarshalJSON implements type json.Marshaler interface, so can be called in json.Marshal(al)

func (*ArrayList[T]) Peek

func (al *ArrayList[T]) Peek() (v T, ok bool)

Peek get the first item of list.

func (*ArrayList[T]) PeekHead

func (al *ArrayList[T]) PeekHead() (v T, ok bool)

PeekHead get the first item of list.

func (*ArrayList[T]) PeekTail

func (al *ArrayList[T]) PeekTail() (v T, ok bool)

PeekTail get the last item of list.

func (*ArrayList[T]) Poll

func (al *ArrayList[T]) Poll() (T, bool)

Poll get and remove the first item of list.

func (*ArrayList[T]) PollHead

func (al *ArrayList[T]) PollHead() (v T, ok bool)

PollHead get and remove the first item of list.

func (*ArrayList[T]) PollTail

func (al *ArrayList[T]) PollTail() (v T, ok bool)

PollTail get and remove the last item of list.

func (*ArrayList[T]) Push

func (al *ArrayList[T]) Push(v T)

Push insert item v at the tail of list al.

func (*ArrayList[T]) PushHead

func (al *ArrayList[T]) PushHead(v T)

PushHead inserts the item v at the head of list al.

func (*ArrayList[T]) PushHeadCol

func (al *ArrayList[T]) PushHeadCol(ac cog.Collection[T])

PushHeadCol inserts a copy of another collection at the head of list al. The al and ac may be the same. They must not be nil.

func (*ArrayList[T]) PushHeads

func (al *ArrayList[T]) PushHeads(vs ...T)

PushHeads inserts all items of vs at the head of list al.

func (*ArrayList[T]) PushTail

func (al *ArrayList[T]) PushTail(v T)

PushTail inserts the item v at the tail of list al.

func (*ArrayList[T]) PushTailCol

func (al *ArrayList[T]) PushTailCol(ac cog.Collection[T])

PushTailCol inserts a copy of another collection at the tail of list al. The al and ac may be the same. They must not be nil.

func (*ArrayList[T]) PushTails

func (al *ArrayList[T]) PushTails(vs ...T)

PushTails inserts all items of vs at the tail of list al.

func (*ArrayList[T]) Pushs

func (al *ArrayList[T]) Pushs(vs ...T)

Push inserts all items of vs at the tail of list al.

func (*ArrayList[T]) Remove

func (al *ArrayList[T]) Remove(v T)

Remove remove all items with associated value v of vs

func (*ArrayList[T]) RemoveCol

func (al *ArrayList[T]) RemoveCol(ac cog.Collection[T])

RemoveCol remove all of this collection's elements that are also contained in the specified collection

func (*ArrayList[T]) RemoveFunc

func (al *ArrayList[T]) RemoveFunc(f func(T) bool)

RemoveFunc remove all items that function f returns true

func (*ArrayList[T]) RemoveIter

func (al *ArrayList[T]) RemoveIter(it cog.Iterator[T])

RemoveIter remove all items in the iterator it

func (*ArrayList[T]) Removes

func (al *ArrayList[T]) Removes(vs ...T)

Removes remove all items in the array vs

func (*ArrayList[T]) Reserve

func (al *ArrayList[T]) Reserve(n int)

Reserve Increase the capacity of the underlying array.

func (*ArrayList[T]) RetainCol

func (al *ArrayList[T]) RetainCol(ac cog.Collection[T])

RetainCol Retains only the elements in this collection that are contained in the specified collection.

func (*ArrayList[T]) RetainFunc

func (al *ArrayList[T]) RetainFunc(f func(T) bool)

RetainFunc Retains all items that function f returns true

func (*ArrayList[T]) Retains

func (al *ArrayList[T]) Retains(vs ...T)

Retains Retains only the elements in this collection that are contained in the argument array vs.

func (*ArrayList[T]) ReverseEach

func (al *ArrayList[T]) ReverseEach(f func(int, T) bool)

ReverseEach call f for each item in the list with reverse order

func (*ArrayList[T]) Set

func (al *ArrayList[T]) Set(index int, v T) (ov T)

Set set the v at the specified index in this list and returns the old value.

func (*ArrayList[T]) Sort

func (al *ArrayList[T]) Sort(less cog.Less[T])

Sort Sorts this list according to the order induced by the specified Comparator.

func (*ArrayList[T]) String

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

String print list to string

func (*ArrayList[T]) Swap

func (al *ArrayList[T]) Swap(i, j int)

Swap swaps values of two items at the given index.

func (*ArrayList[T]) Tail

func (al *ArrayList[T]) Tail() (v T)

Tail get the last item of list.

func (*ArrayList[T]) UnmarshalJSON

func (al *ArrayList[T]) UnmarshalJSON(data []byte) error

UnmarshalJSON implements type json.Unmarshaler interface, so can be called in json.Unmarshal(data, al)

func (*ArrayList[T]) Values

func (al *ArrayList[T]) Values() []T

Values returns a slice contains all the items of the list al

Jump to

Keyboard shortcuts

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