github.com/matrixorigin/matrixone@v0.7.0/pkg/vm/engine/tae/common/hack.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 common 16 17 import ( 18 "fmt" 19 20 "github.com/matrixorigin/matrixone/pkg/container/types" 21 ) 22 23 func InplaceDeleteRowsFromSlice[T types.FixedSizeT](v any, rowGen RowGen) any { 24 if !rowGen.HasNext() { 25 return v 26 } 27 slice := v.([]T) 28 prevRow := -1 29 currPos := 0 30 for rowGen.HasNext() { 31 currRow := int(rowGen.Next()) 32 copy(slice[currPos:], slice[prevRow+1:currRow]) 33 currPos += currRow - prevRow - 1 34 prevRow = currRow 35 } 36 left := len(slice[prevRow+1:]) 37 copy(slice[currPos:], slice[prevRow+1:]) 38 currPos += left 39 return slice[:currPos] 40 } 41 42 func InplaceDeleteRows(orig any, rowGen RowGen) any { 43 if !rowGen.HasNext() { 44 return orig 45 } 46 47 switch arr := orig.(type) { 48 case []bool: 49 return InplaceDeleteRowsFromSlice[bool](arr, rowGen) 50 case []int8: 51 return InplaceDeleteRowsFromSlice[int8](arr, rowGen) 52 case []int16: 53 return InplaceDeleteRowsFromSlice[int16](arr, rowGen) 54 case []int32: 55 return InplaceDeleteRowsFromSlice[int32](arr, rowGen) 56 case []int64: 57 return InplaceDeleteRowsFromSlice[int64](arr, rowGen) 58 case []uint8: 59 return InplaceDeleteRowsFromSlice[uint8](arr, rowGen) 60 case []uint16: 61 return InplaceDeleteRowsFromSlice[uint16](arr, rowGen) 62 case []uint32: 63 return InplaceDeleteRowsFromSlice[uint32](arr, rowGen) 64 case []uint64: 65 return InplaceDeleteRowsFromSlice[uint64](arr, rowGen) 66 case []types.Timestamp: 67 return InplaceDeleteRowsFromSlice[types.Timestamp](arr, rowGen) 68 case []types.Decimal64: 69 return InplaceDeleteRowsFromSlice[types.Decimal64](arr, rowGen) 70 case []types.Decimal128: 71 return InplaceDeleteRowsFromSlice[types.Decimal128](arr, rowGen) 72 case []types.Uuid: 73 return InplaceDeleteRowsFromSlice[types.Uuid](arr, rowGen) 74 case []float32: 75 return InplaceDeleteRowsFromSlice[float32](arr, rowGen) 76 case []float64: 77 return InplaceDeleteRowsFromSlice[float64](arr, rowGen) 78 case []types.Date: 79 return InplaceDeleteRowsFromSlice[types.Date](arr, rowGen) 80 case []types.Datetime: 81 return InplaceDeleteRowsFromSlice[types.Datetime](arr, rowGen) 82 case []types.Time: 83 return InplaceDeleteRowsFromSlice[types.Time](arr, rowGen) 84 case []types.TS: 85 return InplaceDeleteRowsFromSlice[types.TS](arr, rowGen) 86 case []types.Rowid: 87 return InplaceDeleteRowsFromSlice[types.Rowid](arr, rowGen) 88 case []types.Varlena: 89 return InplaceDeleteRowsFromSlice[types.Varlena](arr, rowGen) 90 } 91 panic(fmt.Sprintf("not support: %T", orig)) 92 }