set

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Feb 22, 2024 License: MIT Imports: 0 Imported by: 0

Documentation

Overview

Package set is a set container package.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Set

type Set[E comparable] interface {
	// Add adds an element.
	Add(elem E)
	// AddAll adds all elememts.
	AddAll(elems ...E)
	// Remove removes the specific element.
	Remove(elem E)
	// RemoveAll removes all the specific elements.
	RemoveAll(elems ...E)
	// Size returns the size of the set.
	Size() int
	// Contains checks whether the element is in the set.
	Contains(elem E) bool
	// Empty checks whether the set is empty.
	Empty() bool
	// Values returns all elements list of the set.
	Values() []E
	// Clear clears the set.
	Clear()
}

Set is interface for set container.

Example
s := New(1, 2)
s.Add(3)
s.Remove(2)
fmt.Println("Contains 1:", s.Contains(1))
fmt.Println("Contains 2:", s.Contains(2))
fmt.Println("Empty:", s.Empty())
Output:

Contains 1: true
Contains 2: false
Empty: false

func New

func New[E comparable](elems ...E) Set[E]

New returns a new set container.

Jump to

Keyboard shortcuts

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