| 1 | // Copyright 2014 The Go Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style |
| 3 | // license that can be found in the LICENSE file. |
| 4 | |
| 5 | package intsets_testscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets_test`/ |
| 6 | |
| 7 | import ( |
| 8 | "fmtscip-go gomod github.com/golang/go/src go1.25.0 fmt/" |
| 9 | "logscip-go gomod github.com/golang/go/src go1.25.0 log/" |
| 10 | "math/randscip-go gomod github.com/golang/go/src go1.25.0 `math/rand`/" |
| 11 | "sortscip-go gomod github.com/golang/go/src go1.25.0 sort/" |
| 12 | "stringsscip-go gomod github.com/golang/go/src go1.25.0 strings/" |
| 13 | "testingscip-go gomod github.com/golang/go/src go1.25.0 testing/" |
| 14 | |
| 15 | "golang.org/x/tools/container/intsetsscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets`/" |
| 16 | ) |
| 17 | |
| 18 | func TestBasicsscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets_test`/TestBasics().(t *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Tscip-go gomod github.com/golang/go/src go1.25.0 testing/T#) { |
| 19 | var s intsetsscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets`/.Sparsescip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets`/Sparse# |
| 20 | if len := s.Lenscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets`/Sparse#Len().(); len != 0 { |
| 21 | t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("Len({}): got %d, want 0", len) |
| 22 | } |
| 23 | if s := s.Stringscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets`/Sparse#String().(); s != "{}" { |
| 24 | t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("String({}): got %q, want \"{}\"", s) |
| 25 | } |
| 26 | if s.Hasscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets`/Sparse#Has().(3) { |
| 27 | t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("Has(3): got true, want false") |
| 28 | } |
| 29 | if err := s.Checkscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets`/Sparse#Check().(); err != nil { |
| 30 | t.Errorscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Error().(err) |
| 31 | } |
| 32 | |
| 33 | if !s.Insertscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets`/Sparse#Insert().(3) { |
| 34 | t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("Insert(3): got false, want true") |
| 35 | } |
| 36 | if max := s.Maxscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets`/Sparse#Max().(); max != 3 { |
| 37 | t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("Max: got %d, want 3", max) |
| 38 | } |
| 39 | |
| 40 | if !s.Insertscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets`/Sparse#Insert().(435) { |
| 41 | t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("Insert(435): got false, want true") |
| 42 | } |
| 43 | if s := s.Stringscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets`/Sparse#String().(); s != "{3 435}" { |
| 44 | t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("String({3 435}): got %q, want \"{3 435}\"", s) |
| 45 | } |
| 46 | if max := s.Maxscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets`/Sparse#Max().(); max != 435 { |
| 47 | t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("Max: got %d, want 435", max) |
| 48 | } |
| 49 | if len := s.Lenscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets`/Sparse#Len().(); len != 2 { |
| 50 | t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("Len: got %d, want 2", len) |
| 51 | } |
| 52 | |
| 53 | if !s.Removescip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets`/Sparse#Remove().(435) { |
| 54 | t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("Remove(435): got false, want true") |
| 55 | } |
| 56 | if s := s.Stringscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets`/Sparse#String().(); s != "{3}" { |
| 57 | t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("String({3}): got %q, want \"{3}\"", s) |
| 58 | } |
| 59 | } |
| 60 | |
| 61 | // Insert, Len, IsEmpty, Hash, Clear, AppendTo. |
| 62 | func TestMoreBasicsscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets_test`/TestMoreBasics().(t *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Tscip-go gomod github.com/golang/go/src go1.25.0 testing/T#) { |
| 63 | set := new(intsetsscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets`/.Sparsescip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets`/Sparse#) |
| 64 | set.Insertscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets`/Sparse#Insert().(456) |
| 65 | set.Insertscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets`/Sparse#Insert().(123) |
| 66 | set.Insertscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets`/Sparse#Insert().(789) |
| 67 | if set.Lenscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets`/Sparse#Len().() != 3 { |
| 68 | t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("%s.Len: got %d, want 3", set, set.Lenscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets`/Sparse#Len().()) |
| 69 | } |
| 70 | if set.IsEmptyscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets`/Sparse#IsEmpty().() { |
| 71 | t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("%s.IsEmpty: got true", set) |
| 72 | } |
| 73 | if !set.Hasscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets`/Sparse#Has().(123) { |
| 74 | t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("%s.Has(123): got false", set) |
| 75 | } |
| 76 | if set.Hasscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets`/Sparse#Has().(1234) { |
| 77 | t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("%s.Has(1234): got true", set) |
| 78 | } |
| 79 | got := set.AppendToscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets`/Sparse#AppendTo().([]int{-1}) |
| 80 | if want := []int{-1, 123, 456, 789}; fmtscip-go gomod github.com/golang/go/src go1.25.0 fmt/.Sprintscip-go gomod github.com/golang/go/src go1.25.0 fmt/Sprint().(got) != fmtscip-go gomod github.com/golang/go/src go1.25.0 fmt/.Sprintscip-go gomod github.com/golang/go/src go1.25.0 fmt/Sprint().(want) { |
| 81 | t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("%s.AppendTo: got %v, want %v", set, got, want) |
| 82 | } |
| 83 | |
| 84 | set.Clearscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets`/Sparse#Clear().() |
| 85 | |
| 86 | if set.Lenscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets`/Sparse#Len().() != 0 { |
| 87 | t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("Clear: got %d, want 0", set.Lenscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets`/Sparse#Len().()) |
| 88 | } |
| 89 | if !set.IsEmptyscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets`/Sparse#IsEmpty().() { |
| 90 | t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("IsEmpty: got false") |
| 91 | } |
| 92 | if set.Hasscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets`/Sparse#Has().(123) { |
| 93 | t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("%s.Has: got false", set) |
| 94 | } |
| 95 | } |
| 96 | |
| 97 | func TestTakeMinscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets_test`/TestTakeMin().(t *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Tscip-go gomod github.com/golang/go/src go1.25.0 testing/T#) { |
| 98 | var set intsetsscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets`/.Sparsescip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets`/Sparse# |
| 99 | set.Insertscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets`/Sparse#Insert().(456) |
| 100 | set.Insertscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets`/Sparse#Insert().(123) |
| 101 | set.Insertscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets`/Sparse#Insert().(789) |
| 102 | set.Insertscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets`/Sparse#Insert().(-123) |
| 103 | var got int |
| 104 | for i, want := range []int{-123, 123, 456, 789} { |
| 105 | if !set.TakeMinscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets`/Sparse#TakeMin().(&got) || got != want { |
| 106 | t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("TakeMin #%d: got %d, want %d", i, got, want) |
| 107 | } |
| 108 | } |
| 109 | if set.TakeMinscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets`/Sparse#TakeMin().(&got) { |
| 110 | t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("%s.TakeMin returned true", &set) |
| 111 | } |
| 112 | if err := set.Checkscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets`/Sparse#Check().(); err != nil { |
| 113 | t.Fatalfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatalf().("check: %s: %#v", err, &set) |
| 114 | } |
| 115 | } |
| 116 | |
| 117 | func TestMinAndMaxscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets_test`/TestMinAndMax().(t *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Tscip-go gomod github.com/golang/go/src go1.25.0 testing/T#) { |
| 118 | values := []int{0, 456, 123, 789, -123} // elt 0 => empty set |
| 119 | wantMax := []int{intsetsscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets`/.MinIntscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets`/MinInt., 456, 456, 789, 789} |
| 120 | wantMin := []int{intsetsscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets`/.MaxIntscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets`/MaxInt., 456, 123, 123, -123} |
| 121 | |
| 122 | var set intsetsscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets`/.Sparsescip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets`/Sparse# |
| 123 | for i, x := range values { |
| 124 | if i != 0 { |
| 125 | set.Insertscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets`/Sparse#Insert().(x) |
| 126 | } |
| 127 | if got, want := set.Minscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets`/Sparse#Min().(), wantMin[i]; got != want { |
| 128 | t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("Min #%d: got %d, want %d", i, got, want) |
| 129 | } |
| 130 | if got, want := set.Maxscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets`/Sparse#Max().(), wantMax[i]; got != want { |
| 131 | t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("Max #%d: got %d, want %d", i, got, want) |
| 132 | } |
| 133 | } |
| 134 | |
| 135 | set.Insertscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets`/Sparse#Insert().(intsetsscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets`/.MinIntscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets`/MinInt.) |
| 136 | if got, want := set.Minscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets`/Sparse#Min().(), intsetsscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets`/.MinIntscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets`/MinInt.; got != want { |
| 137 | t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("Min: got %d, want %d", got, want) |
| 138 | } |
| 139 | |
| 140 | set.Insertscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets`/Sparse#Insert().(intsetsscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets`/.MaxIntscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets`/MaxInt.) |
| 141 | if got, want := set.Maxscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets`/Sparse#Max().(), intsetsscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets`/.MaxIntscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets`/MaxInt.; got != want { |
| 142 | t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("Max: got %d, want %d", got, want) |
| 143 | } |
| 144 | } |
| 145 | |
| 146 | func TestEqualsscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets_test`/TestEquals().(t *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Tscip-go gomod github.com/golang/go/src go1.25.0 testing/T#) { |
| 147 | var setX intsetsscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets`/.Sparsescip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets`/Sparse# |
| 148 | setX.Insertscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets`/Sparse#Insert().(456) |
| 149 | setX.Insertscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets`/Sparse#Insert().(123) |
| 150 | setX.Insertscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets`/Sparse#Insert().(789) |
| 151 | |
| 152 | if !setX.Equalsscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets`/Sparse#Equals().(&setX) { |
| 153 | t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("Equals(%s, %s): got false", &setX, &setX) |
| 154 | } |
| 155 | |
| 156 | var setY intsetsscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets`/.Sparsescip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets`/Sparse# |
| 157 | setY.Insertscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets`/Sparse#Insert().(789) |
| 158 | setY.Insertscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets`/Sparse#Insert().(456) |
| 159 | setY.Insertscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets`/Sparse#Insert().(123) |
| 160 | |
| 161 | if !setX.Equalsscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets`/Sparse#Equals().(&setY) { |
| 162 | t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("Equals(%s, %s): got false", &setX, &setY) |
| 163 | } |
| 164 | |
| 165 | setY.Insertscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets`/Sparse#Insert().(1) |
| 166 | if setX.Equalsscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets`/Sparse#Equals().(&setY) { |
| 167 | t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("Equals(%s, %s): got true", &setX, &setY) |
| 168 | } |
| 169 | |
| 170 | var empty intsetsscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets`/.Sparsescip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets`/Sparse# |
| 171 | if setX.Equalsscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets`/Sparse#Equals().(&empty) { |
| 172 | t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("Equals(%s, %s): got true", &setX, &empty) |
| 173 | } |
| 174 | |
| 175 | // Edge case: some block (with offset=0) appears in X but not Y. |
| 176 | setY.Removescip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets`/Sparse#Remove().(123) |
| 177 | if setX.Equalsscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets`/Sparse#Equals().(&setY) { |
| 178 | t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("Equals(%s, %s): got true", &setX, &setY) |
| 179 | } |
| 180 | } |
| 181 | |
| 182 | // A pset is a parallel implementation of a set using both an intsets.Sparse |
| 183 | // and a built-in hash map. |
| 184 | type psetscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets_test`/pset# struct { |
| 185 | hashscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets_test`/pset#hash. map[int]bool |
| 186 | bitsscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets_test`/pset#bits. intsetsscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets`/.Sparsescip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets`/Sparse# |
| 187 | } |
| 188 | |
| 189 | func makePsetscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets_test`/makePset().() *psetscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets_test`/pset# { |
| 190 | return &psetscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets_test`/pset#{hashscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets_test`/pset#hash.: make(map[int]bool)} |
| 191 | } |
| 192 | |
| 193 | func (set *psetscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets_test`/pset#) addscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets_test`/pset#add().(n int) { |
| 194 | prev := len(set.hashscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets_test`/pset#hash.) |
| 195 | set.hashscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets_test`/pset#hash.[n] = true |
| 196 | grewA := len(set.hashscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets_test`/pset#hash.) > prev |
| 197 | |
| 198 | grewB := set.bitsscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets_test`/pset#bits..Insertscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets`/Sparse#Insert().(n) |
| 199 | |
| 200 | if grewA != grewB { |
| 201 | panic(fmtscip-go gomod github.com/golang/go/src go1.25.0 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.25.0 fmt/Sprintf().("add(%d): grewA=%t grewB=%t", n, grewA, grewB)) |
| 202 | } |
| 203 | } |
| 204 | |
| 205 | func (set *psetscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets_test`/pset#) removescip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets_test`/pset#remove().(n int) { |
| 206 | prev := len(set.hashscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets_test`/pset#hash.) |
| 207 | delete(set.hashscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets_test`/pset#hash., n) |
| 208 | shrankA := len(set.hashscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets_test`/pset#hash.) < prev |
| 209 | |
| 210 | shrankB := set.bitsscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets_test`/pset#bits..Removescip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets`/Sparse#Remove().(n) |
| 211 | |
| 212 | if shrankA != shrankB { |
| 213 | panic(fmtscip-go gomod github.com/golang/go/src go1.25.0 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.25.0 fmt/Sprintf().("remove(%d): shrankA=%t shrankB=%t", n, shrankA, shrankB)) |
| 214 | } |
| 215 | } |
| 216 | |
| 217 | func (set *psetscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets_test`/pset#) checkscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets_test`/pset#check().(t *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Tscip-go gomod github.com/golang/go/src go1.25.0 testing/T#, msg string) { |
| 218 | var eltsA []int |
| 219 | for elt := range set.hashscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets_test`/pset#hash. { |
| 220 | eltsA = append(eltsA, int(elt)) |
| 221 | } |
| 222 | sortscip-go gomod github.com/golang/go/src go1.25.0 sort/.Intsscip-go gomod github.com/golang/go/src go1.25.0 sort/Ints().(eltsA) |
| 223 | |
| 224 | eltsB := set.bitsscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets_test`/pset#bits..AppendToscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets`/Sparse#AppendTo().(nil) |
| 225 | |
| 226 | if a, b := fmtscip-go gomod github.com/golang/go/src go1.25.0 fmt/.Sprintscip-go gomod github.com/golang/go/src go1.25.0 fmt/Sprint().(eltsA), fmtscip-go gomod github.com/golang/go/src go1.25.0 fmt/.Sprintscip-go gomod github.com/golang/go/src go1.25.0 fmt/Sprint().(eltsB); a != b { |
| 227 | t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("check(%s): hash=%s bits=%s (%s)", msg, a, b, &set.bitsscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets_test`/pset#bits.) |
| 228 | } |
| 229 | |
| 230 | if err := set.bitsscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets_test`/pset#bits..Checkscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets`/Sparse#Check().(); err != nil { |
| 231 | t.Fatalfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatalf().("Check(%s): %s: %#v", msg, err, &set.bitsscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets_test`/pset#bits.) |
| 232 | } |
| 233 | } |
| 234 | |
| 235 | // randomPset returns a parallel set of random size and elements. |
| 236 | func randomPsetscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets_test`/randomPset().(prng *randscip-go gomod github.com/golang/go/src go1.25.0 `math/rand`/.Randscip-go gomod github.com/golang/go/src go1.25.0 `math/rand`/Rand#, maxSize int) *psetscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets_test`/pset# { |
| 237 | set := makePsetscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets_test`/makePset().() |
| 238 | size := int(prng.Intscip-go gomod github.com/golang/go/src go1.25.0 `math/rand`/Rand#Int().()) % maxSize |
| 239 | for range size { |
| 240 | // TODO(adonovan): benchmark how performance varies |
| 241 | // with this sparsity parameter. |
| 242 | n := int(prng.Intscip-go gomod github.com/golang/go/src go1.25.0 `math/rand`/Rand#Int().()) % 10000 |
| 243 | set.addscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets_test`/pset#add().(n) |
| 244 | } |
| 245 | return set |
| 246 | } |
| 247 | |
| 248 | // TestRandomMutations performs the same random adds/removes on two |
| 249 | // set implementations and ensures that they compute the same result. |
| 250 | func TestRandomMutationsscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets_test`/TestRandomMutations().(t *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Tscip-go gomod github.com/golang/go/src go1.25.0 testing/T#) { |
| 251 | const debug = false |
| 252 | |
| 253 | set := makePsetscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets_test`/makePset().() |
| 254 | prng := randscip-go gomod github.com/golang/go/src go1.25.0 `math/rand`/.Newscip-go gomod github.com/golang/go/src go1.25.0 `math/rand`/New().(randscip-go gomod github.com/golang/go/src go1.25.0 `math/rand`/.NewSourcescip-go gomod github.com/golang/go/src go1.25.0 `math/rand`/NewSource().(0)) |
| 255 | for i := range 10000 { |
| 256 | n := int(prng.Intscip-go gomod github.com/golang/go/src go1.25.0 `math/rand`/Rand#Int().())%2000 - 1000 |
| 257 | if i%2 == 0 { |
| 258 | if debug { |
| 259 | logscip-go gomod github.com/golang/go/src go1.25.0 log/.Printfscip-go gomod github.com/golang/go/src go1.25.0 log/Printf().("add %d", n) |
| 260 | } |
| 261 | set.addscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets_test`/pset#add().(n) |
| 262 | } else { |
| 263 | if debug { |
| 264 | logscip-go gomod github.com/golang/go/src go1.25.0 log/.Printfscip-go gomod github.com/golang/go/src go1.25.0 log/Printf().("remove %d", n) |
| 265 | } |
| 266 | set.removescip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets_test`/pset#remove().(n) |
| 267 | } |
| 268 | if debug { |
| 269 | set.checkscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets_test`/pset#check().(t, "post mutation") |
| 270 | } |
| 271 | } |
| 272 | set.checkscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets_test`/pset#check().(t, "final") |
| 273 | if debug { |
| 274 | logscip-go gomod github.com/golang/go/src go1.25.0 log/.Printscip-go gomod github.com/golang/go/src go1.25.0 log/Print().(&set.bitsscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets_test`/pset#bits.) |
| 275 | } |
| 276 | } |
| 277 | |
| 278 | func TestLowerBoundscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets_test`/TestLowerBound().(t *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Tscip-go gomod github.com/golang/go/src go1.25.0 testing/T#) { |
| 279 | // Use random sets of sizes from 0 to about 4000. |
| 280 | prng := randscip-go gomod github.com/golang/go/src go1.25.0 `math/rand`/.Newscip-go gomod github.com/golang/go/src go1.25.0 `math/rand`/New().(randscip-go gomod github.com/golang/go/src go1.25.0 `math/rand`/.NewSourcescip-go gomod github.com/golang/go/src go1.25.0 `math/rand`/NewSource().(0)) |
| 281 | for i := range uint(12) { |
| 282 | x := randomPsetscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets_test`/randomPset().(prng, 1<<i) |
| 283 | for j := range 10000 { |
| 284 | found := intsetsscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets`/.MaxIntscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets`/MaxInt. |
| 285 | for e := range x.hashscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets_test`/pset#hash. { |
| 286 | if e >= j && e < found { |
| 287 | found = e |
| 288 | } |
| 289 | } |
| 290 | if res := x.bitsscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets_test`/pset#bits..LowerBoundscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets`/Sparse#LowerBound().(j); res != found { |
| 291 | t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("%s: LowerBound(%d)=%d, expected %d", &x.bitsscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets_test`/pset#bits., j, res, found) |
| 292 | } |
| 293 | } |
| 294 | } |
| 295 | } |
| 296 | |
| 297 | // TestSetOperations exercises classic set operations: ∩ , ∪, \. |
| 298 | func TestSetOperationsscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets_test`/TestSetOperations().(t *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Tscip-go gomod github.com/golang/go/src go1.25.0 testing/T#) { |
| 299 | prng := randscip-go gomod github.com/golang/go/src go1.25.0 `math/rand`/.Newscip-go gomod github.com/golang/go/src go1.25.0 `math/rand`/New().(randscip-go gomod github.com/golang/go/src go1.25.0 `math/rand`/.NewSourcescip-go gomod github.com/golang/go/src go1.25.0 `math/rand`/NewSource().(0)) |
| 300 | |
| 301 | // Use random sets of sizes from 0 to about 4000. |
| 302 | // For each operator, we test variations such as |
| 303 | // Z.op(X, Y), Z.op(X, Z) and Z.op(Z, Y) to exercise |
| 304 | // the degenerate cases of each method implementation. |
| 305 | for i := range uint(12) { |
| 306 | X := randomPsetscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets_test`/randomPset().(prng, 1<<i) |
| 307 | Y := randomPsetscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets_test`/randomPset().(prng, 1<<i) |
| 308 | |
| 309 | // TODO(adonovan): minimise dependencies between stanzas below. |
| 310 | |
| 311 | // Copy(X) |
| 312 | C := makePsetscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets_test`/makePset().() |
| 313 | C.bitsscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets_test`/pset#bits..Copyscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets`/Sparse#Copy().(&Y.bitsscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets_test`/pset#bits.) // no effect on result |
| 314 | C.bitsscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets_test`/pset#bits..Copyscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets`/Sparse#Copy().(&X.bitsscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets_test`/pset#bits.) |
| 315 | C.hashscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets_test`/pset#hash. = X.hashscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets_test`/pset#hash. |
| 316 | C.checkscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets_test`/pset#check().(t, "C.Copy(X)") |
| 317 | C.bitsscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets_test`/pset#bits..Copyscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets`/Sparse#Copy().(&C.bitsscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets_test`/pset#bits.) |
| 318 | C.checkscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets_test`/pset#check().(t, "C.Copy(C)") |
| 319 | |
| 320 | // U.Union(X, Y) |
| 321 | U := makePsetscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets_test`/makePset().() |
| 322 | U.bitsscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets_test`/pset#bits..Unionscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets`/Sparse#Union().(&X.bitsscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets_test`/pset#bits., &Y.bitsscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets_test`/pset#bits.) |
| 323 | for n := range X.hashscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets_test`/pset#hash. { |
| 324 | U.hashscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets_test`/pset#hash.[n] = true |
| 325 | } |
| 326 | for n := range Y.hashscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets_test`/pset#hash. { |
| 327 | U.hashscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets_test`/pset#hash.[n] = true |
| 328 | } |
| 329 | U.checkscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets_test`/pset#check().(t, "U.Union(X, Y)") |
| 330 | |
| 331 | // U.Union(X, X) |
| 332 | U.bitsscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets_test`/pset#bits..Unionscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets`/Sparse#Union().(&X.bitsscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets_test`/pset#bits., &X.bitsscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets_test`/pset#bits.) |
| 333 | U.hashscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets_test`/pset#hash. = X.hashscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets_test`/pset#hash. |
| 334 | U.checkscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets_test`/pset#check().(t, "U.Union(X, X)") |
| 335 | |
| 336 | // U.Union(U, Y) |
| 337 | U = makePsetscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets_test`/makePset().() |
| 338 | U.bitsscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets_test`/pset#bits..Copyscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets`/Sparse#Copy().(&X.bitsscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets_test`/pset#bits.) |
| 339 | U.bitsscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets_test`/pset#bits..Unionscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets`/Sparse#Union().(&U.bitsscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets_test`/pset#bits., &Y.bitsscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets_test`/pset#bits.) |
| 340 | for n := range X.hashscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets_test`/pset#hash. { |
| 341 | U.hashscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets_test`/pset#hash.[n] = true |
| 342 | } |
| 343 | for n := range Y.hashscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets_test`/pset#hash. { |
| 344 | U.hashscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets_test`/pset#hash.[n] = true |
| 345 | } |
| 346 | U.checkscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets_test`/pset#check().(t, "U.Union(U, Y)") |
| 347 | |
| 348 | // U.Union(X, U) |
| 349 | U.bitsscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets_test`/pset#bits..Copyscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets`/Sparse#Copy().(&Y.bitsscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets_test`/pset#bits.) |
| 350 | U.bitsscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets_test`/pset#bits..Unionscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets`/Sparse#Union().(&X.bitsscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets_test`/pset#bits., &U.bitsscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets_test`/pset#bits.) |
| 351 | U.checkscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets_test`/pset#check().(t, "U.Union(X, U)") |
| 352 | |
| 353 | // U.UnionWith(U) |
| 354 | U.bitsscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets_test`/pset#bits..UnionWithscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets`/Sparse#UnionWith().(&U.bitsscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets_test`/pset#bits.) |
| 355 | U.checkscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets_test`/pset#check().(t, "U.UnionWith(U)") |
| 356 | |
| 357 | // I.Intersection(X, Y) |
| 358 | I := makePsetscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets_test`/makePset().() |
| 359 | I.bitsscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets_test`/pset#bits..Intersectionscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets`/Sparse#Intersection().(&X.bitsscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets_test`/pset#bits., &Y.bitsscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets_test`/pset#bits.) |
| 360 | for n := range X.hashscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets_test`/pset#hash. { |
| 361 | if Y.hashscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets_test`/pset#hash.[n] { |
| 362 | I.hashscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets_test`/pset#hash.[n] = true |
| 363 | } |
| 364 | } |
| 365 | I.checkscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets_test`/pset#check().(t, "I.Intersection(X, Y)") |
| 366 | |
| 367 | // I.Intersection(X, X) |
| 368 | I.bitsscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets_test`/pset#bits..Intersectionscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets`/Sparse#Intersection().(&X.bitsscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets_test`/pset#bits., &X.bitsscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets_test`/pset#bits.) |
| 369 | I.hashscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets_test`/pset#hash. = X.hashscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets_test`/pset#hash. |
| 370 | I.checkscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets_test`/pset#check().(t, "I.Intersection(X, X)") |
| 371 | |
| 372 | // I.Intersection(I, X) |
| 373 | I.bitsscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets_test`/pset#bits..Intersectionscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets`/Sparse#Intersection().(&I.bitsscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets_test`/pset#bits., &X.bitsscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets_test`/pset#bits.) |
| 374 | I.checkscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets_test`/pset#check().(t, "I.Intersection(I, X)") |
| 375 | |
| 376 | // I.Intersection(X, I) |
| 377 | I.bitsscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets_test`/pset#bits..Intersectionscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets`/Sparse#Intersection().(&X.bitsscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets_test`/pset#bits., &I.bitsscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets_test`/pset#bits.) |
| 378 | I.checkscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets_test`/pset#check().(t, "I.Intersection(X, I)") |
| 379 | |
| 380 | // I.Intersection(I, I) |
| 381 | I.bitsscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets_test`/pset#bits..Intersectionscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets`/Sparse#Intersection().(&I.bitsscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets_test`/pset#bits., &I.bitsscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets_test`/pset#bits.) |
| 382 | I.checkscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets_test`/pset#check().(t, "I.Intersection(I, I)") |
| 383 | |
| 384 | // D.Difference(X, Y) |
| 385 | D := makePsetscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets_test`/makePset().() |
| 386 | D.bitsscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets_test`/pset#bits..Differencescip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets`/Sparse#Difference().(&X.bitsscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets_test`/pset#bits., &Y.bitsscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets_test`/pset#bits.) |
| 387 | for n := range X.hashscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets_test`/pset#hash. { |
| 388 | if !Y.hashscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets_test`/pset#hash.[n] { |
| 389 | D.hashscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets_test`/pset#hash.[n] = true |
| 390 | } |
| 391 | } |
| 392 | D.checkscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets_test`/pset#check().(t, "D.Difference(X, Y)") |
| 393 | |
| 394 | // D.Difference(D, Y) |
| 395 | D.bitsscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets_test`/pset#bits..Copyscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets`/Sparse#Copy().(&X.bitsscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets_test`/pset#bits.) |
| 396 | D.bitsscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets_test`/pset#bits..Differencescip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets`/Sparse#Difference().(&D.bitsscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets_test`/pset#bits., &Y.bitsscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets_test`/pset#bits.) |
| 397 | D.checkscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets_test`/pset#check().(t, "D.Difference(D, Y)") |
| 398 | |
| 399 | // D.Difference(Y, D) |
| 400 | D.bitsscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets_test`/pset#bits..Copyscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets`/Sparse#Copy().(&X.bitsscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets_test`/pset#bits.) |
| 401 | D.bitsscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets_test`/pset#bits..Differencescip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets`/Sparse#Difference().(&Y.bitsscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets_test`/pset#bits., &D.bitsscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets_test`/pset#bits.) |
| 402 | D.hashscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets_test`/pset#hash. = make(map[int]bool) |
| 403 | for n := range Y.hashscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets_test`/pset#hash. { |
| 404 | if !X.hashscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets_test`/pset#hash.[n] { |
| 405 | D.hashscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets_test`/pset#hash.[n] = true |
| 406 | } |
| 407 | } |
| 408 | D.checkscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets_test`/pset#check().(t, "D.Difference(Y, D)") |
| 409 | |
| 410 | // D.Difference(X, X) |
| 411 | D.bitsscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets_test`/pset#bits..Differencescip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets`/Sparse#Difference().(&X.bitsscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets_test`/pset#bits., &X.bitsscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets_test`/pset#bits.) |
| 412 | D.hashscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets_test`/pset#hash. = nil |
| 413 | D.checkscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets_test`/pset#check().(t, "D.Difference(X, X)") |
| 414 | |
| 415 | // D.DifferenceWith(D) |
| 416 | D.bitsscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets_test`/pset#bits..Copyscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets`/Sparse#Copy().(&X.bitsscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets_test`/pset#bits.) |
| 417 | D.bitsscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets_test`/pset#bits..DifferenceWithscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets`/Sparse#DifferenceWith().(&D.bitsscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets_test`/pset#bits.) |
| 418 | D.checkscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets_test`/pset#check().(t, "D.DifferenceWith(D)") |
| 419 | |
| 420 | // SD.SymmetricDifference(X, Y) |
| 421 | SD := makePsetscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets_test`/makePset().() |
| 422 | SD.bitsscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets_test`/pset#bits..SymmetricDifferencescip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets`/Sparse#SymmetricDifference().(&X.bitsscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets_test`/pset#bits., &Y.bitsscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets_test`/pset#bits.) |
| 423 | for n := range X.hashscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets_test`/pset#hash. { |
| 424 | if !Y.hashscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets_test`/pset#hash.[n] { |
| 425 | SD.hashscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets_test`/pset#hash.[n] = true |
| 426 | } |
| 427 | } |
| 428 | for n := range Y.hashscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets_test`/pset#hash. { |
| 429 | if !X.hashscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets_test`/pset#hash.[n] { |
| 430 | SD.hashscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets_test`/pset#hash.[n] = true |
| 431 | } |
| 432 | } |
| 433 | SD.checkscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets_test`/pset#check().(t, "SD.SymmetricDifference(X, Y)") |
| 434 | |
| 435 | // X.SymmetricDifferenceWith(Y) |
| 436 | SD.bitsscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets_test`/pset#bits..Copyscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets`/Sparse#Copy().(&X.bitsscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets_test`/pset#bits.) |
| 437 | SD.bitsscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets_test`/pset#bits..SymmetricDifferenceWithscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets`/Sparse#SymmetricDifferenceWith().(&Y.bitsscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets_test`/pset#bits.) |
| 438 | SD.checkscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets_test`/pset#check().(t, "X.SymmetricDifference(Y)") |
| 439 | |
| 440 | // Y.SymmetricDifferenceWith(X) |
| 441 | SD.bitsscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets_test`/pset#bits..Copyscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets`/Sparse#Copy().(&Y.bitsscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets_test`/pset#bits.) |
| 442 | SD.bitsscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets_test`/pset#bits..SymmetricDifferenceWithscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets`/Sparse#SymmetricDifferenceWith().(&X.bitsscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets_test`/pset#bits.) |
| 443 | SD.checkscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets_test`/pset#check().(t, "Y.SymmetricDifference(X)") |
| 444 | |
| 445 | // SD.SymmetricDifference(X, X) |
| 446 | SD.bitsscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets_test`/pset#bits..SymmetricDifferencescip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets`/Sparse#SymmetricDifference().(&X.bitsscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets_test`/pset#bits., &X.bitsscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets_test`/pset#bits.) |
| 447 | SD.hashscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets_test`/pset#hash. = nil |
| 448 | SD.checkscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets_test`/pset#check().(t, "SD.SymmetricDifference(X, X)") |
| 449 | |
| 450 | // SD.SymmetricDifference(X, Copy(X)) |
| 451 | X2 := makePsetscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets_test`/makePset().() |
| 452 | X2.bitsscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets_test`/pset#bits..Copyscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets`/Sparse#Copy().(&X.bitsscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets_test`/pset#bits.) |
| 453 | SD.bitsscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets_test`/pset#bits..SymmetricDifferencescip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets`/Sparse#SymmetricDifference().(&X.bitsscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets_test`/pset#bits., &X2.bitsscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets_test`/pset#bits.) |
| 454 | SD.checkscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets_test`/pset#check().(t, "SD.SymmetricDifference(X, Copy(X))") |
| 455 | |
| 456 | // Copy(X).SymmetricDifferenceWith(X) |
| 457 | SD.bitsscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets_test`/pset#bits..Copyscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets`/Sparse#Copy().(&X.bitsscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets_test`/pset#bits.) |
| 458 | SD.bitsscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets_test`/pset#bits..SymmetricDifferenceWithscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets`/Sparse#SymmetricDifferenceWith().(&X.bitsscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets_test`/pset#bits.) |
| 459 | SD.checkscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets_test`/pset#check().(t, "Copy(X).SymmetricDifferenceWith(X)") |
| 460 | } |
| 461 | } |
| 462 | |
| 463 | // TestUnionWithChanged checks the 'changed' result of UnionWith. |
| 464 | func TestUnionWithChangedscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets_test`/TestUnionWithChanged().(t *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Tscip-go gomod github.com/golang/go/src go1.25.0 testing/T#) { |
| 465 | setOf := func(elems ...int) *intsetsscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets`/.Sparsescip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets`/Sparse# { |
| 466 | s := new(intsetsscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets`/.Sparsescip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets`/Sparse#) |
| 467 | for _, elem := range elems { |
| 468 | s.Insertscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets`/Sparse#Insert().(elem) |
| 469 | } |
| 470 | return s |
| 471 | } |
| 472 | |
| 473 | checkUnionWith := func(x, y *intsetsscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets`/.Sparsescip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets`/Sparse#) { |
| 474 | xstr := x.Stringscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets`/Sparse#String().() |
| 475 | prelen := x.Lenscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets`/Sparse#Len().() |
| 476 | changed := x.UnionWithscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets`/Sparse#UnionWith().(y) |
| 477 | if (x.Lenscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets`/Sparse#Len().() > prelen) != changed { |
| 478 | t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("%s.UnionWith(%s) => %s, changed=%t", xstr, y, x, changed) |
| 479 | } |
| 480 | } |
| 481 | |
| 482 | // The case marked "!" is a regression test for Issue 50352, |
| 483 | // which spuriously returned true when y ⊂ x. |
| 484 | |
| 485 | // same block |
| 486 | checkUnionWith(setOf(1, 2), setOf(1, 2)) |
| 487 | checkUnionWith(setOf(1, 2, 3), setOf(1, 2)) // ! |
| 488 | checkUnionWith(setOf(1, 2), setOf(1, 2, 3)) |
| 489 | checkUnionWith(setOf(1, 2), setOf()) |
| 490 | |
| 491 | // different blocks |
| 492 | checkUnionWith(setOf(1, 1000000), setOf(1, 1000000)) |
| 493 | checkUnionWith(setOf(1, 2, 1000000), setOf(1, 2)) |
| 494 | checkUnionWith(setOf(1, 2), setOf(1, 2, 1000000)) |
| 495 | checkUnionWith(setOf(1, 1000000), setOf()) |
| 496 | } |
| 497 | |
| 498 | func TestIntersectionWithscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets_test`/TestIntersectionWith().(t *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Tscip-go gomod github.com/golang/go/src go1.25.0 testing/T#) { |
| 499 | // Edge cases: the pairs (1,1), (1000,2000), (8000,4000) |
| 500 | // exercise the <, >, == cases in IntersectionWith that the |
| 501 | // TestSetOperations data is too dense to cover. |
| 502 | var X, Y intsetsscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets`/.Sparsescip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets`/Sparse# |
| 503 | X.Insertscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets`/Sparse#Insert().(1) |
| 504 | X.Insertscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets`/Sparse#Insert().(1000) |
| 505 | X.Insertscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets`/Sparse#Insert().(8000) |
| 506 | Y.Insertscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets`/Sparse#Insert().(1) |
| 507 | Y.Insertscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets`/Sparse#Insert().(2000) |
| 508 | Y.Insertscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets`/Sparse#Insert().(4000) |
| 509 | X.IntersectionWithscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets`/Sparse#IntersectionWith().(&Y) |
| 510 | if got, want := X.Stringscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets`/Sparse#String().(), "{1}"; got != want { |
| 511 | t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("IntersectionWith: got %s, want %s", got, want) |
| 512 | } |
| 513 | } |
| 514 | |
| 515 | func TestIntersectsscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets_test`/TestIntersects().(t *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Tscip-go gomod github.com/golang/go/src go1.25.0 testing/T#) { |
| 516 | prng := randscip-go gomod github.com/golang/go/src go1.25.0 `math/rand`/.Newscip-go gomod github.com/golang/go/src go1.25.0 `math/rand`/New().(randscip-go gomod github.com/golang/go/src go1.25.0 `math/rand`/.NewSourcescip-go gomod github.com/golang/go/src go1.25.0 `math/rand`/NewSource().(0)) |
| 517 | |
| 518 | for i := range uint(12) { |
| 519 | X, Y := randomPsetscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets_test`/randomPset().(prng, 1<<i), randomPsetscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets_test`/randomPset().(prng, 1<<i) |
| 520 | x, y := &X.bitsscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets_test`/pset#bits., &Y.bitsscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets_test`/pset#bits. |
| 521 | |
| 522 | // test the slow way |
| 523 | var z intsetsscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets`/.Sparsescip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets`/Sparse# |
| 524 | z.Copyscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets`/Sparse#Copy().(x) |
| 525 | z.IntersectionWithscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets`/Sparse#IntersectionWith().(y) |
| 526 | |
| 527 | if got, want := x.Intersectsscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets`/Sparse#Intersects().(y), !z.IsEmptyscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets`/Sparse#IsEmpty().(); got != want { |
| 528 | t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("Intersects(%s, %s): got %v, want %v (%s)", x, y, got, want, &z) |
| 529 | } |
| 530 | |
| 531 | // make it false |
| 532 | a := x.AppendToscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets`/Sparse#AppendTo().(nil) |
| 533 | for _, v := range a { |
| 534 | y.Removescip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets`/Sparse#Remove().(v) |
| 535 | } |
| 536 | |
| 537 | if got, want := x.Intersectsscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets`/Sparse#Intersects().(y), false; got != want { |
| 538 | t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("Intersects: got %v, want %v", got, want) |
| 539 | } |
| 540 | |
| 541 | // make it true |
| 542 | if x.IsEmptyscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets`/Sparse#IsEmpty().() { |
| 543 | continue |
| 544 | } |
| 545 | i := prng.Intnscip-go gomod github.com/golang/go/src go1.25.0 `math/rand`/Rand#Intn().(len(a)) |
| 546 | y.Insertscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets`/Sparse#Insert().(a[i]) |
| 547 | |
| 548 | if got, want := x.Intersectsscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets`/Sparse#Intersects().(y), true; got != want { |
| 549 | t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("Intersects: got %v, want %v", got, want) |
| 550 | } |
| 551 | } |
| 552 | } |
| 553 | |
| 554 | func TestSubsetOfscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets_test`/TestSubsetOf().(t *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Tscip-go gomod github.com/golang/go/src go1.25.0 testing/T#) { |
| 555 | prng := randscip-go gomod github.com/golang/go/src go1.25.0 `math/rand`/.Newscip-go gomod github.com/golang/go/src go1.25.0 `math/rand`/New().(randscip-go gomod github.com/golang/go/src go1.25.0 `math/rand`/.NewSourcescip-go gomod github.com/golang/go/src go1.25.0 `math/rand`/NewSource().(0)) |
| 556 | |
| 557 | for i := range uint(12) { |
| 558 | X, Y := randomPsetscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets_test`/randomPset().(prng, 1<<i), randomPsetscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets_test`/randomPset().(prng, 1<<i) |
| 559 | x, y := &X.bitsscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets_test`/pset#bits., &Y.bitsscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets_test`/pset#bits. |
| 560 | |
| 561 | // test the slow way |
| 562 | var z intsetsscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets`/.Sparsescip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets`/Sparse# |
| 563 | z.Copyscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets`/Sparse#Copy().(x) |
| 564 | z.DifferenceWithscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets`/Sparse#DifferenceWith().(y) |
| 565 | |
| 566 | if got, want := x.SubsetOfscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets`/Sparse#SubsetOf().(y), z.IsEmptyscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets`/Sparse#IsEmpty().(); got != want { |
| 567 | t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("SubsetOf: got %v, want %v", got, want) |
| 568 | } |
| 569 | |
| 570 | // make it true |
| 571 | y.UnionWithscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets`/Sparse#UnionWith().(x) |
| 572 | |
| 573 | if got, want := x.SubsetOfscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets`/Sparse#SubsetOf().(y), true; got != want { |
| 574 | t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("SubsetOf: got %v, want %v", got, want) |
| 575 | } |
| 576 | |
| 577 | // make it false |
| 578 | if x.IsEmptyscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets`/Sparse#IsEmpty().() { |
| 579 | continue |
| 580 | } |
| 581 | a := x.AppendToscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets`/Sparse#AppendTo().(nil) |
| 582 | i := prng.Intnscip-go gomod github.com/golang/go/src go1.25.0 `math/rand`/Rand#Intn().(len(a)) |
| 583 | y.Removescip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets`/Sparse#Remove().(a[i]) |
| 584 | |
| 585 | if got, want := x.SubsetOfscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets`/Sparse#SubsetOf().(y), false; got != want { |
| 586 | t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("SubsetOf: got %v, want %v", got, want) |
| 587 | } |
| 588 | } |
| 589 | } |
| 590 | |
| 591 | func TestBitStringscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets_test`/TestBitString().(t *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Tscip-go gomod github.com/golang/go/src go1.25.0 testing/T#) { |
| 592 | for _, test := range []struct { |
| 593 | input []int |
| 594 | want string |
| 595 | }{ |
| 596 | {nil, "0"}, |
| 597 | {[]int{0}, "1"}, |
| 598 | {[]int{0, 4, 5}, "110001"}, |
| 599 | {[]int{0, 7, 177}, "1" + stringsscip-go gomod github.com/golang/go/src go1.25.0 strings/.Repeatscip-go gomod github.com/golang/go/src go1.25.0 strings/Repeat().("0", 169) + "10000001"}, |
| 600 | {[]int{-3, 0, 4, 5}, "110001.001"}, |
| 601 | {[]int{-3}, "0.001"}, |
| 602 | } { |
| 603 | var set intsetsscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets`/.Sparsescip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets`/Sparse# |
| 604 | for _, x := range test.input { |
| 605 | set.Insertscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets`/Sparse#Insert().(x) |
| 606 | } |
| 607 | if got := set.BitStringscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets`/Sparse#BitString().(); got != test.want { |
| 608 | t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("BitString(%s) = %s, want %s", set.Stringscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets`/Sparse#String().(), got, test.want) |
| 609 | } |
| 610 | } |
| 611 | } |
| 612 | |
| 613 | func TestFailFastOnShallowCopyscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets_test`/TestFailFastOnShallowCopy().(t *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Tscip-go gomod github.com/golang/go/src go1.25.0 testing/T#) { |
| 614 | var x intsetsscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets`/.Sparsescip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets`/Sparse# |
| 615 | x.Insertscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets`/Sparse#Insert().(1) |
| 616 | |
| 617 | y := x // shallow copy (breaks representation invariants) |
| 618 | defer func() { |
| 619 | got := fmtscip-go gomod github.com/golang/go/src go1.25.0 fmt/.Sprintscip-go gomod github.com/golang/go/src go1.25.0 fmt/Sprint().(recover()) |
| 620 | want := "interface conversion: interface {} is nil, not intsets.to_copy_a_sparse_you_must_call_its_Copy_method" |
| 621 | if got != want { |
| 622 | t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("shallow copy: recover() = %q, want %q", got, want) |
| 623 | } |
| 624 | }() |
| 625 | _ = y.Stringscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets`/Sparse#String().() // panics |
| 626 | t.Errorscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Error().("didn't panic as expected") |
| 627 | } |
| 628 | |
| 629 | // -- Benchmarks ------------------------------------------------------- |
| 630 | |
| 631 | // TODO(adonovan): |
| 632 | // - Add benchmarks of each method. |
| 633 | // - Gather set distributions from pointer analysis. |
| 634 | // - Measure memory usage. |
| 635 | |
| 636 | func benchmarkInsertProbeSparsescip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets_test`/benchmarkInsertProbeSparse().(b *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Bscip-go gomod github.com/golang/go/src go1.25.0 testing/B#, size, spread int) { |
| 637 | prng := randscip-go gomod github.com/golang/go/src go1.25.0 `math/rand`/.Newscip-go gomod github.com/golang/go/src go1.25.0 `math/rand`/New().(randscip-go gomod github.com/golang/go/src go1.25.0 `math/rand`/.NewSourcescip-go gomod github.com/golang/go/src go1.25.0 `math/rand`/NewSource().(0)) |
| 638 | // Generate our insertions and probes beforehand (we don't want to benchmark |
| 639 | // the prng). |
| 640 | insert := make([]int, size) |
| 641 | probe := make([]int, size*2) |
| 642 | for i := range insert { |
| 643 | insert[i] = prng.Intscip-go gomod github.com/golang/go/src go1.25.0 `math/rand`/Rand#Int().() % spread |
| 644 | } |
| 645 | for i := range probe { |
| 646 | probe[i] = prng.Intscip-go gomod github.com/golang/go/src go1.25.0 `math/rand`/Rand#Int().() % spread |
| 647 | } |
| 648 | |
| 649 | var x intsetsscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets`/.Sparsescip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets`/Sparse# |
| 650 | for b.Loopscip-go gomod github.com/golang/go/src go1.25.0 testing/B#Loop().() { |
| 651 | x.Clearscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets`/Sparse#Clear().() |
| 652 | for _, n := range insert { |
| 653 | x.Insertscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets`/Sparse#Insert().(n) |
| 654 | } |
| 655 | hits := 0 |
| 656 | for _, n := range probe { |
| 657 | if x.Hasscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets`/Sparse#Has().(n) { |
| 658 | hits++ |
| 659 | } |
| 660 | } |
| 661 | // Use the variable so it doesn't get optimized away. |
| 662 | if hits > len(probe) { |
| 663 | b.Fatalfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatalf().("%d hits, only %d probes", hits, len(probe)) |
| 664 | } |
| 665 | } |
| 666 | } |
| 667 | |
| 668 | func BenchmarkInsertProbeSparse_2_10scip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets_test`/BenchmarkInsertProbeSparse_2_10().(b *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Bscip-go gomod github.com/golang/go/src go1.25.0 testing/B#) { |
| 669 | benchmarkInsertProbeSparsescip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets_test`/benchmarkInsertProbeSparse().(b, 2, 10) |
| 670 | } |
| 671 | |
| 672 | func BenchmarkInsertProbeSparse_10_10scip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets_test`/BenchmarkInsertProbeSparse_10_10().(b *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Bscip-go gomod github.com/golang/go/src go1.25.0 testing/B#) { |
| 673 | benchmarkInsertProbeSparsescip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets_test`/benchmarkInsertProbeSparse().(b, 10, 10) |
| 674 | } |
| 675 | |
| 676 | func BenchmarkInsertProbeSparse_10_1000scip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets_test`/BenchmarkInsertProbeSparse_10_1000().(b *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Bscip-go gomod github.com/golang/go/src go1.25.0 testing/B#) { |
| 677 | benchmarkInsertProbeSparsescip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets_test`/benchmarkInsertProbeSparse().(b, 10, 1000) |
| 678 | } |
| 679 | |
| 680 | func BenchmarkInsertProbeSparse_100_100scip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets_test`/BenchmarkInsertProbeSparse_100_100().(b *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Bscip-go gomod github.com/golang/go/src go1.25.0 testing/B#) { |
| 681 | benchmarkInsertProbeSparsescip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets_test`/benchmarkInsertProbeSparse().(b, 100, 100) |
| 682 | } |
| 683 | |
| 684 | func BenchmarkInsertProbeSparse_100_10000scip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets_test`/BenchmarkInsertProbeSparse_100_10000().(b *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Bscip-go gomod github.com/golang/go/src go1.25.0 testing/B#) { |
| 685 | benchmarkInsertProbeSparsescip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets_test`/benchmarkInsertProbeSparse().(b, 100, 1000) |
| 686 | } |
| 687 | |
| 688 | func BenchmarkUnionDifferenceSparsescip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets_test`/BenchmarkUnionDifferenceSparse().(b *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Bscip-go gomod github.com/golang/go/src go1.25.0 testing/B#) { |
| 689 | prng := randscip-go gomod github.com/golang/go/src go1.25.0 `math/rand`/.Newscip-go gomod github.com/golang/go/src go1.25.0 `math/rand`/New().(randscip-go gomod github.com/golang/go/src go1.25.0 `math/rand`/.NewSourcescip-go gomod github.com/golang/go/src go1.25.0 `math/rand`/NewSource().(0)) |
| 690 | for b.Loopscip-go gomod github.com/golang/go/src go1.25.0 testing/B#Loop().() { |
| 691 | var x, y, z intsetsscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets`/.Sparsescip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets`/Sparse# |
| 692 | for i := range 1000 { |
| 693 | n := int(prng.Intscip-go gomod github.com/golang/go/src go1.25.0 `math/rand`/Rand#Int().()) % 100000 |
| 694 | if i%2 == 0 { |
| 695 | x.Insertscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets`/Sparse#Insert().(n) |
| 696 | } else { |
| 697 | y.Insertscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets`/Sparse#Insert().(n) |
| 698 | } |
| 699 | } |
| 700 | z.Unionscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets`/Sparse#Union().(&x, &y) |
| 701 | z.Differencescip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets`/Sparse#Difference().(&x, &y) |
| 702 | } |
| 703 | } |
| 704 | |
| 705 | func BenchmarkUnionDifferenceHashTablescip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets_test`/BenchmarkUnionDifferenceHashTable().(b *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Bscip-go gomod github.com/golang/go/src go1.25.0 testing/B#) { |
| 706 | prng := randscip-go gomod github.com/golang/go/src go1.25.0 `math/rand`/.Newscip-go gomod github.com/golang/go/src go1.25.0 `math/rand`/New().(randscip-go gomod github.com/golang/go/src go1.25.0 `math/rand`/.NewSourcescip-go gomod github.com/golang/go/src go1.25.0 `math/rand`/NewSource().(0)) |
| 707 | for b.Loopscip-go gomod github.com/golang/go/src go1.25.0 testing/B#Loop().() { |
| 708 | x, y, z := make(map[int]bool), make(map[int]bool), make(map[int]bool) |
| 709 | for i := range 1000 { |
| 710 | n := int(prng.Intscip-go gomod github.com/golang/go/src go1.25.0 `math/rand`/Rand#Int().()) % 100000 |
| 711 | if i%2 == 0 { |
| 712 | x[n] = true |
| 713 | } else { |
| 714 | y[n] = true |
| 715 | } |
| 716 | } |
| 717 | // union |
| 718 | for n := range x { |
| 719 | z[n] = true |
| 720 | } |
| 721 | for n := range y { |
| 722 | z[n] = true |
| 723 | } |
| 724 | // difference |
| 725 | z = make(map[int]bool) |
| 726 | for n := range y { |
| 727 | if !x[n] { |
| 728 | z[n] = true |
| 729 | } |
| 730 | } |
| 731 | } |
| 732 | } |
| 733 | |
| 734 | func BenchmarkAppendToscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets_test`/BenchmarkAppendTo().(b *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Bscip-go gomod github.com/golang/go/src go1.25.0 testing/B#) { |
| 735 | prng := randscip-go gomod github.com/golang/go/src go1.25.0 `math/rand`/.Newscip-go gomod github.com/golang/go/src go1.25.0 `math/rand`/New().(randscip-go gomod github.com/golang/go/src go1.25.0 `math/rand`/.NewSourcescip-go gomod github.com/golang/go/src go1.25.0 `math/rand`/NewSource().(0)) |
| 736 | var x intsetsscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets`/.Sparsescip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets`/Sparse# |
| 737 | for range 1000 { |
| 738 | x.Insertscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets`/Sparse#Insert().(int(prng.Intscip-go gomod github.com/golang/go/src go1.25.0 `math/rand`/Rand#Int().()) % 10000) |
| 739 | } |
| 740 | var space [1000]int |
| 741 | for b.Loopscip-go gomod github.com/golang/go/src go1.25.0 testing/B#Loop().() { |
| 742 | x.AppendToscip-go gomod golang.org/x/tools . `golang.org/x/tools/container/intsets`/Sparse#AppendTo().(space[:0]) |
| 743 | } |
| 744 | } |