WIP: rebase fork onto upstream/main (v1.103.0) #15

Closed
codinget wants to merge 670 commits from webnet into save/webnet-2026-07-29
2 changed files with 30 additions and 0 deletions
Showing only changes of commit d0b4d44963 - Show all commits
+16
View File
@@ -10,6 +10,8 @@ import (
"maps"
"reflect"
"sort"
"tailscale.com/types/views"
)
// Set is a set of T.
@@ -27,6 +29,13 @@ func Of[T comparable](slice ...T) Set[T] {
return s
}
// OfSliceView returns a new set constructed from the elements in v.
func OfSliceView[T comparable](v views.Slice[T]) Set[T] {
s := make(Set[T], v.Len())
s.AddSliceView(v)
return s
}
// Clone returns a new set cloned from the elements in s.
func (s Set[T]) Clone() Set[T] {
return maps.Clone(s)
@@ -56,6 +65,13 @@ func (s Set[T]) AddSlice(es []T) {
}
}
// AddSliceView adds each element of v to s.
func (s Set[T]) AddSliceView(v views.Slice[T]) {
for _, e := range v.All() {
s.Add(e)
}
}
// AddSet adds each element of es to s.
func (s Set[T]) AddSet(es Set[T]) {
for e := range es {
+14
View File
@@ -7,6 +7,8 @@ import (
"encoding/json"
"slices"
"testing"
"tailscale.com/types/views"
)
func TestSet(t *testing.T) {
@@ -98,6 +100,18 @@ func TestSetOf(t *testing.T) {
}
}
func TestOfSliceView(t *testing.T) {
s := OfSliceView(views.SliceOf([]int{1, 2, 3, 4, 4, 1}))
if s.Len() != 4 {
t.Errorf("wrong len %d; want 4", s.Len())
}
for _, n := range []int{1, 2, 3, 4} {
if !s.Contains(n) {
t.Errorf("should contain %d", n)
}
}
}
func TestEqual(t *testing.T) {
type test struct {
name string