linkedlist

package
v1.0.27 Latest Latest
Warning

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

Go to latest
Published: Aug 16, 2025 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 LinkedList

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

LinkedList implements a doubly linked list. The zero value for LinkedList is an empty list ready to use.

To iterate over a list (where ll is a *LinkedList):

it := ll.Iterator()
for it.Next() {
	// do something with it.Value()
}

func NewLinkedList

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

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

Example
list := NewLinkedList[string]()
list.Add("a")                            // ["a"]
list.AddAll("c", "b")                    // ["a","c","b"]
list.Sort(cmp.Less[string])              // ["a","b","c"]
_ = list.Get(0)                          // "a"  //_ = list.Get(100)  --> panic
_ = list.Contains("a")                   // true
_ = list.ContainsAll("a", "b", "c")      // true
_ = list.ContainsAll("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"]

func (*LinkedList[T]) Add

func (ll *LinkedList[T]) Add(v T)

Add add the item v.

func (*LinkedList[T]) AddAll added in v1.0.27

func (ll *LinkedList[T]) AddAll(vs ...T)

AddAll adds all items of vs.

func (*LinkedList[T]) AddCol

func (ll *LinkedList[T]) AddCol(ac cog.Collection[T])

AddCol adds all items of another collection

func (*LinkedList[T]) Clear

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

Clear clears list ll.

func (*LinkedList[T]) Contains

func (ll *LinkedList[T]) Contains(v T) bool

Contains Test to see if the list contains the value v

func (*LinkedList[T]) ContainsAll added in v1.0.27

func (ll *LinkedList[T]) ContainsAll(vs ...T) bool

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

func (*LinkedList[T]) ContainsCol added in v1.0.27

func (ll *LinkedList[T]) ContainsCol(ac cog.Collection[T]) bool

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

func (*LinkedList[T]) ContainsIter added in v1.0.27

func (ll *LinkedList[T]) ContainsIter(it cog.Iterator[T]) bool

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

func (*LinkedList[T]) DeleteAt

func (ll *LinkedList[T]) DeleteAt(index int)

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

func (*LinkedList[T]) Each

func (ll *LinkedList[T]) Each(f func(int, T) bool)

Each call f for each item in the list

func (*LinkedList[T]) Get

func (ll *LinkedList[T]) Get(index int) T

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

func (*LinkedList[T]) Head

func (ll *LinkedList[T]) Head() (v T)

Head get the first item of list.

func (*LinkedList[T]) Index

