-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathreal_main.go
More file actions
37 lines (30 loc) · 773 Bytes
/
real_main.go
File metadata and controls
37 lines (30 loc) · 773 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package main
import (
"fmt"
"io"
"github.com/fgm/container"
"github.com/fgm/container/set"
)
type Element int
// SizeHint is an indication of the maximum number of elements expected in the
// set. It is not a hard limit. Implementations may use it or not.
const sizeHint = 100
func realMain(w io.Writer) int {
var e Element = 42
s := set.NewBasicMap[Element](sizeHint)
// Add squares.
for i := range e {
s.Add(i * i)
}
if cs, ok := s.(container.Countable); ok {
fmt.Fprintf(w, "elements in set: %d\n", cs.Len())
}
// Remove elements to show that we
// can also remove elements which are absent in the map.
for i := Element(0); i < 10; i++ {
del := i * i * i
ok := s.Remove(del)
fmt.Fprintf(w, "Element: %3v ok: %t\n", del, ok)
}
return 0
}