linkedhashset

package
v1.0.26 Latest Latest
Warning

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

Go to latest
Published: Sep 20, 2024 License: MIT Imports: 7 Imported by: 1

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type LinkedHashSet

type LinkedHashSet[T comparable] struct {
	// contains filtered or unexported fields
}

LinkedHashSet implements a doubly linked set. The zero value for LinkedHashSet is an empty set ready to use. Note that insertion order is not affected if an element is re-inserted into the set. (An element e is reinserted into a set s if s.Add(e) is invoked when s.Contains(e) would return true immediately prior to the invocation.)

To iterate over a set (where ls is a *LinkedHashSet):

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

func NewLinkedHashSet

func NewLinkedHashSet[T comparable](vs ...T) *LinkedHashSet[T]

NewLinkedHashSet returns an initialized set. Example: cog.NewLinkedHashSet(1, 2, 3)

Example
set := NewLinkedHashSet[int]()
set.Add(5)              // 5
set.Adds(4, 4, 3, 2, 1) // 5, 4, 3, 2, 1 (in insertion-order, duplicates ignored)
set.Add(4)              // 5, 4, 3, 2, 1 (duplicates ignored, insertion-order unchanged)
set.Remove(4)           // 5, 3, 2, 1 (in insertion-order)
set.Removes(2, 3)       // 5, 1 (in insertion-order)
set.Contains(1)         // true
set.Contains(1, 5)      // true
set.Contains(1, 6)      // false
_ = set.Values()        // []int{5, 1} (in insertion-order)
set.Clear()             // empty
set.IsEmpty()           // true
set.Len()               // 0

func (*LinkedHashSet[T]) Add

func (ls *LinkedHashSet[T]) Add(v T)

Add add the item v. Note: existing item's order will not change.

func (*LinkedHashSet[T]) AddCol

func (ls *LinkedHashSet[T]) AddCol(ac cog.Collection[T])

AddCol adds all items of another collection Note: existing item's order will not change.

func (*LinkedHashSet[T]) Adds

func (ls *LinkedHashSet[T]) Adds(vs ...T)

Adds adds all items of vs. Note: existing item's order will not change.

func (*LinkedHashSet[T]) Clear

func (ls *LinkedHashSet[T]) Clear()

Clear clears set ls.

func (*LinkedHashSet[T]) Contain

func (ls *LinkedHashSet[T]) Contain(v T) bool

Contain Test to see if the list contains the value v

func (*LinkedHashSet[T]) ContainCol

func (ls *LinkedHashSet[T]) ContainCol(ac cog.Collection[T]) bool

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

func (*LinkedHashSet[T]) ContainIter

func (ls *LinkedHashSet[T]) ContainIter(it cog.Iterator[T]) bool

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

func (*LinkedHashSet[T]) Contains

func (ls *LinkedHashSet[T]) Contains(vs ...T) bool

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

func (*LinkedHashSet[T]) DeleteAt

func (ls *LinkedHashSet[T]) DeleteAt(index int)

DeleteAt removes the element at the specified position in this set.

func (*LinkedHashSet[T]) Each

func (ls *LinkedHashSet[T]) Each(f func(int, T) bool)

Each call f for each item in the set

func (*LinkedHashSet[T]) Get

func (ls *LinkedHashSet[T]) Get(index int) T

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

func (*LinkedHashSet[T]) Head

func (ls *LinkedHashSet[T]) Head() (v T)

Head get the first item of set.

func (*LinkedHashSet[T]) Index

func (ls *LinkedHashSet[T]) Index(v T) int

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

func (*LinkedHashSet[T]) Insert

