March 2020
Intermediate to advanced
406 pages
8h 39m
English
Multisets are unordered sets with a count associated with each element. There are lots of convenient bits of manipulation that can be used with multisets, such as taking the difference, scaling the set, or checking the cardinality of a set.
In our example, we build a multiset x, scale it by 2 as a multiset y, validate that x is a subset of y, and check the cardinality of x. We can see an example implementation of a multiset in the following code:
package mainimport ( "fmt" "github.com/soniakeys/multiset")func main() { x := multiset.Multiset{"foo": 1, "bar": 2, "baz": 3} fmt.Println("x: ", x) // Create a scaled version of x y := multiset.Scale(x, 2) fmt.Println("y: ", y) fmt.Print("x is a subset of y: ") fmt.Println(multiset.Subset(x, ...Read now
Unlock full access