├── go.mod ├── go.sum ├── .github └── workflows │ └── test.yml ├── example_test.go ├── README.md ├── set.go ├── set_test.go └── LICENSE /go.mod: -------------------------------------------------------------------------------- 1 | module github.com/micnncim/go-set 2 | 3 | go 1.19 4 | 5 | require github.com/google/go-cmp v0.5.9 6 | -------------------------------------------------------------------------------- /go.sum: -------------------------------------------------------------------------------- 1 | github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38= 2 | github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= 3 | -------------------------------------------------------------------------------- /.github/workflows/test.yml: -------------------------------------------------------------------------------- 1 | name: Test 2 | 3 | on: 4 | push: 5 | branches: 6 | - main 7 | paths: 8 | - '**.go' 9 | pull_request_target: 10 | types: 11 | - opened 12 | - synchronize 13 | - reopened 14 | paths: 15 | - '**.go' 16 | 17 | jobs: 18 | test: 19 | name: Test 20 | 21 | runs-on: ubuntu-latest 22 | 23 | strategy: 24 | fail-fast: false 25 | matrix: 26 | go: 27 | - '^1.18' 28 | - '^1.19' 29 | 30 | steps: 31 | - name: Check out 32 | uses: actions/checkout@v3 33 | 34 | - name: Set up Go 35 | uses: actions/setup-go@v3 36 | with: 37 | go-version: ${{ matrix.go }} 38 | cache: true 39 | 40 | - name: Run test 41 | run: | 42 | go test -v -race ./... 43 | -------------------------------------------------------------------------------- /example_test.go: -------------------------------------------------------------------------------- 1 | package set_test 2 | 3 | import ( 4 | "fmt" 5 | 6 | "github.com/micnncim/go-set" 7 | ) 8 | 9 | func ExampleSet_Contains() { 10 | s := set.New(1, 2) 11 | 12 | fmt.Println(s.Contains(1)) 13 | fmt.Println(s.Contains(0)) 14 | // Output: 15 | // true 16 | // false 17 | } 18 | 19 | func ExampleSet_ContainsAll() { 20 | s := set.New("foo", "bar") 21 | 22 | fmt.Println(s.ContainsAll("foo", "bar")) 23 | fmt.Println(s.ContainsAll("foo", "bar", "baz")) 24 | // Output: 25 | // true 26 | // false 27 | } 28 | 29 | func ExampleSet_Difference() { 30 | s := set.New(1, 2) 31 | t := set.New(2, 3) 32 | 33 | fmt.Println(s.Difference(t)) 34 | fmt.Println(t.Difference(s)) 35 | // Output: 36 | // [1] 37 | // [3] 38 | } 39 | 40 | func ExampleSet_Intersection() { 41 | s := set.New(1, 2) 42 | t := set.New(2, 4) 43 | 44 | fmt.Println(s.Intersection(t)) 45 | // Output: 46 | // [2] 47 | } 48 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # go-set 2 | 3 | [![actions-workflow-test][actions-workflow-test-badge]][actions-workflow-test] 4 | [![release][release-badge]][release] 5 | [![pkg.go.dev][pkg.go.dev-badge]][pkg.go.dev] 6 | [![license][license-badge]][license] 7 | 8 | An experimental Go package that defines various methods for a [set](https://en.wikipedia.org/wiki/Set_(abstract_data_type)) implemented with Go generics. 9 | 10 | ## Usage 11 | 12 | See the [examples](./example_test.go). 13 | 14 | ## Alternatives 15 | 16 | - [golang.org/x/exp/slices](https://pkg.go.dev/golang.org/x/exp/slices) 17 | - `go-set` may be a better option if you don't find functions you want in this packages. 18 | - [k8s.io/apimachinery/pkg/util/sets](https://pkg.go.dev/k8s.io/apimachinery/pkg/util/sets) 19 | - `go-set` may be a better option if you prefer to use generics. 20 | 21 | 22 | 23 | [actions-workflow-test]: https://github.com/micnncim/go-set/actions?query=workflow%3ATest 24 | [actions-workflow-test-badge]: https://img.shields.io/github/workflow/status/micnncim/go-set/Test?label=Test&style=for-the-badge&logo=github 25 | 26 | [release]: https://github.com/micnncim/go-set/releases 27 | [release-badge]: https://img.shields.io/github/v/release/micnncim/go-set?style=for-the-badge&logo=github 28 | 29 | [pkg.go.dev]: https://pkg.go.dev/github.com/micnncim/go-set?tab=overview 30 | [pkg.go.dev-badge]: http://bit.ly/pkg-go-dev-badge 31 | 32 | [license]: LICENSE 33 | [license-badge]: https://img.shields.io/github/license/micnncim/go-set?style=for-the-badge 34 | -------------------------------------------------------------------------------- /set.go: -------------------------------------------------------------------------------- 1 | // Package set defines various methods for a set. 2 | package set 3 | 4 | import ( 5 | "fmt" 6 | ) 7 | 8 | // Set is a set of comparables. 9 | type Set[V comparable] struct { 10 | m map[V]struct{} 11 | } 12 | 13 | // New returns a Set from the given values. 14 | func New[V comparable](v ...V) *Set[V] { 15 | s := &Set[V]{make(map[V]struct{})} 16 | 17 | s.Insert(v...) 18 | 19 | return s 20 | } 21 | 22 | // Clone returns a new Set that a copy of `s`. 23 | func (s *Set[V]) Clone() *Set[V] { 24 | t := New[V]() 25 | 26 | t.Insert(s.Values()...) 27 | 28 | return t 29 | } 30 | 31 | // Delete removes the given values from `s`. 32 | func (s *Set[V]) Delete(v ...V) { 33 | for _, x := range v { 34 | delete(s.m, x) 35 | } 36 | } 37 | 38 | // Difference returns a Set whose values are in `s` and not in `t`. 39 | // 40 | // For example: 41 | // 42 | // s = {a1, a2, a3} 43 | // t = {a1, a2, a4, a5} 44 | // s.Difference(t) = {a3} 45 | // t.Difference(s) = {a4, a5} 46 | func (s *Set[V]) Difference(t *Set[V]) *Set[V] { 47 | u := New[V]() 48 | 49 | for k := range s.m { 50 | if !t.Contains(k) { 51 | u.Insert(k) 52 | } 53 | } 54 | 55 | return u 56 | } 57 | 58 | // Intersection returns a new Set whose values are included in both `s` and `t`. 59 | // 60 | // For example: 61 | // 62 | // s = {a1, a2} 63 | // t = {a2, a3} 64 | // s.Intersection(t) = {a2} 65 | func (s *Set[V]) Intersection(t *Set[V]) *Set[V] { 66 | u := New[V]() 67 | 68 | var walk, other *Set[V] 69 | 70 | if s.Len() < t.Len() { 71 | walk = s 72 | other = t 73 | } else { 74 | walk = t 75 | other = s 76 | } 77 | 78 | for k := range walk.m { 79 | if other.Contains(k) { 80 | u.Insert(k) 81 | } 82 | } 83 | 84 | return u 85 | } 86 | 87 | // Equal returns true iff `s` is equal to `t`. 88 | // 89 | // Two sets are equal if their underlying values are identical not considering 90 | // order. 91 | func (s *Set[V]) Equal(t *Set[V]) bool { 92 | return len(s.m) == len(t.m) && s.IsSuperset(t) 93 | } 94 | 95 | // Contains returns true iff `s` contains a given value. 96 | func (s *Set[V]) Contains(v V) bool { 97 | _, ok := s.m[v] 98 | return ok 99 | } 100 | 101 | // ContainsAll returns true iff `s` contains all the given values. 102 | func (s *Set[V]) ContainsAll(v ...V) bool { 103 | for _, x := range v { 104 | if !s.Contains(x) { 105 | return false 106 | } 107 | } 108 | 109 | return true 110 | } 111 | 112 | // ContainsAny returns true iff `s` contains any of the given values. 113 | func (s *Set[V]) ContainsAny(v ...V) bool { 114 | for _, x := range v { 115 | if s.Contains(x) { 116 | return true 117 | } 118 | } 119 | 120 | return false 121 | } 122 | 123 | // Insert adds the given values to `s`. 124 | func (s *Set[V]) Insert(v ...V) { 125 | for _, x := range v { 126 | s.m[x] = struct{}{} 127 | } 128 | } 129 | 130 | // IsSuperset returns true iff `t` is a superset of `s`. 131 | func (s *Set[V]) IsSuperset(t *Set[V]) bool { 132 | for k := range t.m { 133 | if !s.Contains(k) { 134 | return false 135 | } 136 | } 137 | 138 | return true 139 | } 140 | 141 | // Len returns the size of `s`. 142 | func (s *Set[V]) Len() int { 143 | return len(s.m) 144 | } 145 | 146 | // PopAny returns a single value randomly chosen and removes it from `s`. 147 | func (s *Set[V]) PopAny() (v V, _ bool) { 148 | for k := range s.m { 149 | delete(s.m, k) 150 | return k, true 151 | } 152 | 153 | return v, false 154 | } 155 | 156 | // String implements fmt.Stringer. 157 | func (s *Set[V]) String() string { 158 | return fmt.Sprint(s.Values()) 159 | } 160 | 161 | // Values returns the underlying values of `s` as a slice. 162 | func (s *Set[V]) Values() []V { 163 | v := make([]V, 0, len(s.m)) 164 | 165 | for k := range s.m { 166 | v = append(v, k) 167 | } 168 | 169 | return v 170 | } 171 | 172 | // Union returns a new Set whose values are included in either `s` or `t`. 173 | // 174 | // For example: 175 | // 176 | // s = {a1, a2} 177 | // t = {a3, a4} 178 | // s.Union(t) = {a1, a2, a3, a4} 179 | // t.Union(s) = {a1, a2, a3, a4} 180 | func (s *Set[V]) Union(t *Set[V]) *Set[V] { 181 | u := s.Clone() 182 | 183 | for k := range t.m { 184 | u.Insert(k) 185 | } 186 | 187 | return u 188 | } 189 | -------------------------------------------------------------------------------- /set_test.go: -------------------------------------------------------------------------------- 1 | package set_test 2 | 3 | import ( 4 | "testing" 5 | 6 | "github.com/google/go-cmp/cmp" 7 | "github.com/google/go-cmp/cmp/cmpopts" 8 | 9 | "github.com/micnncim/go-set" 10 | ) 11 | 12 | func equal(t *testing.T) func(*set.Set[int], *set.Set[int]) bool { 13 | t.Helper() 14 | 15 | return func(s1, s2 *set.Set[int]) bool { 16 | return s1.Equal(s2) 17 | } 18 | } 19 | 20 | func TestSetDelete(t *testing.T) { 21 | t.Parallel() 22 | 23 | tests := []struct { 24 | name string 25 | s *set.Set[int] 26 | v []int 27 | want *set.Set[int] 28 | }{ 29 | { 30 | name: "delete int", 31 | s: set.New(1, 2, 3), 32 | v: []int{1, 2}, 33 | want: set.New(3), 34 | }, 35 | } 36 | 37 | for _, tt := range tests { 38 | tt := tt 39 | 40 | t.Run(tt.name, func(t *testing.T) { 41 | t.Parallel() 42 | 43 | tt.s.Delete(tt.v...) 44 | 45 | if diff := cmp.Diff(tt.want, tt.s, cmp.Comparer(equal(t))); diff != "" { 46 | t.Errorf("(-want +got):\n%s", diff) 47 | } 48 | }) 49 | } 50 | } 51 | 52 | func TestSetDifference(t *testing.T) { 53 | t.Parallel() 54 | 55 | tests := []struct { 56 | name string 57 | s *set.Set[int] 58 | t *set.Set[int] 59 | want *set.Set[int] 60 | }{ 61 | { 62 | name: "difference int 1", 63 | s: set.New(1, 2, 3), 64 | t: set.New(1, 2, 4, 5), 65 | want: set.New(3), 66 | }, 67 | { 68 | name: "difference int 2", 69 | s: set.New(1, 2, 4, 5), 70 | t: set.New(1, 2, 3), 71 | want: set.New(4, 5), 72 | }, 73 | } 74 | 75 | for _, tt := range tests { 76 | tt := tt 77 | 78 | t.Run(tt.name, func(t *testing.T) { 79 | t.Parallel() 80 | 81 | if diff := cmp.Diff(tt.want, tt.s.Difference(tt.t), cmp.Comparer(equal(t))); diff != "" { 82 | t.Errorf("(-want +got):\n%s", diff) 83 | } 84 | }) 85 | } 86 | } 87 | 88 | func TestSetEqual(t *testing.T) { 89 | t.Parallel() 90 | 91 | tests := []struct { 92 | name string 93 | s *set.Set[int] 94 | t *set.Set[int] 95 | want bool 96 | }{ 97 | { 98 | name: "equal", 99 | s: set.New(1, 2), 100 | t: set.New(2, 1), 101 | want: true, 102 | }, 103 | { 104 | name: "not equal", 105 | s: set.New(1, 2), 106 | t: set.New(1, 3), 107 | want: false, 108 | }, 109 | } 110 | 111 | for _, tt := range tests { 112 | tt := tt 113 | 114 | t.Run(tt.name, func(t *testing.T) { 115 | t.Parallel() 116 | 117 | if diff := cmp.Diff(tt.want, tt.s.Equal(tt.t)); diff != "" { 118 | t.Errorf("(-want +got):\n%s", diff) 119 | } 120 | }) 121 | } 122 | } 123 | 124 | func TestSetContains(t *testing.T) { 125 | t.Parallel() 126 | 127 | tests := []struct { 128 | name string 129 | s *set.Set[int] 130 | v int 131 | want bool 132 | }{ 133 | { 134 | name: "contains", 135 | s: set.New(1), 136 | v: 1, 137 | want: true, 138 | }, 139 | { 140 | name: "not contains int", 141 | s: set.New(1), 142 | v: 2, 143 | want: false, 144 | }, 145 | } 146 | 147 | for _, tt := range tests { 148 | tt := tt 149 | 150 | t.Run(tt.name, func(t *testing.T) { 151 | t.Parallel() 152 | 153 | if diff := cmp.Diff(tt.want, tt.s.Contains(tt.v)); diff != "" { 154 | t.Errorf("(-want +got):\n%s", diff) 155 | } 156 | }) 157 | } 158 | } 159 | 160 | func TestSetContainsAll(t *testing.T) { 161 | t.Parallel() 162 | 163 | tests := []struct { 164 | name string 165 | s *set.Set[int] 166 | v []int 167 | want bool 168 | }{ 169 | { 170 | name: "contains", 171 | s: set.New(1, 2, 3), 172 | v: []int{1, 2}, 173 | want: true, 174 | }, 175 | { 176 | name: "not contains all", 177 | s: set.New(1, 2), 178 | v: []int{1, 2, 3}, 179 | want: false, 180 | }, 181 | } 182 | 183 | for _, tt := range tests { 184 | tt := tt 185 | 186 | t.Run(tt.name, func(t *testing.T) { 187 | t.Parallel() 188 | 189 | if diff := cmp.Diff(tt.want, tt.s.ContainsAll(tt.v...)); diff != "" { 190 | t.Errorf("(-want +got):\n%s", diff) 191 | } 192 | }) 193 | } 194 | } 195 | 196 | func TestSetContainsAny(t *testing.T) { 197 | t.Parallel() 198 | 199 | tests := []struct { 200 | name string 201 | s *set.Set[int] 202 | v []int 203 | want bool 204 | }{ 205 | { 206 | name: "contains any", 207 | s: set.New(1, 2), 208 | v: []int{1, 3}, 209 | want: true, 210 | }, 211 | { 212 | name: "not contains any", 213 | s: set.New(1, 2), 214 | v: []int{3}, 215 | want: false, 216 | }, 217 | } 218 | 219 | for _, tt := range tests { 220 | tt := tt 221 | 222 | t.Run(tt.name, func(t *testing.T) { 223 | t.Parallel() 224 | 225 | if diff := cmp.Diff(tt.want, tt.s.ContainsAny(tt.v...)); diff != "" { 226 | t.Errorf("(-want +got):\n%s", diff) 227 | } 228 | }) 229 | } 230 | } 231 | 232 | func TestSetInsert(t *testing.T) { 233 | t.Parallel() 234 | 235 | tests := []struct { 236 | name string 237 | s *set.Set[int] 238 | v int 239 | want *set.Set[int] 240 | }{ 241 | { 242 | name: "insert int", 243 | s: set.New(1), 244 | v: 2, 245 | want: set.New(1, 2), 246 | }, 247 | } 248 | 249 | for _, tt := range tests { 250 | tt := tt 251 | 252 | t.Run(tt.name, func(t *testing.T) { 253 | t.Parallel() 254 | 255 | tt.s.Insert(tt.v) 256 | 257 | if diff := cmp.Diff(tt.want, tt.s); diff != "" { 258 | t.Errorf("(-want +got):\n%s", diff) 259 | } 260 | }) 261 | } 262 | } 263 | 264 | func TestSetIntersection(t *testing.T) { 265 | t.Parallel() 266 | 267 | tests := []struct { 268 | name string 269 | s *set.Set[int] 270 | t *set.Set[int] 271 | want *set.Set[int] 272 | }{ 273 | { 274 | name: "intersection int with same len", 275 | s: set.New(1, 2, 3), 276 | t: set.New(2, 3, 5), 277 | want: set.New(2, 3), 278 | }, 279 | { 280 | name: "intersection int with different len", 281 | s: set.New(1, 2, 3, 4), 282 | t: set.New(2, 3, 5), 283 | want: set.New(2, 3), 284 | }, 285 | } 286 | 287 | for _, tt := range tests { 288 | tt := tt 289 | 290 | t.Run(tt.name, func(t *testing.T) { 291 | t.Parallel() 292 | 293 | if diff := cmp.Diff(tt.want, tt.s.Intersection(tt.t), cmp.Comparer(equal(t))); diff != "" { 294 | t.Errorf("(-want +got):\n%s", diff) 295 | } 296 | }) 297 | } 298 | } 299 | 300 | func TestSetIsSuperset(t *testing.T) { 301 | t.Parallel() 302 | 303 | tests := []struct { 304 | name string 305 | s *set.Set[int] 306 | t *set.Set[int] 307 | want bool 308 | }{ 309 | { 310 | name: "is superset", 311 | s: set.New(1, 2, 3), 312 | t: set.New(1, 2), 313 | want: true, 314 | }, 315 | { 316 | name: "is not superset", 317 | s: set.New(1, 2), 318 | t: set.New(1, 2, 3), 319 | want: false, 320 | }, 321 | } 322 | 323 | for _, tt := range tests { 324 | tt := tt 325 | 326 | t.Run(tt.name, func(t *testing.T) { 327 | t.Parallel() 328 | 329 | if diff := cmp.Diff(tt.want, tt.s.IsSuperset(tt.t)); diff != "" { 330 | t.Errorf("(-want +got):\n%s", diff) 331 | } 332 | }) 333 | } 334 | } 335 | 336 | func TestSetLen(t *testing.T) { 337 | t.Parallel() 338 | 339 | tests := []struct { 340 | name string 341 | s *set.Set[int] 342 | want int 343 | }{ 344 | { 345 | name: "len", 346 | s: set.New(1, 2), 347 | want: 2, 348 | }, 349 | } 350 | 351 | for _, tt := range tests { 352 | tt := tt 353 | 354 | t.Run(tt.name, func(t *testing.T) { 355 | t.Parallel() 356 | 357 | if diff := cmp.Diff(tt.want, tt.s.Len()); diff != "" { 358 | t.Errorf("(-want +got):\n%s", diff) 359 | } 360 | }) 361 | } 362 | } 363 | 364 | func TestSetPopAny(t *testing.T) { 365 | t.Parallel() 366 | 367 | tests := []struct { 368 | name string 369 | s *set.Set[int] 370 | want int 371 | wantBool bool 372 | wantSet *set.Set[int] 373 | }{ 374 | { 375 | name: "pop", 376 | s: set.New(1), 377 | want: 1, 378 | wantBool: true, 379 | wantSet: set.New[int](), 380 | }, 381 | { 382 | name: "no pop", 383 | s: set.New[int](), 384 | want: 0, 385 | wantBool: false, 386 | wantSet: set.New[int](), 387 | }, 388 | } 389 | 390 | for _, tt := range tests { 391 | tt := tt 392 | 393 | t.Run(tt.name, func(t *testing.T) { 394 | t.Parallel() 395 | 396 | got, ok := tt.s.PopAny() 397 | 398 | if diff := cmp.Diff(tt.want, got); diff != "" { 399 | t.Errorf("(-want +got):\n%s", diff) 400 | } 401 | if diff := cmp.Diff(tt.wantBool, ok); diff != "" { 402 | t.Errorf("(-want +got):\n%s", diff) 403 | } 404 | if diff := cmp.Diff(tt.wantSet, tt.s); diff != "" { 405 | t.Errorf("(-want +got):\n%s", diff) 406 | } 407 | }) 408 | } 409 | } 410 | 411 | func TestSetString(t *testing.T) { 412 | t.Parallel() 413 | 414 | tests := []struct { 415 | name string 416 | s *set.Set[int] 417 | want string 418 | }{ 419 | { 420 | name: "string of int", 421 | s: set.New(1), 422 | want: "[1]", 423 | }, 424 | } 425 | 426 | for _, tt := range tests { 427 | tt := tt 428 | 429 | t.Run(tt.name, func(t *testing.T) { 430 | t.Parallel() 431 | 432 | if diff := cmp.Diff(tt.want, tt.s.String()); diff != "" { 433 | t.Errorf("(-want +got):\n%s", diff) 434 | } 435 | }) 436 | } 437 | } 438 | 439 | func TestSetValues(t *testing.T) { 440 | t.Parallel() 441 | 442 | tests := []struct { 443 | name string 444 | s *set.Set[int] 445 | want []int 446 | }{ 447 | { 448 | name: "valid int set", 449 | s: set.New(1, 2), 450 | want: []int{1, 2}, 451 | }, 452 | } 453 | 454 | for _, tt := range tests { 455 | tt := tt 456 | 457 | t.Run(tt.name, func(t *testing.T) { 458 | t.Parallel() 459 | 460 | if diff := cmp.Diff(tt.want, tt.s.Values(), cmpopts.SortSlices(func(i, j int) bool { 461 | return i < j 462 | })); diff != "" { 463 | t.Errorf("(-want +got):\n%s", diff) 464 | } 465 | }) 466 | } 467 | } 468 | 469 | func TestSetUnion(t *testing.T) { 470 | t.Parallel() 471 | 472 | tests := []struct { 473 | name string 474 | s *set.Set[int] 475 | t *set.Set[int] 476 | want *set.Set[int] 477 | }{ 478 | { 479 | name: "union", 480 | s: set.New(1, 2), 481 | t: set.New(2, 3), 482 | want: set.New(1, 2, 3), 483 | }, 484 | } 485 | 486 | for _, tt := range tests { 487 | tt := tt 488 | 489 | t.Run(tt.name, func(t *testing.T) { 490 | t.Parallel() 491 | 492 | if diff := cmp.Diff(tt.want, tt.s.Union(tt.t), cmp.Comparer(equal(t))); diff != "" { 493 | t.Errorf("(-want +got):\n%s", diff) 494 | } 495 | }) 496 | } 497 | } 498 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright 2022 micnncim 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | --------------------------------------------------------------------------------