set

package module
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 15, 2022 License: MIT Imports: 2 Imported by: 1 module, 1 package

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

set

Library of generic set data structure for Go.

Install

$ go get github.com/golang-ds/set

Set Usage

Import
import "github.com/golang-ds/set"
Use
s := set.New[int]()
s.Add(1)

Documentation

Overview

Package set implements a generic set using a map as the underlying data structure.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Set

type Set[T comparable] struct {
	Data map[T]struct{}
}

func New

func New[T comparable]() Set[T]

New constructs and returns an empty set. time-complexity: O(1)

func (*Set[T]) Add

func (s *Set[T]) Add(val T)

Add adds a new elements to the set. time-complexity: O(1)

func (*Set[T]) Delete

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

Delete removes the val from the set. time-complexity: O(1)

func (*Set[T]) Has

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

Has returns true if the set has the given val. time-complexity: O(1)

func (*Set[T]) IsEmpty

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

IsEmpty returns true if the set doesn't contain any elements. time-complexity: O(1)

func (*Set[T]) Size

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

Size returns the number of the elements in the set. time-complexity: O(1)

func (*Set[T]) String

func (s *Set[T]) String() string

String returns the string representation of the set. time-complexity: O(n)

Jump to

Keyboard shortcuts

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