ch6ex2

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Jul 5, 2022 License: GPL-3.0 Imports: 2 Imported by: 0

README

= Exercise 6.2
// Refs:
:url-base: https://github.com/fenegroni/TGPL-exercise-solutions
:workflow: workflows/Exercise 6.2
:action: actions/workflows/ch6ex2.yml
:url-workflow: {url-base}/{workflow}
:url-action: {url-base}/{action}
:badge-exercise: image:{url-workflow}/badge.svg?branch=main[link={url-action}]

{badge-exercise}

Define a variadic `(*IntSet).AddAll(...int)` method that allows a list of
values to be added, such as `s.AddAll(1, 2, 3)`.

== Tests

For this test, we leverage the `TestIntSet` function we made for exercise 6.1.
For that reason we keep the code for `Add`, `Remove`, `Clear` and `String`
as used by the test.

For this exercise we also define the equivalent `RemoveAll` method
that takes a list of values to remove from the set.

We can then call `AddAll` and `RemoveAll`
instead of calling `Add` and `Remove` in a loop
to add and remove more than one value.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type IntSet

type IntSet struct {
	// contains filtered or unexported fields
}

An IntSet is a set of small non-negative integers. Its zero value represents the empty set.

func (*IntSet) Add

func (s *IntSet) Add(x int)

Add the non-negative value x to the set

func (*IntSet) AddAll

func (s *IntSet) AddAll(xs ...int)

AddAll adds the non-negative values xs to the set

func (*IntSet) Clear

func (s *IntSet) Clear()

Clear removes all elements from the set

func (*IntSet) Remove

func (s *IntSet) Remove(x int)

Remove the non-negative value x from the set.

func (*IntSet) RemoveAll

func (s *IntSet) RemoveAll(xs ...int)

RemoveAll removes all the non-negative values xs from the set

func (*IntSet) String

func (s *IntSet) String() string

String returns the set as a string of the form "{1 2 3}"

Jump to

Keyboard shortcuts

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