github.com/matrixorigin/matrixone@v0.7.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/RoaringBitmap/roaring/roaring64" 20 ) 21 22 func BM32Window(bm *roaring.Bitmap, start, end int) *roaring.Bitmap { 23 new := roaring.NewBitmap() 24 if bm == nil || bm.IsEmpty() { 25 return new 26 } 27 iterator := bm.Iterator() 28 for iterator.HasNext() { 29 n := iterator.Next() 30 if uint32(start) <= n { 31 if n >= uint32(end) { 32 break 33 } 34 new.Add(n - uint32(start)) 35 } 36 } 37 return new 38 } 39 40 func BM64Window(bm *roaring64.Bitmap, start, end int) *roaring64.Bitmap { 41 new := roaring64.NewBitmap() 42 if bm == nil || bm.IsEmpty() { 43 return new 44 } 45 iterator := bm.Iterator() 46 for iterator.HasNext() { 47 n := iterator.Next() 48 if uint64(start) <= n { 49 if n >= uint64(end) { 50 break 51 } 52 new.Add(n - uint64(start)) 53 } 54 } 55 return new 56 }