Skip to content

Commit 794cd71

Browse files
committed
made rangeend = 0 as unlimited in rb64_fill,rb64_clear,rb64_flip,rb64_range,rb64_range_cardinality and rb64_select
1 parent e10b548 commit 794cd71

File tree

6 files changed

+47
-33
lines changed

6 files changed

+47
-33
lines changed

README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -826,39 +826,39 @@ or
826826
<td><code>rb64_fill</code></td>
827827
<td><code>roaringbitmap64,range_start bigint,range_end bigint</code></td>
828828
<td><code>roaringbitmap64</code></td>
829-
<td>Fill the specified range (not include the range_end),negative range value will be internally converted to unsigned int64</td>
829+
<td>Fill the specified range (not include the range_end),negative range value will be internally converted to unsigned int64, and range_end = 0 means unlimited</td>
830830
<td><code>rb64_fill('{1,2,3}',5,7)</code></td>
831831
<td><code>{1,2,3,5,6}</code></td>
832832
</tr>
833833
<tr>
834834
<td><code>rb64_clear</code></td>
835835
<td><code>roaringbitmap64,range_start bigint,range_end bigint</code></td>
836836
<td><code>roaringbitmap64</code></td>
837-
<td>Clear the specified range (not include the range_end),negative range value will be internally converted to unsigned int64</td>
837+
<td>Clear the specified range (not include the range_end),negative range value will be internally converted to unsigned int64, and range_end = 0 means unlimited</td>
838838
<td><code>rb64_clear('{1,2,3}',2,3)</code></td>
839839
<td><code>{1,3}</code></td>
840840
</tr>
841841
<tr>
842842
<td><code>rb64_flip</code></td>
843843
<td><code>roaringbitmap64,range_start bigint,range_end bigint</code></td>
844844
<td><code>roaringbitmap64</code></td>
845-
<td>Negative the specified range (not include the range_end),negative range value will be internally converted to unsigned int64</td>
845+
<td>Negative the specified range (not include the range_end),negative range value will be internally converted to unsigned int64, and range_end = 0 means unlimited</td>
846846
<td><code>rb64_flip('{1,2,3}',2,10)</code></td>
847847
<td><code>{1,4,5,6,7,8,9}</code></td>
848848
</tr>
849849
<tr>
850850
<td><code>rb64_range</code></td>
851851
<td><code>roaringbitmap64,range_start bigint,range_end bigint</code></td>
852852
<td><code>roaringbitmap64</code></td>
853-
<td>Return new set with specified range (not include the range_end),negative range value will be internally converted to unsigned int64</td>
853+
<td>Return new set with specified range (not include the range_end),negative range value will be internally converted to unsigned int64, and range_end = 0 means unlimited</td>
854854
<td><code>rb64_range('{1,2,3}',2,3)</code></td>
855855
<td><code>{2}</code></td>
856856
</tr>
857857
<tr>
858858
<td><code>rb64_range_cardinality</code></td>
859859
<td><code>roaringbitmap64,range_start bigint,range_end bigint</code></td>
860860
<td><code>bigint</code></td>
861-
<td>Return the cardinality of specified range (not include the range_end),negative range value will be internally converted to unsigned int64</td>
861+
<td>Return the cardinality of specified range (not include the range_end),negative range value will be internally converted to unsigned int64, and range_end = 0 means unlimited</td>
862862
<td><code>rb64_range_cardinality('{1,2,3}',2,3)</code></td>
863863
<td><code>1</code></td>
864864
</tr>
@@ -898,7 +898,7 @@ or
898898
<td><code>rb64_select</code></td>
899899
<td><code>roaringbitmap64,bitset_limit bigint,bitset_offset bigint=0,reverse boolean=false,range_start bigint=0,range_end bigint=-1</code></td>
900900
<td><code>roaringbitmap64</code></td>
901-
<td>Return subset [bitset_offset,bitset_offset+bitset_limit) of bitmap between range [range_start,range_end),negative range value will be internally converted to unsigned int64</td>
901+
<td>Return subset [bitset_offset,bitset_offset+bitset_limit) of bitmap between range [range_start,range_end),negative range value will be internally converted to unsigned int64, and range_end = 0 means unlimited</td>
902902
<td><code>rb64_select('{1,2,3,4,5,6,7,8,9}',5,2)</code></td>
903903
<td><code>{3,4,5,6,7}</code></td>
904904
</tr>

