github.com/hasnat/dolt/go@v0.0.0-20210628190320-9eb5d843fbb7/libraries/doltcore/sqle/setalgebra/set.go (about) 1 // Copyright 2020 Dolthub, Inc. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package setalgebra 16 17 // Set is a well-defined collection of distint objects 18 type Set interface { 19 // Union takes the current set and another set and returns a set containing all values from both. 20 Union(other Set) (Set, error) 21 // Interset takes the current set and another set and returns a set containing the values that are in both 22 Intersect(other Set) (Set, error) 23 } 24 25 // EmptySet is a Set implementation that has no values 26 type EmptySet struct{} 27 28 // Union takes the current set and another set and returns a set containing all values from both. When EmptySet is 29 // unioned against any other set X, X will be the result. 30 func (es EmptySet) Union(other Set) (Set, error) { 31 return other, nil 32 } 33 34 // Intersect takes the current set and another set and returns a set containing the values that are in both. When 35 // EmptySet is intersected with any other set X, EmptySet will be returned. 36 func (es EmptySet) Intersect(other Set) (Set, error) { 37 return es, nil 38 } 39 40 // UniversalSet is the set containing all values 41 type UniversalSet struct{} 42 43 // Union takes the current set and another set and returns a set containing all values from both. When 44 // UniversalSet is unioned with any other set X, UniversalSet will be returned. 45 func (us UniversalSet) Union(other Set) (Set, error) { 46 return us, nil 47 } 48 49 // Interset takes the current set and another set and returns a set containing the values that are in both. When 50 // UniversalSet is intersected with any other set X, X will be the result. 51 func (us UniversalSet) Intersect(other Set) (Set, error) { 52 return other, nil 53 }