mapset

package
v0.7.3 Latest Latest
Warning

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

Go to latest
Published: Jun 24, 2022 License: MIT, MIT Imports: 0 Imported by: 0

README

mapset

import "github.com/fufuok/utils/generic/mapset"

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

Example

package main

import (
	"fmt"
	"github.com/fufuok/utils/generic/mapset"
)

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

	fmt.Println(set.Has("foo"))
	fmt.Println(set.Has("quux"))
}
Output
true
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 (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

Documentation

Overview

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

Example
package main

import (
	"fmt"

	"github.com/fufuok/utils/generic/mapset"
)

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

	fmt.Println(set.Has("foo"))
	fmt.Println(set.Has("quux"))
}
Output:

true
false

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Set

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

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

func New

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

New returns an empty hashset.

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.

Jump to

Keyboard shortcuts

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