github.com/matrixorigin/matrixone@v0.7.0/pkg/vectorize/startswith/startsWith.go (about) 1 // Copyright 2022 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 startswith 16 17 import ( 18 "bytes" 19 ) 20 21 func hasPrefix(b1, b2 []byte) uint8 { 22 if len(b1) >= len(b2) && bytes.Equal(b1[:len(b2)], b2) { 23 return 1 24 } 25 return 0 26 } 27 28 func StartsWith(lv, rv []string, rs []uint8) []uint8 { 29 for i := range lv { 30 rs[i] = hasPrefix([]byte(lv[i]), []byte(rv[i])) 31 } 32 return rs 33 } 34 35 func StartsWithRightConst(lv []string, rv string, rs []uint8) []uint8 { 36 for i := range lv { 37 rs[i] = hasPrefix([]byte(lv[i]), []byte(rv)) 38 } 39 return rs 40 } 41 42 func StartsWithLeftConst(lv string, rv []string, rs []uint8) []uint8 { 43 for i := range rv { 44 rs[i] = hasPrefix([]byte(lv), []byte(rv[i])) 45 } 46 return rs 47 } 48 49 func StartsWithAllConst(lv, rv string, rs []uint8) []uint8 { 50 rs[0] = hasPrefix([]byte(lv), []byte(rv)) 51 return rs 52 }