github.com/matrixorigin/matrixone@v0.7.0/pkg/vm/engine/tae/mergesort/func.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 mergesort 16 17 import ( 18 "github.com/matrixorigin/matrixone/pkg/vm/engine/tae/containers" 19 ) 20 21 func Shuffle(col containers.Vector, idx []uint32) containers.Vector { 22 ret := containers.MakeVector(col.GetType(), col.Nullable()) 23 for _, j := range idx { 24 ret.Append(col.Get(int(j))) 25 } 26 col.Close() 27 return ret 28 } 29 30 func Multiplex(col []containers.Vector, src []uint32, fromLayout, toLayout []uint32) (ret []containers.Vector) { 31 ret = make([]containers.Vector, len(toLayout)) 32 cursors := make([]int, len(fromLayout)) 33 34 k := 0 35 for i := 0; i < len(toLayout); i++ { 36 ret[i] = containers.MakeVector(col[0].GetType(), col[0].Nullable()) 37 for j := 0; j < int(toLayout[i]); j++ { 38 s := src[k] 39 ret[i].Append(col[s].Get(cursors[s])) 40 cursors[s]++ 41 k++ 42 } 43 } 44 45 for _, v := range col { 46 v.Close() 47 } 48 return 49 }