ds

package module
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Jun 4, 2025 License: MIT Imports: 1 Imported by: 0

Documentation

Overview

Package ds implements some basic data structures in Go.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Set

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

A Set represents a mathematical set.

The zero value for Set is usable, and represents an empty set. Sets might not work correctly with values which are not comparable in the ordinary way, such as floating point NaNs.

func (*Set[T]) All

func (s *Set[T]) All() iter.Seq[T]

All returns an iterator over the elements of s, in arbitrary order.

func (*Set[T]) Delete

func (s *Set[T]) Delete(t T)

Delete removes t from s.

func (*Set[T]) Empty

func (s *Set[T]) Empty() bool

Empty returns whether s is an empty set.

func (*Set[T]) Has

func (s *Set[T]) Has(t T) bool

Has returns whether s contains t.

func (*Set[T]) Insert

func (s *Set[T]) Insert(t T)

Insert adds t to s. If t is already in s, s does not change (we do add a second copy).

func (*Set[T]) Len

func (s *Set[T]) Len() int

Len returns the number of items in s.

type Stack

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

A Stack is a simple last-in-first-out collection of items.

func (Stack[T]) Empty

func (s Stack[T]) Empty() bool

Empty returns whether a Stack contains no values.

func (Stack[T]) Len

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

Len returns the number of values currently in a Stack.

func (*Stack[T]) Peek

func (s *Stack[T]) Peek() T

Peek returns the same value as Pop, but does not remove it from the Stack.

Peek panics when called on an empty Stack.

func (*Stack[T]) Pop

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

Pop removes the value that was most recently inserted into a Stack, and not yet returned by Pop.

It returns the value that was removed. Pop panics when called on an empty Stack.

func (*Stack[T]) Push

func (s *Stack[T]) Push(t T)

Push inserts a value into a Stack.

func (*Stack[T]) PushMany

func (s *Stack[T]) PushMany(ts ...T)

PushMany inserts several values into a stack.

The values are inserted in the order given, so they will be returned by Pop in the reverse order.

Jump to

Keyboard shortcuts

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