Documentation ¶
Index ¶
- type ArrayList
- func (al *ArrayList[T]) Add(v T)
- func (al *ArrayList[T]) AddCol(ac cog.Collection[T])
- func (al *ArrayList[T]) Adds(vs ...T)
- func (al *ArrayList[T]) Cap() int
- func (al *ArrayList[T]) Clear()
- func (al *ArrayList[T]) Contain(v T) bool
- func (al *ArrayList[T]) ContainCol(ac cog.Collection[T]) bool
- func (al *ArrayList[T]) ContainIter(it cog.Iterator[T]) bool
- func (al *ArrayList[T]) Contains(vs ...T) bool
- func (al *ArrayList[T]) DeleteAt(index int)
- func (al *ArrayList[T]) Each(f func(int, T) bool)
- func (al *ArrayList[T]) Get(index int) T
- func (al *ArrayList[T]) Head() (v T)
- func (al *ArrayList[T]) Index(v T) int
- func (al *ArrayList[T]) IndexFunc(f func(T) bool) int
- func (al *ArrayList[T]) Insert(index int, v T)
- func (al *ArrayList[T]) InsertCol(index int, ac cog.Collection[T])
- func (al *ArrayList[T]) Inserts(index int, vs ...T)
- func (al *ArrayList[T]) IsEmpty() bool
- func (al *ArrayList[T]) Iterator() cog.Iterator[T]
- func (al *ArrayList[T]) Len() int
- func (al *ArrayList[T]) MarshalJSON() ([]byte, error)
- func (al *ArrayList[T]) Peek() (v T, ok bool)
- func (al *ArrayList[T]) PeekHead() (v T, ok bool)
- func (al *ArrayList[T]) PeekTail() (v T, ok bool)
- func (al *ArrayList[T]) Poll() (T, bool)
- func (al *ArrayList[T]) PollHead() (v T, ok bool)
- func (al *ArrayList[T]) PollTail() (v T, ok bool)
- func (al *ArrayList[T]) Push(v T)
- func (al *ArrayList[T]) PushHead(v T)
- func (al *ArrayList[T]) PushHeadCol(ac cog.Collection[T])
- func (al *ArrayList[T]) PushHeads(vs ...T)
- func (al *ArrayList[T]) PushTail(v T)
- func (al *ArrayList[T]) PushTailCol(ac cog.Collection[T])
- func (al *ArrayList[T]) PushTails(vs ...T)
- func (al *ArrayList[T]) Pushs(vs ...T)
- func (al *ArrayList[T]) Remove(v T)
- func (al *ArrayList[T]) RemoveCol(ac cog.Collection[T])
- func (al *ArrayList[T]) RemoveFunc(f func(T) bool)
- func (al *ArrayList[T]) RemoveIter(it cog.Iterator[T])
- func (al *ArrayList[T]) Removes(vs ...T)
- func (al *ArrayList[T]) Reserve(n int)
- func (al *ArrayList[T]) RetainCol(ac cog.Collection[T])
- func (al *ArrayList[T]) RetainFunc(f func(T) bool)
- func (al *ArrayList[T]) Retains(vs ...T)
- func (al *ArrayList[T]) ReverseEach(f func(int, T) bool)
- func (al *ArrayList[T]) Set(index int, v T) (ov T)
- func (al *ArrayList[T]) Sort(less cog.Less[T])
- func (al *ArrayList[T]) String() string
- func (al *ArrayList[T]) Swap(i, j int)
- func (al *ArrayList[T]) Tail() (v T)
- func (al *ArrayList[T]) UnmarshalJSON(data []byte) error
- func (al *ArrayList[T]) Values() []T
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 ¶
AsArrayList returns an initialized list. Example: AsArrayList([]T{1, 2, 3})
func NewArrayList ¶
NewArrayList returns an initialized list. Example: cog.NewArrayList(1, 2, 3)
func (*ArrayList[T]) AddCol ¶
func (al *ArrayList[T]) AddCol(ac cog.Collection[T])
AddCol adds all items of another collection
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 ¶
ContainIter Test to see if the collection contains all items of iterator 'it'
func (*ArrayList[T]) Get ¶
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]) Index ¶
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 ¶
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 ¶
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 ¶
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]) MarshalJSON ¶
MarshalJSON implements type json.Marshaler interface, so can be called in json.Marshal(al)
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 ¶
RemoveFunc remove all items that function f returns true
func (*ArrayList[T]) RemoveIter ¶
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]) 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 ¶
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 ¶
ReverseEach call f for each item in the list with reverse order
func (*ArrayList[T]) Set ¶
Set set the v at the specified index in this list and returns the old value.
func (*ArrayList[T]) Sort ¶
Sort Sorts this list according to the order induced by the specified Comparator.
func (*ArrayList[T]) UnmarshalJSON ¶
UnmarshalJSON implements type json.Unmarshaler interface, so can be called in json.Unmarshal(data, al)