set

package
v0.5.1 Latest Latest
Warning

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

Go to latest
Published: Feb 20, 2025 License: Apache-2.0 Imports: 0 Imported by: 0

README

The deriveSet function is useful for creating a set of basic types which are comparable as a key in map.

Given the following input:

package set

func subset(set, sub []int) bool {
	s := deriveSet(set)
	for _, k := range sub {
		if _, ok := s[k]; !ok {
			return false
		}
	}
	return true
}

goderive will generate the following code:

// Code generated by goderive DO NOT EDIT.

package set

// deriveSet returns the input list as a map with the items of the list as the keys of the map.
//
// Deprecated: In favour of generics.
func deriveSet(list []int) map[int]struct{} {
	set := make(map[int]struct{}, len(list))
	for _, v := range list {
		set[v] = struct{}{}
	}
	return set
}

Documentation

The Go Gopher

There is no documentation for this package.

Jump to

Keyboard shortcuts

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