ch6ex4

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.4
// Refs:
:url-base: https://github.com/fenegroni/TGPL-exercise-solutions
:workflow: workflows/Exercise 6.4
:action: actions/workflows/ch6ex4.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}

Add a method `Elems` that returns a slice containing the elements of the set,
suitable for iterating over with a `range` loop.

Documentation

Index

Examples

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)

func (*IntSet) Elems

func (s *IntSet) Elems() (elems []int)

Elems returns a slice containing the elements of the set suitable for iterating over with a range loop

Example
v := new(IntSet)
v.AddAll(200, 3000, 1)
for _, e := range v.Elems() {
	fmt.Println(e)
}
Output:

1
200
3000

func (*IntSet) Len

func (s *IntSet) Len() int

Len returns the number of elements in 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