collections

package module
v0.0.0-...-908a7d2 Latest Latest
Warning

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

Go to latest
Published: Feb 22, 2023 License: Apache-2.0 Imports: 3 Imported by: 0

README

go-collections

GitHub Workflow Status Go Report Card

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Comparator

type Comparator[E any] func(a, b E) int

Comparator is a function that returns a value indicating whether the first argument is less than, greater than, or equal to the second argument. If the returned value is less than zero, the first argument is less than the second If the returned value is greater than zero, the first argument is greater than the second If the returned value is zero, the first argument is equal to the second

type PriorityQueue

type PriorityQueue[E any] struct {
	// contains filtered or unexported fields
}

PriorityQueue is an ordered collection of elements. Elements can be pushed and popped from a PriorityQueue; when popping, elements come out in an order determined by the provided comparator. Elements that compare as "less" than others come out first

func MakePriorityQueue

func MakePriorityQueue[E any](c Comparator[E], initialElements ...E) *PriorityQueue[E]

func (PriorityQueue[E]) Len

func (pq PriorityQueue[E]) Len() int

func (*PriorityQueue[E]) Pop

func (pq *PriorityQueue[E]) Pop() E

func (*PriorityQueue[E]) Push

func (pq *PriorityQueue[E]) Push(e E)

type Queue

type Queue[E any] struct {
	// contains filtered or unexported fields
}

func MakeQueue

func MakeQueue[E any]() *Queue[E]

func (Queue[E]) Len

func (q Queue[E]) Len() int

func (*Queue[E]) Pop

func (q *Queue[E]) Pop() E

func (*Queue[E]) Push

func (q *Queue[E]) Push(e E)

type Set

type Set[E comparable] struct {
	// contains filtered or unexported fields
}

Set represents a unique set of elements. It has constant-time insert and contains operations

func MakeSet

func MakeSet[E comparable](initialElements ...E) *Set[E]

MakeSet returns a Set containing the given initial elements

func (Set[E]) Contains

func (s Set[E]) Contains(element E) bool

Contains returns true if the given element is in the set, false otherwise

func (*Set[E]) Insert

func (s *Set[E]) Insert(element E) bool

Insert inserts the given element into the set. It returns true if the element was not previously in the set, false otherwise

func (Set[E]) Len

func (s Set[E]) Len() int

func (Set[E]) Remove

func (s Set[E]) Remove(element E) bool

Remove removes the given element from the set, if present. It returns true if the element was found in the set, false otherwise

func (Set[E]) String

func (s Set[E]) String() string

func (Set[E]) ToSlice

func (s Set[E]) ToSlice() []E

ToSlice returns a slice containing shallow copies of each element in the set. Element order is not defined

type Stack

type Stack[E any] struct {
	// contains filtered or unexported fields
}

func MakeStack

func MakeStack[E any]() *Stack[E]

func (Stack[E]) Len

func (s Stack[E]) Len() int

func (*Stack[E]) Pop

func (s *Stack[E]) Pop() E

func (*Stack[E]) Push

func (s *Stack[E]) Push(e E)

Jump to

Keyboard shortcuts

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