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