github.com/matrixorigin/matrixone@v0.7.0/pkg/vectorize/findinset/findinset.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 findinset 16 17 import ( 18 "strings" 19 ) 20 21 func findInStrList(str, strlist string) uint64 { 22 for j, s := range strings.Split(strlist, ",") { 23 if s == str { 24 return uint64(j + 1) 25 } 26 } 27 return 0 28 } 29 30 func FindInSet(lv, rv []string, rs []uint64) []uint64 { 31 for i := range lv { 32 rs[i] = findInStrList(lv[i], rv[i]) 33 } 34 return rs 35 } 36 37 func FindInSetWithLeftConst(lv string, rv []string, rs []uint64) []uint64 { 38 for i := range rv { 39 rs[i] = findInStrList(lv, rv[i]) 40 } 41 return rs 42 } 43 44 func FindInSetWithRightConst(lv []string, rv string, rs []uint64) []uint64 { 45 for i := range lv { 46 rs[i] = findInStrList(lv[i], rv) 47 } 48 return rs 49 } 50 51 func FindInSetWithAllConst(lv, rv string, rs []uint64) []uint64 { 52 rs[0] = findInStrList(lv, rv) 53 return rs 54 }