func (ls *LinkedHashSet[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 set's size Note: position equal to set's size is valid, i.e. append. Note: existing item's order will not change.

func (*LinkedHashSet[T]) InsertCol

func (ls *LinkedHashSet[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. Note: existing item's order will not change.

func (*LinkedHashSet[T]) Inserts

func (ls *LinkedHashSet[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 set's size Note: position equal to set's size is valid, i.e. append. Note: existing item's order will not change.

func (*LinkedHashSet[T]) IsEmpty

func (ls *LinkedHashSet[T]) IsEmpty() bool

IsEmpty returns true if the set length == 0

func (*LinkedHashSet[T]) Iterator

func (ls *LinkedHashSet[T]) Iterator() cog.Iterator[T]

Iterator returns a iterator for the set

func (*LinkedHashSet[T]) Len

func (ls *LinkedHashSet[T]) Len() int

Len returns the length of the set.

func (*LinkedHashSet[T]) MarshalJSON

func (ls *LinkedHashSet[T]) MarshalJSON() ([]byte, error)

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

func (*LinkedHashSet[T]) Peek

func (ls *LinkedHashSet[T]) Peek() (v T, ok bool)

Peek get the first item of set.

func (*LinkedHashSet[T]) PeekHead

func (ls *LinkedHashSet[T]) PeekHead() (v T, ok bool)

PeekHead get the first item of set.

func (*LinkedHashSet[T]) PeekTail

func (ls *LinkedHashSet[T]) PeekTail() (v T, ok bool)

PeekTail get the last item of set.

func (*LinkedHashSet[T]) Poll

func (ls *LinkedHashSet[T]) Poll() (T, bool)

Poll get and remove the first item of set.

func (*LinkedHashSet[T]) PollHead

func (ls *LinkedHashSet[T]) PollHead() (v T, ok bool)

PollHead remove the first item of set.

func (*LinkedHashSet[T]) PollTail

func (ls *LinkedHashSet[T]) PollTail() (v T, ok bool)

PollTail remove the last item of set.

func (*LinkedHashSet[T]) Push

func (ls *LinkedHashSet[T]) Push(v T)

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

func (*LinkedHashSet[T]) PushHead

func (ls *LinkedHashSet[T]) PushHead(v T)

PushHead insert the item v at the head of set ls.

func (*LinkedHashSet[T]) PushHeadCol

func (ls *LinkedHashSet[T]) PushHeadCol(ac cog.Collection[T])

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

func (*LinkedHashSet[T]) PushHeads

func (ls *LinkedHashSet[T]) PushHeads(vs ...T)

PushHeads inserts all items of vs at the head of set ls.

func (*LinkedHashSet[T]) PushTail

func (ls *LinkedHashSet[T]) PushTail(v T)

PushTail insert the item v at the tail of set ls.

func (*LinkedHashSet[T]) PushTailCol

func (ls *LinkedHashSet[T]) PushTailCol(ac cog.Collection[T])

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

func (*LinkedHashSet[T]) PushTails

func (ls *LinkedHashSet[T]) PushTails(vs ...T)

PushTails inserts all items of vs at the tail of set ls.

func (*LinkedHashSet[T]) Pushs

func (ls *LinkedHashSet[T]) Pushs(vs ...T)

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

func (*LinkedHashSet[T]) Remove

func (ls *LinkedHashSet[T]) Remove(v T)

Remove remove all items with associated value v

func (*LinkedHashSet[T]) RemoveCol

func (ls *LinkedHashSet[T]) RemoveCol(ac cog.Collection[T])

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

func (*LinkedHashSet[T]) RemoveFunc

func (ls *LinkedHashSet[T]) RemoveFunc(f func(T) bool)

RemoveFunc remove all items that function f returns true

func (*LinkedHashSet[T]) RemoveIter

func (ls *LinkedHashSet[T]) RemoveIter(it cog.Iterator[T])

RemoveIter remove all items in the iterator it

func (*LinkedHashSet[T]) Removes

func (ls *LinkedHashSet[T]) Removes(vs ...T)

Removes remove all items in the array vs

func (*LinkedHashSet[T]) RetainCol

func (ls *LinkedHashSet[T]) RetainCol(ac cog.Collection[T])

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

func (*LinkedHashSet[T]) RetainFunc

func (ls *LinkedHashSet[T]) RetainFunc(f func(T) bool)

RetainFunc Retains all items that function f returns true

func (*LinkedHashSet[T]) Retains

func (ls *LinkedHashSet[T]) Retains(vs ...T)

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

func (*LinkedHashSet[T]) ReverseEach

func (ls *LinkedHashSet[T]) ReverseEach(f func(int, T) bool)

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

func (*LinkedHashSet[T]) Set

func (ls *LinkedHashSet[T]) Set(index int, v T) (ov T)

Set set the v at the specified index in this set and returns the old value. Old item at index will be removed.

func (*LinkedHashSet[T]) Sort

func (ls *LinkedHashSet[T]) Sort(less cog.Less[T])

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

func (*LinkedHashSet[T]) String

func (ls *LinkedHashSet[T]) String() string

String print list to string

func (*LinkedHashSet[T]) Swap

func (ls *LinkedHashSet[T]) Swap(i, j int)

Swap swaps values of two items at the given index.

func (*LinkedHashSet[T]) Tail

func (ls *LinkedHashSet[T]) Tail() (v T)

Tail get the last item of set.

func (*LinkedHashSet[T]) UnmarshalJSON

func (ls *LinkedHashSet[T]) UnmarshalJSON(data []byte) error

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

func (*LinkedHashSet[T]) Values

func (ls *LinkedHashSet[T]) Values() []T

Values returns a slice contains all the items of the set ls

Jump to

Keyboard shortcuts

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