Skip to content

Latest commit

 

History

History

mapset

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 

mapset

import "github.com/zyedidia/generic/mapset"

Package mapset provides an implementation of a set using the built-in map.

Example

package main

import (
	"fmt"

	"github.com/zyedidia/generic/mapset"
)

func main() {
	set := mapset.New[string]()
	set.Put("foo")
	set.Put("bar")
	set.Put("baz")

	fmt.Println("foo", set.Has("foo"))
	fmt.Println("quux", set.Has("quux"))

	set.Remove("foo")
	fmt.Println("foo", set.Has("foo"))
	fmt.Println("bar", set.Has("bar"))

	set.Clear()
	fmt.Println("foo", set.Has("foo"))
	fmt.Println("bar", set.Has("bar"))
}

Output

foo true
quux false
foo false
bar true
foo false
bar false

Index

type Set

Set implements a hashset, using the hashmap as the underlying storage.

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

func New

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

New returns an empty hashset.

func Of

func Of[K comparable](vals ...K) Set[K]

Of returns a new hashset initialized with the given 'vals'

func (Set[K]) Clear

func (s Set[K]) Clear()

Clear removes all elements from the set.

func (Set[K]) Each

func (s Set[K]) Each(fn func(key K))

Each calls 'fn' on every item in the set in no particular order.

func (Set[K]) Has

func (s Set[K]) Has(val K) bool

Has returns true only if 'val' is in the set.

func (Set[K]) Put

func (s Set[K]) Put(val K)

Put adds 'val' to the set.

func (Set[K]) Remove

func (s Set[K]) Remove(val K)

Remove removes 'val' from the set.

func (Set[K]) Size

func (s Set[K]) Size() int

Size returns the number of elements in the set.

Generated by gomarkdoc