github.com/matrixorigin/matrixone@v0.7.0/pkg/compare/types.go (about)

     1  // Copyright 2021 - 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 compare
    16  
    17  import (
    18  	"github.com/matrixorigin/matrixone/pkg/container/nulls"
    19  	"github.com/matrixorigin/matrixone/pkg/container/vector"
    20  	"github.com/matrixorigin/matrixone/pkg/vm/process"
    21  )
    22  
    23  type Compare interface {
    24  	Vector() *vector.Vector
    25  	Set(int, *vector.Vector)
    26  	Compare(int, int, int64, int64) int
    27  	Copy(int, int, int64, int64, *process.Process) error
    28  }
    29  
    30  type compare[T any] struct {
    31  	xs        [][]T
    32  	cmp       func(T, T) int
    33  	ns        []*nulls.Nulls
    34  	vs        []*vector.Vector
    35  	cpy       func([]T, []T, int64, int64)
    36  	nullsLast bool
    37  }
    38  
    39  type strCompare struct {
    40  	desc      bool
    41  	nullsLast bool
    42  	vs        []*vector.Vector
    43  }
    44  
    45  func nullsCompare(n1, n2 *nulls.Nulls, i1, i2 int64, nullsLast bool) int {
    46  	if nulls.Contains(n1, uint64(i1)) {
    47  		if nulls.Contains(n2, uint64(i2)) {
    48  			return 0
    49  		} else {
    50  			if nullsLast {
    51  				return 1
    52  			} else {
    53  				return -1
    54  			}
    55  		}
    56  	} else {
    57  		if nulls.Contains(n2, uint64(i2)) {
    58  			if nullsLast {
    59  				return -1
    60  			} else {
    61  				return 1
    62  			}
    63  		} else {
    64  			return 0
    65  		}
    66  	}
    67  }