github.com/matrixorigin/matrixone@v1.2.0/pkg/vm/engine/tae/common/bitmap.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 common 16 17 import ( 18 "github.com/RoaringBitmap/roaring" 19 "github.com/matrixorigin/matrixone/pkg/container/nulls" 20 ) 21 22 func BitmapEqual(v1, v2 *nulls.Bitmap) bool { 23 if v1 == nil || v2 == nil { 24 return v1 == v2 25 } 26 if v1.GetCardinality() != v2.GetCardinality() { 27 return false 28 } 29 vals1 := v1.ToArray() 30 vals2 := v2.ToArray() 31 for i := range vals1 { 32 if vals1[i] != vals2[i] { 33 return false 34 } 35 } 36 return true 37 } 38 39 func RoaringToMOBitmap(bm *roaring.Bitmap) *nulls.Bitmap { 40 if bm == nil { 41 return nil 42 } 43 nbm := nulls.NewWithSize(int(bm.Maximum()) + 1) 44 iterator := bm.Iterator() 45 for iterator.HasNext() { 46 nbm.Add(uint64(iterator.Next())) 47 } 48 return nbm 49 } 50 51 func MOOrRoaringBitmap(bm *nulls.Bitmap, rbm *roaring.Bitmap) { 52 if bm == nil || rbm == nil { 53 return 54 } 55 iterator := rbm.Iterator() 56 for iterator.HasNext() { 57 bm.Add(uint64(iterator.Next())) 58 } 59 }