func (ll *LinkedList[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 (*LinkedList[T]) IndexFunc

func (ll *LinkedList[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 (*LinkedList[T]) Insert

func (ll *LinkedList[T]) Insert(index int, v T)

Insert insert value 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 (*LinkedList[T]) InsertCol

func (ll *LinkedList[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 (*LinkedList[T]) Inserts

func (ll *LinkedList[T]) Inserts(index int, vs ...T)

Inserts 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 (*LinkedList[T]) IsEmpty

func (ll *LinkedList[T]) IsEmpty() bool

IsEmpty returns true if the list length == 0

func (*LinkedList[T]) Iterator

func (ll *LinkedList[T]) Iterator() cog.Iterator[T]

Iterator returns a iterator for the list

func (*LinkedList[T]) LastIndex

func (ll *LinkedList[T]) LastIndex(v T) int

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

func (*LinkedList[T]) Len

func (ll *LinkedList[T]) Len() int

Len returns the length of the list.

func (*LinkedList[T]) MarshalJSON

func (ll *LinkedList[T]) MarshalJSON() ([]byte, error)

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

func (*LinkedList[T]) Peek

func (ll *LinkedList[T]) Peek() (v T, ok bool)

Peek get the first item of list.

func (*LinkedList[T]) PeekHead

func (ll *LinkedList[T]) PeekHead() (v T, ok bool)

PeekHead get the first item of list.

func (*LinkedList[T]) PeekTail

func (ll *LinkedList[T]) PeekTail() (v T, ok bool)

PeekTail get the last item of list.

func (*LinkedList[T]) Poll

func (ll *LinkedList[T]) Poll() (T, bool)

Poll get and remove the first item of list.

func (*LinkedList[T]) PollHead

func (ll *LinkedList[T]) PollHead() (v T, ok bool)

PollHead remove the first item of list.

func (*LinkedList[T]) PollTail

func (ll *LinkedList[T]) PollTail() (v T, ok bool)

PollTail remove the last item of list.

func (*LinkedList[T]) Pop added in v1.0.27

func (ll *LinkedList[T]) Pop() (T, bool)

Pop Retrieves and removes the tail of this list, or returns (nil, false) if this list is empty.

func (*LinkedList[T]) Push

func (ll *LinkedList[T]) Push(v T)

Push insert the item v at the tail of list al.

func (*LinkedList[T]) PushHead

func (ll *LinkedList[T]) PushHead(v T)

PushHead insert the item v at the head of list ll.

func (*LinkedList[T]) PushHeadCol

func (ll *LinkedList[T]) PushHeadCol(ac cog.Collection[T])

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

func (*LinkedList[T]) PushHeads

func (ll *LinkedList[T]) PushHeads(vs ...T)

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

func (*LinkedList[T]) PushTail

func (ll *LinkedList[T]) PushTail(v T)

PushTail insert the item v at the tail of list ll.

func (*LinkedList[T]) PushTailCol

func (ll *LinkedList[T]) PushTailCol(ac cog.Collection[T])

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

func (*LinkedList[T]) PushTails

func (ll *LinkedList[T]) PushTails(vs ...T)

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

func (*LinkedList[T]) Pushs

func (ll *LinkedList[T]) Pushs(vs ...T)

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

func (*LinkedList[T]) Remove

func (ll *LinkedList[T]) Remove(v T)

Remove remove all items with associated value v

func (*LinkedList[T]) RemoveAll added in v1.0.27

func (ll *LinkedList[T]) RemoveAll(vs ...T)

RemoveAll remove all items in the array vs

func (*LinkedList[T]) RemoveCol

func (ll *LinkedList[T]) RemoveCol(ac cog.Collection[T])

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

func (*LinkedList[T]) RemoveFunc

func (ll *LinkedList[T]) RemoveFunc(f func(T) bool)

RemoveFunc remove all items that function f returns true

func (*LinkedList[T]) RemoveIter

func (ll *LinkedList[T]) RemoveIter(it cog.Iterator[T])

RemoveIter remove all items in the iterator it

func (*LinkedList[T]) RetainAll added in v1.0.27

func (ll *LinkedList[T]) RetainAll(vs ...T)

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

func (*LinkedList[T]) RetainCol

func (ll *LinkedList[T]) RetainCol(ac cog.Collection[T])

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

func (*LinkedList[T]) RetainFunc

func (ll *LinkedList[T]) RetainFunc(f func(T) bool)

RetainFunc Retains all items that function f returns true

func (*LinkedList[T]) ReverseEach

func (ll *LinkedList[T]) ReverseEach(f func(int, T) bool)

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

func (*LinkedList[T]) Seq added in v1.0.27

func (ll *LinkedList[T]) Seq() iter.Seq[T]

Seq returns a iter.Seq[T] for range

func (*LinkedList[T]) Set

func (ll *LinkedList[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 (*LinkedList[T]) Sort

func (ll *LinkedList[T]) Sort(less cog.Less[T])

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

func (*LinkedList[T]) String

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

String print list to string

func (*LinkedList[T]) Swap

func (ll *LinkedList[T]) Swap(i, j int)

Swap swaps values of two items at the given index.

func (*LinkedList[T]) Tail

func (ll *LinkedList[T]) Tail() (v T)

Tail get the last item of list.

func (*LinkedList[T]) UnmarshalJSON

func (ll *LinkedList[T]) UnmarshalJSON(data []byte) error

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

func (*LinkedList[T]) Values

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

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

Jump to

Keyboard shortcuts

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