loset

package
v1.19.3 Latest Latest
Warning

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

Go to latest
Published: Mar 8, 2023 License: LGPL-3.0 Imports: 1 Imported by: 0

Documentation

Overview

Package loset implements a linked ordered set which supports iteration in insertion order. It's also optimized for ordered traverse. loset is short for Linked Ordered Set.

Caution: This package is not goroutine-safe!

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Iterator

type Iterator[K constraints.Ordered] struct {
	// contains filtered or unexported fields
}

Iterator is used for iterating the LinkedOrderedSet.

func (*Iterator[K]) IsValid

func (it *Iterator[K]) IsValid() bool

IsValid returns true if the iterator is valid for use, false otherwise. We must not call Next, Key, or Value if IsValid returns false.

func (*Iterator[K]) Next

func (it *Iterator[K]) Next()

Next advances the iterator to the next element of the set

func (*Iterator[K]) Value

func (it *Iterator[K]) Value() K

Value returns the value of the underlying element

type LinkedIterator

type LinkedIterator[K constraints.Ordered] struct {
	// contains filtered or unexported fields
}

LinkedIterator is used for iterating the LinkedOrderedSet in insertion order.

func (*LinkedIterator[K]) IsValid

func (it *LinkedIterator[K]) IsValid() bool

IsValid returns true if the iterator is valid for use, false otherwise. We must not call Next, Key, or Value if IsValid returns false.

func (*LinkedIterator[K]) Next

func (it *LinkedIterator[K]) Next()

Next advances the iterator to the next element of the set in insertion order

func (*LinkedIterator[K]) Value

func (it *LinkedIterator[K]) Value() K

Value returns the value of the underlying element

type LinkedOrderedSet

type LinkedOrderedSet[K constraints.Ordered] struct {
	// contains filtered or unexported fields
}

LinkedOrderedSet is a linked ordered set which supports iteration in insertion order. It's also optimized for ordered traverse.

func New

New is the only way to get a new, ready-to-use LinkedOrderedSet object.

Example:

lom := New[int]()

func (*LinkedOrderedSet[K]) Clear

func (m *LinkedOrderedSet[K]) Clear()

Clear removes all elements from the set.

func (*LinkedOrderedSet[K]) Count

func (m *LinkedOrderedSet[K]) Count(value K) int

Count returns the number of elements with given `value`, which is either 1 or 0 since this container does not allow duplicates.

value: value of the elements to count

func (*LinkedOrderedSet[K]) Empty

func (m *LinkedOrderedSet[K]) Empty() bool

Empty returns true if the set does not contain any element, otherwise it returns false.

func (*LinkedOrderedSet[K]) Erase

func (m *LinkedOrderedSet[K]) Erase(value K)

Erase removes the element with the given value from the set.

func (*LinkedOrderedSet[K]) EraseByLinkedIterator

func (m *LinkedOrderedSet[K]) EraseByLinkedIterator(iter *LinkedIterator[K])

EraseByLinkedIterator erases the element specified by `iter`

func (*LinkedOrderedSet[K]) EraseFront

func (m *LinkedOrderedSet[K]) EraseFront()

EraseFront erases the front element

func (*LinkedOrderedSet[K]) FindLinkedIterator

func (m *LinkedOrderedSet[K]) FindLinkedIterator(value K) *LinkedIterator[K]

FindLinkedIterator returns a LinkedIterator to the given `value`. If found, LinkedIterator.IsValid() returns true, otherwise it returns false.

func (*LinkedOrderedSet[K]) Insert

func (m *LinkedOrderedSet[K]) Insert(value K) bool

Insert inserts a new element into the LinkedOrderedSet if it doesn't already exist. Nothing will be changed if the LinkedOrderedSet already contains an element with the specified value.

value: value to be inserted

Return value: true if the insertion takes place and false otherwise.

func (*LinkedOrderedSet[K]) Iterator

func (m *LinkedOrderedSet[K]) Iterator() *Iterator[K]

Iterator returns an iterator for iterating the LinkedOrderedSet.

func (*LinkedOrderedSet[K]) LinkedIterator

func (m *LinkedOrderedSet[K]) LinkedIterator() *LinkedIterator[K]

LinkedIterator returns an iterator for iterating the LinkedOrderedSet in insertion order.

func (*LinkedOrderedSet[K]) MoveToBack

func (m *LinkedOrderedSet[K]) MoveToBack(iter *LinkedIterator[K])

MoveToBack move the element specified by `iter` to the back of the linked list as if it is just inserted.

func (*LinkedOrderedSet[K]) ReverseIterator

func (m *LinkedOrderedSet[K]) ReverseIterator() *ReverseIterator[K]

ReverseIterator returns an iterator for iterating the LinkedOrderedSet in reverse order.

func (*LinkedOrderedSet[K]) ReverseLinkedIterator

func (m *LinkedOrderedSet[K]) ReverseLinkedIterator() *ReverseLinkedIterator[K]

ReverseLinkedIterator returns an iterator for iterating the LinkedOrderedSet in reverse insertion order.

func (*LinkedOrderedSet[K]) Size

func (m *LinkedOrderedSet[K]) Size() int

Size returns the number of elements in the set.

type ReverseIterator

type ReverseIterator[K constraints.Ordered] struct {
	// contains filtered or unexported fields
}

ReverseIterator is used for iterating the LinkedOrderedSet in reverse order.

func (*ReverseIterator[K]) IsValid

func (it *ReverseIterator[K]) IsValid() bool

IsValid returns true if the iterator is valid for use, false otherwise. We must not call Next, Key, or Value if IsValid returns false.

func (*ReverseIterator[K]) Next

func (it *ReverseIterator[K]) Next()

Next advances the iterator to the next element of the set in reverse order

func (*ReverseIterator[K]) Value

func (it *ReverseIterator[K]) Value() K

Value returns the value of the underlying element

type ReverseLinkedIterator

type ReverseLinkedIterator[K constraints.Ordered] struct {
	// contains filtered or unexported fields
}

ReverseLinkedIterator is used for iterating the LinkedOrderedSet in reverse insertion order.

func (*ReverseLinkedIterator[K]) IsValid

func (it *ReverseLinkedIterator[K]) IsValid() bool

IsValid returns true if the iterator is valid for use, false otherwise. We must not call Next, Key, or Value if IsValid returns false.

func (*ReverseLinkedIterator[K]) Next

func (it *ReverseLinkedIterator[K]) Next()

Next advances the iterator to the next element of the set in reverse insertion order

func (*ReverseLinkedIterator[K]) Value

func (it *ReverseLinkedIterator[K]) Value() K

Value returns the value of the underlying element

Jump to

Keyboard shortcuts

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