expected/roaringbitmap64.out

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1682,13 +1682,13 @@ select rb64_remove('{1,10,100,9223372036854775807,-9223372036854775808,-1}',-922
16821682
{1,10,100,9223372036854775807,-1}
16831683
(1 row)
16841684

1685-
select rb64_fill(NULL,0,0);
1685+
select rb64_fill(NULL,-1,-1);
16861686
rb64_fill
16871687
-----------
16881688

16891689
(1 row)
16901690

1691-
select rb64_fill('{}',0,0);
1691+
select rb64_fill('{}',-1,-1);
16921692
rb64_fill
16931693
-----------
16941694
{}
@@ -1736,7 +1736,7 @@ select rb64_fill('{1,10,100}',10,20);
17361736
{1,10,11,12,13,14,15,16,17,18,19,100}
17371737
(1 row)
17381738

1739-
select rb64_fill('{1,10,100}',0,0);
1739+
select rb64_fill('{1,10,100}',-1,-1);
17401740
rb64_fill
17411741
------------
17421742
{1,10,100}
@@ -1916,7 +1916,7 @@ select rb64_flip('{1,10,100}',-3,3);
19161916
{1,10,100}
19171917
(1 row)
19181918

1919-
select rb64_flip('{1,10,100}',0,0);
1919+
select rb64_flip('{1,10,100}',-1,-1);
19201920
rb64_flip
19211921
------------
19221922
{1,10,100}
@@ -2024,6 +2024,12 @@ select rb64_range('{0,1,10,100,-2,-1}',1,9223372036854775807);
20242024
{1,10,100}
20252025
(1 row)
20262026

2027+
select rb64_range('{0,1,10,100,-2,-1}',1,0);
2028+
rb64_range
2029+
------------------
2030+
{1,10,100,-2,-1}
2031+
(1 row)
2032+
20272033
select rb64_range_cardinality(NULL,0,10);
20282034
rb64_range_cardinality
20292035
------------------------
@@ -2096,6 +2102,12 @@ select rb64_range_cardinality('{0,1,10,100,-2,-1}',1,9223372036854775807);
20962102
3
20972103
(1 row)
20982104

2105+
select rb64_range_cardinality('{0,1,10,100,-2,-1}',1,0);
2106+
rb64_range_cardinality
2107+
------------------------
2108+
5
2109+
(1 row)
2110+
20992111
select rb64_select(NULL,10);
21002112
rb64_select
21012113
-------------
@@ -2139,15 +2151,15 @@ select rb64_select('{0,1,2,10,100,1000,9223372036854775807,-9223372036854775808,
21392151
(1 row)
21402152

21412153
select rb64_select('{0,1,2,10,100,1000,9223372036854775807,-9223372036854775808,-2,-1}',2,1,true);
2142-
rb64_select
2143-
--------------------------------------------
2144-
{9223372036854775807,-9223372036854775808}
2154+
rb64_select
2155+
---------------------------
2156+
{-9223372036854775808,-2}
21452157
(1 row)
21462158

21472159
select rb64_select('{0,1,2,10,100,1000,9223372036854775807,-9223372036854775808,-2,-1}',2,1,true,9);
2148-
rb64_select
2149-
--------------------------------------------
2150-
{9223372036854775807,-9223372036854775808}
2160+
rb64_select
2161+
---------------------------
2162+
{-9223372036854775808,-2}
21512163
(1 row)
21522164

21532165
select rb64_select('{0,1,2,10,100,1000,9223372036854775807,-9223372036854775808,-2,-1}',2,1,true,9,4294967295);

roaringbitmap--0.5--1.0.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ CREATE OR REPLACE FUNCTION rb64_jaccard_dist(roaringbitmap64, roaringbitmap64)
242242
AS 'MODULE_PATHNAME', 'rb64_jaccard_dist'
243243
LANGUAGE C STRICT IMMUTABLE PARALLEL SAFE;
244244

245-
CREATE OR REPLACE FUNCTION rb64_select(roaringbitmap64, bitset_limit bigint,bitset_offset bigint=0,reverse boolean=false,range_start bigint=0,range_end bigint=-1)
245+
CREATE OR REPLACE FUNCTION rb64_select(roaringbitmap64, bitset_limit bigint,bitset_offset bigint=0,reverse boolean=false,range_start bigint=0,range_end bigint=0)
246246
RETURNS roaringbitmap64
247247
AS 'MODULE_PATHNAME', 'rb64_select'
248248
LANGUAGE C STRICT IMMUTABLE PARALLEL SAFE;

roaringbitmap--1.0.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -726,7 +726,7 @@ CREATE OR REPLACE FUNCTION rb64_jaccard_dist(roaringbitmap64, roaringbitmap64)
726726
AS 'MODULE_PATHNAME', 'rb64_jaccard_dist'
727727
LANGUAGE C STRICT IMMUTABLE PARALLEL SAFE;
728728

729-
CREATE OR REPLACE FUNCTION rb64_select(roaringbitmap64, bitset_limit bigint,bitset_offset bigint=0,reverse boolean=false,range_start bigint=0,range_end bigint=-1)
729+
CREATE OR REPLACE FUNCTION rb64_select(roaringbitmap64, bitset_limit bigint,bitset_offset bigint=0,reverse boolean=false,range_start bigint=0,range_end bigint=0)
730730
RETURNS roaringbitmap64
731731
AS 'MODULE_PATHNAME', 'rb64_select'
732732
LANGUAGE C STRICT IMMUTABLE PARALLEL SAFE;

roaringbitmap64.c

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1087,8 +1087,8 @@ rb64_fill(PG_FUNCTION_ARGS) {
10871087
(errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED),
10881088
errmsg("bitmap format is error")));
10891089

1090-
if (rangestart < rangeend) {
1091-
roaring64_bitmap_add_range(r1,rangestart, rangeend);
1090+
if (rangestart < rangeend || rangeend == 0) {
1091+
roaring64_bitmap_add_range_closed(r1,rangestart, rangeend - 1);
10921092
}
10931093

10941094
expectedsize = roaring64_bitmap_portable_size_in_bytes(r1);
@@ -1119,8 +1119,8 @@ rb64_clear(PG_FUNCTION_ARGS) {
11191119
(errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED),
11201120
errmsg("bitmap format is error")));
11211121

1122-
if (rangestart < rangeend) {
1123-
roaring64_bitmap_remove_range(r1,rangestart, rangeend);
1122+
if (rangestart < rangeend || rangeend == 0) {
1123+
roaring64_bitmap_remove_range_closed(r1,rangestart, rangeend - 1);
11241124
}
11251125

11261126
expectedsize = roaring64_bitmap_portable_size_in_bytes(r1);
@@ -1151,8 +1151,8 @@ rb64_flip(PG_FUNCTION_ARGS) {
11511151
(errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED),
11521152
errmsg("bitmap format is error")));
11531153

1154-
if (rangestart < rangeend) {
1155-
roaring64_bitmap_flip_inplace(r1, rangestart, rangeend);
1154+
if (rangestart < rangeend || rangeend == 0) {
1155+
roaring64_bitmap_flip_closed_inplace(r1, rangestart, rangeend - 1);
11561156
}
11571157

11581158
expectedsize = roaring64_bitmap_portable_size_in_bytes(r1);
@@ -1259,7 +1259,7 @@ rb64_range(PG_FUNCTION_ARGS) {
12591259
roaring64_iterator_move_equalorlarger(iterator, rangestart);
12601260

12611261
while(roaring64_iterator_has_value(iterator)) {
1262-
if(roaring64_iterator_value(iterator) >= rangeend)
1262+
if(rangeend != 0 && roaring64_iterator_value(iterator) >= rangeend)
12631263
break;
12641264
roaring64_bitmap_add(r2, roaring64_iterator_value(iterator));
12651265
roaring64_iterator_advance(iterator);
@@ -1298,7 +1298,7 @@ rb64_range_cardinality(PG_FUNCTION_ARGS) {
12981298
iterator = roaring64_iterator_create(r1);
12991299
roaring64_iterator_move_equalorlarger(iterator, rangestart);
13001300
while(roaring64_iterator_has_value(iterator)) {
1301-
if(roaring64_iterator_value(iterator) >= rangeend)
1301+
if(rangeend != 0 && roaring64_iterator_value(iterator) >= rangeend)
13021302
break;
13031303
card1++;
13041304
roaring64_iterator_advance(iterator);
@@ -1350,7 +1350,7 @@ rb64_select(PG_FUNCTION_ARGS) {
13501350
roaring64_iterator_move_equalorlarger(iterator, rangestart);
13511351
if (!reverse) {
13521352
while (roaring64_iterator_has_value(iterator)) {
1353-
if ((roaring64_iterator_value(iterator) >= rangeend)
1353+
if ((rangeend != 0 && roaring64_iterator_value(iterator) >= rangeend)
13541354
|| count - offset >= limit)
13551355
break;
13561356
if (count >= offset) {
@@ -1361,7 +1361,7 @@ rb64_select(PG_FUNCTION_ARGS) {
13611361
}
13621362
} else {
13631363
while (roaring64_iterator_has_value(iterator)) {
1364-
if (roaring64_iterator_value(iterator) >= rangeend)
1364+
if (rangeend != 0 && roaring64_iterator_value(iterator) >= rangeend)
13651365
break;
13661366
roaring64_iterator_advance(iterator);
13671367
total_count++;
@@ -1376,7 +1376,7 @@ rb64_select(PG_FUNCTION_ARGS) {
13761376
roaring64_iterator_move_equalorlarger(iterator,rangestart);
13771377
count = 0;
13781378
while (roaring64_iterator_has_value(iterator)) {
1379-
if ((rangeend >= 0 && roaring64_iterator_value(iterator) >= rangeend)
1379+
if ((rangeend != 0 && roaring64_iterator_value(iterator) >= rangeend)
13801380
|| count - offset >= limit)
13811381
break;
13821382
if (count >= offset) {

sql/roaringbitmap64.sql

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -350,16 +350,16 @@ select rb64_remove('{1,10,100}',1);
350350
select rb64_remove('{1,10,100}',99);
351351
select rb64_remove('{1,10,100,9223372036854775807,-9223372036854775808,-1}',-9223372036854775808);
352352

353-
select rb64_fill(NULL,0,0);
354-
select rb64_fill('{}',0,0);
353+
select rb64_fill(NULL,-1,-1);
354+
select rb64_fill('{}',-1,-1);
355355
select rb64_fill('{}',0,1);
356356
select rb64_fill('{}',0,2);
357357
select rb64_fill('{1,10,100}',10,10);
358358
select rb64_fill('{1,10,100}',10,11);
359359
select rb64_fill('{1,10,100}',10,12);
360360
select rb64_fill('{1,10,100}',10,13);
361361
select rb64_fill('{1,10,100}',10,20);
362-
select rb64_fill('{1,10,100}',0,0);
362+
select rb64_fill('{1,10,100}',-1,-1);
363363
select rb64_fill('{1,10,100,9223372036854775807,-9223372036854775808,-1}',9223372036854775800,9223372036854775807);
364364
select rb64_cardinality(rb64_fill('{1,10,100}',2,1000000000));
365365
select rb64_cardinality(rb64_fill('{1,10,100}',0,5000000000));
@@ -392,7 +392,7 @@ select rb64_flip('{}',0,10);
392392
select rb64_flip('{1,10,100}',9,100);
393393
select rb64_flip('{1,10,100}',10,101);
394394
select rb64_flip('{1,10,100}',-3,3);
395-
select rb64_flip('{1,10,100}',0,0);
395+
select rb64_flip('{1,10,100}',-1,-1);
396396
select rb64_flip('{1,10,100}',9,9);
397397
select rb64_flip('{1,10,100,9223372036854775807,-9223372036854775808,-1}',9223372036854775800,9223372036854775807);
398398
select rb64_cardinality(rb64_flip('{1,10,100}',2,1000000000));
@@ -412,6 +412,7 @@ select rb64_range('{0,1,10,100,-2,-1}',1,4294967295);
412412
select rb64_range('{0,1,10,100,-2,-1}',0,4294967296);
413413
select rb64_range('{0,1,10,100,-2,-1}',9223372036854775800,9223372036854775807);
414414
select rb64_range('{0,1,10,100,-2,-1}',1,9223372036854775807);
415+
select rb64_range('{0,1,10,100,-2,-1}',1,0);
415416

416417
select rb64_range_cardinality(NULL,0,10);
417418
select rb64_range_cardinality('{}',0,10);
@@ -425,6 +426,7 @@ select rb64_range_cardinality('{0,1,10,100,-2,-1}',1,4294967295);
425426
select rb64_range_cardinality('{0,1,10,100,-2,-1}',0,4294967296);
426427
select rb64_range_cardinality('{0,1,10,100,-2,-1}',9223372036854775800,9223372036854775807);
427428
select rb64_range_cardinality('{0,1,10,100,-2,-1}',1,9223372036854775807);
429+
select rb64_range_cardinality('{0,1,10,100,-2,-1}',1,0);
428430

429431
select rb64_select(NULL,10);
430432
select rb64_select('{}',10);

0 commit comments

Comments
 (0)