From 51f7fb653a12ccc3f109022c90b761208fb4a582 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E5=BD=95=E7=A5=A5?= Date: Tue, 11 Jun 2024 17:58:46 +0800 Subject: [PATCH 1/2] fix bis.compareValue --- BitSliceIndexing/bsi.go | 40 ++++++++++++++++++++++++++++++++++------ 1 file changed, 34 insertions(+), 6 deletions(-) diff --git a/BitSliceIndexing/bsi.go b/BitSliceIndexing/bsi.go index a1521b66..63372b60 100644 --- a/BitSliceIndexing/bsi.go +++ b/BitSliceIndexing/bsi.go @@ -277,8 +277,29 @@ func compareValue(e *task, batch []uint32, resultsChan chan *roaring.Bitmap, wg if e.bsi.runOptimized { results.RunOptimize() } - - x := e.bsi.BitCount() + if len(batch) == 0 { + resultsChan <- results + return + } + //以下代码解决在bsi没有设置max或者compare的值超过了max的时候该函数返回的结果不准确的问题 + /***********************************************************************/ + var x int + if e.op == RANGE { + //如果操作是range并且end的位数比ba的长度大,则x设为end的位数 + if bits.Len64(uint64(e.end)) > e.bsi.BitCount() { + x = bits.Len64(uint64(e.end)) + } else { + x = e.bsi.BitCount() + } + } else { + //如果操作不是range并且value位数比ba的长度大,则x设为value的位数 + if bits.Len64(uint64(e.valueOrStart)) > e.bsi.BitCount() { + x = bits.Len64(uint64(e.valueOrStart)) + } else { + x = e.bsi.BitCount() + } + } + /***********************************************************************/ startIsNegative := x == 64 && uint64(e.valueOrStart)&(1< 0 endIsNegative := x == 64 && uint64(e.end)&(1< 0 @@ -286,10 +307,12 @@ func compareValue(e *task, batch []uint32, resultsChan chan *roaring.Bitmap, wg cID := batch[i] eq1, eq2 := true, true lt1, lt2, gt1 := false, false, false - j := e.bsi.BitCount() - 1 + j := x - 1 isNegative := false if x == 64 { - isNegative = e.bsi.bA[j].Contains(cID) + if j < e.bsi.BitCount() { + isNegative = e.bsi.bA[j].Contains(cID) + } j-- } compStartValue := e.valueOrStart @@ -301,8 +324,13 @@ func compareValue(e *task, batch []uint32, resultsChan chan *roaring.Bitmap, wg compEndValue = ^e.end + 1 } for ; j >= 0; j-- { - sliceContainsBit := e.bsi.bA[j].Contains(cID) - + var sliceContainsBit bool + //j的值可能比ba的长度大,所以增加了以下判断 + if e.bsi.BitCount() <= j { + sliceContainsBit = false + } else { + sliceContainsBit = e.bsi.bA[j].Contains(cID) + } if uint64(compStartValue)&(1< 0 { // BIT in value is SET if !sliceContainsBit { From 8d9101b2a04749e3e9790b67a96bff12372e6992 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E5=BD=95=E7=A5=A5?= Date: Wed, 12 Jun 2024 09:04:01 +0800 Subject: [PATCH 2/2] fix bis.compareValue --- BitSliceIndexing/bsi.go | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/BitSliceIndexing/bsi.go b/BitSliceIndexing/bsi.go index 63372b60..01d3cb21 100644 --- a/BitSliceIndexing/bsi.go +++ b/BitSliceIndexing/bsi.go @@ -281,25 +281,23 @@ func compareValue(e *task, batch []uint32, resultsChan chan *roaring.Bitmap, wg resultsChan <- results return } - //以下代码解决在bsi没有设置max或者compare的值超过了max的时候该函数返回的结果不准确的问题 - /***********************************************************************/ + //The following code solves the problem of inaccurate results returned by the function when bsi is not set to max or the value of compare exceeds max var x int if e.op == RANGE { - //如果操作是range并且end的位数比ba的长度大,则x设为end的位数 + //If the operation is range and the number of bits in end is greater than the length of ba, then x is set to the number of bits in end if bits.Len64(uint64(e.end)) > e.bsi.BitCount() { x = bits.Len64(uint64(e.end)) } else { x = e.bsi.BitCount() } } else { - //如果操作不是range并且value位数比ba的长度大,则x设为value的位数 + //If the operation is not range and the number of value bits is greater than the length of ba, then x is set to the number of value bits if bits.Len64(uint64(e.valueOrStart)) > e.bsi.BitCount() { x = bits.Len64(uint64(e.valueOrStart)) } else { x = e.bsi.BitCount() } } - /***********************************************************************/ startIsNegative := x == 64 && uint64(e.valueOrStart)&(1< 0 endIsNegative := x == 64 && uint64(e.end)&(1< 0 @@ -325,7 +323,7 @@ func compareValue(e *task, batch []uint32, resultsChan chan *roaring.Bitmap, wg } for ; j >= 0; j-- { var sliceContainsBit bool - //j的值可能比ba的长度大,所以增加了以下判断 + //The value of j may be larger than the length of ba, so the following judgment has been added if e.bsi.BitCount() <= j { sliceContainsBit = false } else {