maps

package
v0.8.2 Latest Latest
Warning

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

Go to latest
Published: Jul 29, 2024 License: MIT Imports: 2 Imported by: 2

README

maps

Generic operations on maps, including map-based set operations.
Go does not have a set type but we can use maps to represent sets.

Documentation

Overview

Package maps provides generic operations on maps, including map-based set operations. Go does not have a set type but we can use maps to represent sets.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddAll

func AddAll[K comparable, V any](this map[K]V, value V, keys ...K)

AddAll adds multiple keys to this set, each with the same value.

func AnyOf added in v0.8.1

func AnyOf[K comparable, V any](this, other map[K]V) bool

AnyOf returns true if any key in this set is in the other set.

func Contains

func Contains[K comparable, V any](this map[K]V, key K) bool

Contains returns true if this set contains the given key.

func ContainsAll

func ContainsAll[K comparable, V any](this map[K]V, keys ...K) bool

ContainsAll returns true if this set contains every given key.

func ContainsAny

func ContainsAny[K comparable, V any](this map[K]V, keys ...K) bool

ContainsAny returns true if this set contains any given key.

func Difference

func Difference[K comparable, V any](this, other map[K]V) map[K]V

Difference returns a new set containing all keys in this set that don't exist in the other set.

func Discard

func Discard[K comparable, V any](this, other map[K]V)

Discard removes all keys from this set that exist in the other set.

func FromEntries added in v0.2.6

func FromEntries[K comparable, V any](src []Entry[K, V]) map[K]V

FromEntries creates a map from a slice of key/value tuples.

func Intersection

func Intersection[K comparable, V any](this, other map[K]V) map[K]V

Intersection returns a new set containing only keys that exist in both sets.

func Keys

func Keys[K comparable, V any](src map[K]V) []K

Keys returns a randomly-sorted slice of map keys.

func NewSet

func NewSet[K comparable](keys ...K) map[K]bool

NewSet creates a new set.

func NewSetWithValue added in v0.2.5

func NewSetWithValue[K comparable, V any](value V, keys ...K) map[K]V

NewSetWithValue creates a set with each key given the same value.

func RemoveAll

func RemoveAll[K comparable, V any](this map[K]V, keys ...K)

RemoveAll removes multiple keys from this set.

func SortedKeys

func SortedKeys[K cmp.Ordered, V any](src map[K]V) []K

SortedKeys returns a sorted slice of map keys.

func SortedValues

func SortedValues[K comparable, V cmp.Ordered](src map[K]V) []V

SortedValues returns a sorted slice of map values.

func SubsetOf

func SubsetOf[K comparable, V any](this, other map[K]V) bool

SubsetOf returns true if every key in this set is in the other set.

func Union

func Union[K comparable, V any](this, other map[K]V) map[K]V

Union returns a new set containing all keys from both sets.

func Update

func Update[K comparable, V any](this, other map[K]V)

Update adds every key from the other set to this set.

func Values

func Values[K comparable, V any](src map[K]V) []V

Values returns a randomly-sorted slice of map values.

Types

type Entry added in v0.2.6

type Entry[K comparable, V any] struct {
	Key K
	Val V
}

Entry is a key/value tuple representing a map entry.

func Entries added in v0.2.6

func Entries[K comparable, V any](src map[K]V) []Entry[K, V]

Entries returns a randomly-sorted slice of map entries.

func SortedEntries added in v0.2.6

func SortedEntries[K cmp.Ordered, V any](src map[K]V) []Entry[K, V]

SortedEntries returns a slice of map entries sorted by their keys.

Jump to

Keyboard shortcuts

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