github.com/matrixorigin/matrixone@v0.7.0/pkg/sql/colexec/agg/bit_xor.go (about) 1 // Copyright 2021 Matrix Origin 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 agg 16 17 import ( 18 "github.com/matrixorigin/matrixone/pkg/container/types" 19 "math" 20 ) 21 22 type BitXor[T1 types.Ints | types.UInts | types.Floats] struct { 23 } 24 25 func BitXorReturnType(_ []types.Type) types.Type { 26 return types.New(types.T_uint64, 0, 0, 0) 27 } 28 29 func NewBitXor[T1 types.Ints | types.UInts | types.Floats]() *BitXor[T1] { 30 return &BitXor[T1]{} 31 } 32 33 func (bx *BitXor[T1]) Grows(_ int) { 34 } 35 36 func (bx *BitXor[T1]) Eval(vs []uint64) []uint64 { 37 return vs 38 } 39 40 func (bx *BitXor[T1]) Merge(_, _ int64, x, y uint64, IsEmpty1 bool, IsEmpty2 bool, _ any) (uint64, bool) { 41 if IsEmpty1 && !IsEmpty2 { 42 return y, false 43 } else if IsEmpty2 && !IsEmpty1 { 44 return x, false 45 } else if IsEmpty1 && IsEmpty2 { 46 return x, true 47 } else { 48 return x ^ y, false 49 } 50 } 51 52 func (bx *BitXor[T1]) Fill(_ int64, v1 T1, v2 uint64, z int64, IsEmpty bool, hasNull bool) (uint64, bool) { 53 if hasNull { 54 return v2, IsEmpty 55 } else if IsEmpty { 56 if z%2 == 0 { 57 return uint64(0), false 58 } else { 59 if float64(v1) > math.MaxUint64 { 60 return math.MaxInt64, false 61 } 62 if float64(v1) < 0 { 63 return uint64(int64(v1)), false 64 } 65 return uint64(v1), false 66 } 67 } 68 if z%2 == 0 { 69 return v2, false 70 } else { 71 if float64(v1) > math.MaxUint64 { 72 return math.MaxInt64 ^ v2, false 73 } 74 if float64(v1) < 0 { 75 return uint64(int64(v1)) ^ v2, false 76 } 77 return uint64(v1) ^ v2, false 78 } 79 } 80 81 func (bx *BitXor[T1]) MarshalBinary() ([]byte, error) { 82 return nil, nil 83 } 84 85 func (bx *BitXor[T1]) UnmarshalBinary(data []byte) error { 86 return nil 87 }