package main
import (
"fmt"
"packs/genset"
)
type String struct {
val string
}
func (x String) Cmp(c genset.Comparable) int {
s := c.(String)
if x.val < s.val {
return -1
} else if x.val > s.val {
return 1
} else {
return 0
}
}
func main() {
// Some tests with printed results.
var ss genset.GenSet
// Insert some strings, then print the set.
somestr := [10]string{"bill","fred","frank","alice","ron",
"evan","bill","sally","timmy","kermit"}
for _,s := range(somestr[0:8]) {
fmt.Printf("Add %s: %t\n", s, ss.Add(String{s}))
}
fmt.Println(ss.Contents())
// Check the contains.
for _,s := range(somestr) {
fmt.Printf("Contains %s: %t\n", s, ss.Contains(String{s}))
}
// Delete some and print again.
fmt.Printf("Remove norbert: %t\n", ss.Remove(String{"norbert"}))
for _,s := range(somestr[2:10]) {
fmt.Printf("Remove %s: %t\n", s, ss.Remove(String{s}))
}
fmt.Printf("Add ellen: %t\n", ss.Add(String{"ellen"}))
fmt.Println(ss.Contents())
for _,s := range(somestr) {
fmt.Printf("Contains %s: %t\n", s, ss.Contains(String{s}))
}
}