build
00000
----
00000
Binary representation:
bitmap
 └── 0-1: x 01 # zero bitmap encoding

build offset=3
00000
----
00000
Binary representation:
bitmap
 ├── 0-3: x 000000 # initial offset
 └── 3-4: x 01     # zero bitmap encoding

build invert
00000
----
11111
Binary representation:
bitmap
 ├── 00-01: x 00                                                               # default bitmap encoding
 ├── 01-08: x 00000000000000                                                   # padding to align to 64-bit boundary
 ├── 08-16: b 0001111100000000000000000000000000000000000000000000000000000000 # bitmap word 0
 └── 16-24: b 0000000100000000000000000000000000000000000000000000000000000000 # bitmap summary word 0-63

build invert offset=3
00000
----
11111
Binary representation:
bitmap
 ├── 00-03: x 000000                                                           # initial offset
 ├── 03-04: x 00                                                               # default bitmap encoding
 ├── 04-08: x 00000000                                                         # padding to align to 64-bit boundary
 ├── 08-16: b 0001111100000000000000000000000000000000000000000000000000000000 # bitmap word 0
 └── 16-24: b 0000000100000000000000000000000000000000000000000000000000000000 # bitmap summary word 0-63

# An inverted bitmap never uses the zero encoding.
build invert
11111
----
00000
Binary representation:
bitmap
 ├── 00-01: x 00                                                               # default bitmap encoding
 ├── 01-08: x 00000000000000                                                   # padding to align to 64-bit boundary
 ├── 08-16: b 0000000000000000000000000000000000000000000000000000000000000000 # bitmap word 0
 └── 16-24: b 0000000000000000000000000000000000000000000000000000000000000000 # bitmap summary word 0-63

build rows=100
0
----
0000000000000000000000000000000000000000000000000000000000000000
000000000000000000000000000000000000
Binary representation:
bitmap
 └── 0-1: x 01 # zero bitmap encoding

build
10101011100011100
----
10101011100011100
Binary representation:
bitmap
 ├── 00-01: x 00                                                               # default bitmap encoding
 ├── 01-08: x 00000000000000                                                   # padding to align to 64-bit boundary
 ├── 08-16: b 1101010101110001000000000000000000000000000000000000000000000000 # bitmap word 0
 └── 16-24: b 0000000100000000000000000000000000000000000000000000000000000000 # bitmap summary word 0-63

seek-set-ge indexes=(0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16)
----
bitmap.SeekSetBitGE(0) = 0
bitmap.SeekSetBitGE(1) = 2
bitmap.SeekSetBitGE(2) = 2
bitmap.SeekSetBitGE(3) = 4
bitmap.SeekSetBitGE(4) = 4
bitmap.SeekSetBitGE(5) = 6
bitmap.SeekSetBitGE(6) = 6
bitmap.SeekSetBitGE(7) = 7
bitmap.SeekSetBitGE(8) = 8
bitmap.SeekSetBitGE(9) = 12
bitmap.SeekSetBitGE(10) = 12
bitmap.SeekSetBitGE(11) = 12
bitmap.SeekSetBitGE(12) = 12
bitmap.SeekSetBitGE(13) = 13
bitmap.SeekSetBitGE(14) = 14
bitmap.SeekSetBitGE(15) = 17
bitmap.SeekSetBitGE(16) = 17

seek-set-le indexes=(0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16)
----
bitmap.SeekSetBitLE(0) = 0
bitmap.SeekSetBitLE(1) = 0
bitmap.SeekSetBitLE(2) = 2
bitmap.SeekSetBitLE(3) = 2
bitmap.SeekSetBitLE(4) = 4
bitmap.SeekSetBitLE(5) = 4
bitmap.SeekSetBitLE(6) = 6
bitmap.SeekSetBitLE(7) = 7
bitmap.SeekSetBitLE(8) = 8
bitmap.SeekSetBitLE(9) = 8
bitmap.SeekSetBitLE(10) = 8
bitmap.SeekSetBitLE(11) = 8
bitmap.SeekSetBitLE(12) = 12
bitmap.SeekSetBitLE(13) = 13
bitmap.SeekSetBitLE(14) = 14
bitmap.SeekSetBitLE(15) = 14
bitmap.SeekSetBitLE(16) = 14

seek-unset-ge indexes=(0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16)
----
bitmap.SeekUnsetBitGE(0) = 1
bitmap.SeekUnsetBitGE(1) = 1
bitmap.SeekUnsetBitGE(2) = 3
bitmap.SeekUnsetBitGE(3) = 3
bitmap.SeekUnsetBitGE(4) = 5
bitmap.SeekUnsetBitGE(5) = 5
bitmap.SeekUnsetBitGE(6) = 9
bitmap.SeekUnsetBitGE(7) = 9
bitmap.SeekUnsetBitGE(8) = 9
bitmap.SeekUnsetBitGE(9) = 9
bitmap.SeekUnsetBitGE(10) = 10
bitmap.SeekUnsetBitGE(11) = 11
bitmap.SeekUnsetBitGE(12) = 15
bitmap.SeekUnsetBitGE(13) = 15
bitmap.SeekUnsetBitGE(14) = 15
bitmap.SeekUnsetBitGE(15) = 15
bitmap.SeekUnsetBitGE(16) = 16

seek-unset-le indexes=(0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16)
----
bitmap.SeekUnsetBitLE(0) = -1
bitmap.SeekUnsetBitLE(1) = 1
bitmap.SeekUnsetBitLE(2) = 1
bitmap.SeekUnsetBitLE(3) = 3
bitmap.SeekUnsetBitLE(4) = 3
bitmap.SeekUnsetBitLE(5) = 5
bitmap.SeekUnsetBitLE(6) = 5
bitmap.SeekUnsetBitLE(7) = 5
bitmap.SeekUnsetBitLE(8) = 5
bitmap.SeekUnsetBitLE(9) = 9
bitmap.SeekUnsetBitLE(10) = 10
bitmap.SeekUnsetBitLE(11) = 11
bitmap.SeekUnsetBitLE(12) = 11
bitmap.SeekUnsetBitLE(13) = 11
bitmap.SeekUnsetBitLE(14) = 11
bitmap.SeekUnsetBitLE(15) = 15
bitmap.SeekUnsetBitLE(16) = 16

build offset=1
10101011100011100
----
10101011100011100
Binary representation:
bitmap
 ├── 00-01: x 00                                                               # initial offset
 ├── 01-02: x 00                                                               # default bitmap encoding
 ├── 02-08: x 000000000000                                                     # padding to align to 64-bit boundary
 ├── 08-16: b 1101010101110001000000000000000000000000000000000000000000000000 # bitmap word 0
 └── 16-24: b 0000000100000000000000000000000000000000000000000000000000000000 # bitmap summary word 0-63

# Test calling Invert() before finishing.

build invert
10101011100011100
----
01010100011100011
Binary representation:
bitmap
 ├── 00-01: x 00                                                               # default bitmap encoding
 ├── 01-08: x 00000000000000                                                   # padding to align to 64-bit boundary
 ├── 08-16: b 0010101010001110000000010000000000000000000000000000000000000000 # bitmap word 0
 └── 16-24: b 0000000100000000000000000000000000000000000000000000000000000000 # bitmap summary word 0-63

build invert offset=1
10101011100011100
----
01010100011100011
Binary representation:
bitmap
 ├── 00-01: x 00                                                               # initial offset
 ├── 01-02: x 00                                                               # default bitmap encoding
 ├── 02-08: x 000000000000                                                     # padding to align to 64-bit boundary
 ├── 08-16: b 0010101010001110000000010000000000000000000000000000000000000000 # bitmap word 0
 └── 16-24: b 0000000100000000000000000000000000000000000000000000000000000000 # bitmap summary word 0-63

build
1
----
1
Binary representation:
bitmap
 ├── 00-01: x 00                                                               # default bitmap encoding
 ├── 01-08: x 00000000000000                                                   # padding to align to 64-bit boundary
 ├── 08-16: b 0000000100000000000000000000000000000000000000000000000000000000 # bitmap word 0
 └── 16-24: b 0000000100000000000000000000000000000000000000000000000000000000 # bitmap summary word 0-63

# Test sparseness; relying on the tailing bits being implicitly zeroed.

build rows=512
1
----
1000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
Binary representation:
bitmap
 ├── 00-01: x 00                                                               # default bitmap encoding
 ├── 01-08: x 00000000000000                                                   # padding to align to 64-bit boundary
 ├── 08-16: b 0000000100000000000000000000000000000000000000000000000000000000 # bitmap word 0
 ├── 16-24: b 0000000000000000000000000000000000000000000000000000000000000000 # bitmap word 1
 ├── 24-32: b 0000000000000000000000000000000000000000000000000000000000000000 # bitmap word 2
 ├── 32-40: b 0000000000000000000000000000000000000000000000000000000000000000 # bitmap word 3
 ├── 40-48: b 0000000000000000000000000000000000000000000000000000000000000000 # bitmap word 4
 ├── 48-56: b 0000000000000000000000000000000000000000000000000000000000000000 # bitmap word 5
 ├── 56-64: b 0000000000000000000000000000000000000000000000000000000000000000 # bitmap word 6
 ├── 64-72: b 0000000000000000000000000000000000000000000000000000000000000000 # bitmap word 7
 └── 72-80: b 0000000100000000000000000000000000000000000000000000000000000000 # bitmap summary word 0-63

build invert
1
----
0
Binary representation:
bitmap
 ├── 00-01: x 00                                                               # default bitmap encoding
 ├── 01-08: x 00000000000000                                                   # padding to align to 64-bit boundary
 ├── 08-16: b 0000000000000000000000000000000000000000000000000000000000000000 # bitmap word 0
 └── 16-24: b 0000000000000000000000000000000000000000000000000000000000000000 # bitmap summary word 0-63

# Test sparseness with inversion, relying on the trailing bits being implicitly
# set to one.

build invert rows=512
1
----
0111111111111111111111111111111111111111111111111111111111111111
1111111111111111111111111111111111111111111111111111111111111111
1111111111111111111111111111111111111111111111111111111111111111
1111111111111111111111111111111111111111111111111111111111111111
1111111111111111111111111111111111111111111111111111111111111111
1111111111111111111111111111111111111111111111111111111111111111
1111111111111111111111111111111111111111111111111111111111111111
1111111111111111111111111111111111111111111111111111111111111111
Binary representation:
bitmap
 ├── 00-01: x 00                                                               # default bitmap encoding
 ├── 01-08: x 00000000000000                                                   # padding to align to 64-bit boundary
 ├── 08-16: b 1111111011111111111111111111111111111111111111111111111111111111 # bitmap word 0
 ├── 16-24: b 1111111111111111111111111111111111111111111111111111111111111111 # bitmap word 1
 ├── 24-32: b 1111111111111111111111111111111111111111111111111111111111111111 # bitmap word 2
 ├── 32-40: b 1111111111111111111111111111111111111111111111111111111111111111 # bitmap word 3
 ├── 40-48: b 1111111111111111111111111111111111111111111111111111111111111111 # bitmap word 4
 ├── 48-56: b 1111111111111111111111111111111111111111111111111111111111111111 # bitmap word 5
 ├── 56-64: b 1111111111111111111111111111111111111111111111111111111111111111 # bitmap word 6
 ├── 64-72: b 1111111111111111111111111111111111111111111111111111111111111111 # bitmap word 7
 └── 72-80: b 1111111100000000000000000000000000000000000000000000000000000000 # bitmap summary word 0-63

# 32-bits wide

build
1010101010111111111110000001110
----
1010101010111111111110000001110
Binary representation:
bitmap
 ├── 00-01: x 00                                                               # default bitmap encoding
 ├── 01-08: x 00000000000000                                                   # padding to align to 64-bit boundary
 ├── 08-16: b 0101010111111101000111110011100000000000000000000000000000000000 # bitmap word 0
 └── 16-24: b 0000000100000000000000000000000000000000000000000000000000000000 # bitmap summary word 0-63

# 33-bits wide

build
10101010101111111111100000011101
----
10101010101111111111100000011101
Binary representation:
bitmap
 ├── 00-01: x 00                                                               # default bitmap encoding
 ├── 01-08: x 00000000000000                                                   # padding to align to 64-bit boundary
 ├── 08-16: b 0101010111111101000111111011100000000000000000000000000000000000 # bitmap word 0
 └── 16-24: b 0000000100000000000000000000000000000000000000000000000000000000 # bitmap summary word 0-63

# 64-bits wide

build
1010101010111111111110000001110101010101011111111111000000111011
----
1010101010111111111110000001110101010101011111111111000000111011
Binary representation:
bitmap
 ├── 00-01: x 00                                                               # default bitmap encoding
 ├── 01-08: x 00000000000000                                                   # padding to align to 64-bit boundary
 ├── 08-16: b 0101010111111101000111111011100010101010111111100000111111011100 # bitmap word 0
 └── 16-24: b 0000000100000000000000000000000000000000000000000000000000000000 # bitmap summary word 0-63

# 63-bits wide

build
101010101011111111111000000111010101010101111111111100000011101
----
101010101011111111111000000111010101010101111111111100000011101
Binary representation:
bitmap
 ├── 00-01: x 00                                                               # default bitmap encoding
 ├── 01-08: x 00000000000000                                                   # padding to align to 64-bit boundary
 ├── 08-16: b 0101010111111101000111111011100010101010111111100000111101011100 # bitmap word 0
 └── 16-24: b 0000000100000000000000000000000000000000000000000000000000000000 # bitmap summary word 0-63

# 65-bits wide

build
1010101010111111111110000001110101010101011111111111000000111011
1
----
1010101010111111111110000001110101010101011111111111000000111011
1
Binary representation:
bitmap
 ├── 00-01: x 00                                                               # default bitmap encoding
 ├── 01-08: x 00000000000000                                                   # padding to align to 64-bit boundary
 ├── 08-16: b 0101010111111101000111111011100010101010111111100000111111011100 # bitmap word 0
 ├── 16-24: b 0000000100000000000000000000000000000000000000000000000000000000 # bitmap word 1
 └── 24-32: b 0000001100000000000000000000000000000000000000000000000000000000 # bitmap summary word 0-63

build
1111111111111111111111111111111111111111111111111111111111111111
1111111111111111111111111111111111111111111111111111111111111111
1111111111111111111111111111111111111111111111111111111111111111
1111111111111111111111111111111111111111111111111111111111111111
1111111111111111111111111111111111111111111111111111111111111111
----
1111111111111111111111111111111111111111111111111111111111111111
1111111111111111111111111111111111111111111111111111111111111111
1111111111111111111111111111111111111111111111111111111111111111
1111111111111111111111111111111111111111111111111111111111111111
1111111111111111111111111111111111111111111111111111111111111111
Binary representation:
bitmap
 ├── 00-01: x 00                                                               # default bitmap encoding
 ├── 01-08: x 00000000000000                                                   # padding to align to 64-bit boundary
 ├── 08-16: b 1111111111111111111111111111111111111111111111111111111111111111 # bitmap word 0
 ├── 16-24: b 1111111111111111111111111111111111111111111111111111111111111111 # bitmap word 1
 ├── 24-32: b 1111111111111111111111111111111111111111111111111111111111111111 # bitmap word 2
 ├── 32-40: b 1111111111111111111111111111111111111111111111111111111111111111 # bitmap word 3
 ├── 40-48: b 1111111111111111111111111111111111111111111111111111111111111111 # bitmap word 4
 └── 48-56: b 0001111100000000000000000000000000000000000000000000000000000000 # bitmap summary word 0-63

build
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
----
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
Binary representation:
bitmap
 └── 0-1: x 01 # zero bitmap encoding

build
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000001
----
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000001
Binary representation:
bitmap
 ├── 00-01: x 00                                                               # default bitmap encoding
 ├── 01-08: x 00000000000000                                                   # padding to align to 64-bit boundary
 ├── 08-16: b 0000000000000000000000000000000000000000000000000000000000000000 # bitmap word 0
 ├── 16-24: b 0000000000000000000000000000000000000000000000000000000000000000 # bitmap word 1
 ├── 24-32: b 0000000000000000000000000000000000000000000000000000000000000000 # bitmap word 2
 ├── 32-40: b 0000000000000000000000000000000000000000000000000000000000000000 # bitmap word 3
 ├── 40-48: b 0000000000000000000000000000000000000000000000000000000010000000 # bitmap word 4
 └── 48-56: b 0001000000000000000000000000000000000000000000000000000000000000 # bitmap summary word 0-63

# Write out one fewer row than is set, which should result in the all-zeroes
# encoding.

build rows=319
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000001
----
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
000000000000000000000000000000000000000000000000000000000000000
Binary representation:
bitmap
 └── 0-1: x 01 # zero bitmap encoding

# Write out fewer rows than we set. The bitmap summary should reflect the
# truncated view of the bitmap.

build rows=260
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000111000000000000000000000000000000000000000000000000000
0000000000111000000000000000000000000000000000000000000000000000
----
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000111000000000000000000000000000000000000000000000000000
0000
Binary representation:
bitmap
 ├── 00-01: x 00                                                               # default bitmap encoding
 ├── 01-08: x 00000000000000                                                   # padding to align to 64-bit boundary
 ├── 08-16: b 0000000000000000000000000000000000000000000000000000000000000000 # bitmap word 0
 ├── 16-24: b 0000000000000000000000000000000000000000000000000000000000000000 # bitmap word 1
 ├── 24-32: b 0000000000000000000000000000000000000000000000000000000000000000 # bitmap word 2
 ├── 32-40: b 0000000000011100000000000000000000000000000000000000000000000000 # bitmap word 3
 ├── 40-48: b 0000000000000000000000000000000000000000000000000000000000000000 # bitmap word 4
 └── 48-56: b 0000100000000000000000000000000000000000000000000000000000000000 # bitmap summary word 0-63

# Test a case where we invert a bitmap that has more words than we'll need in
# the finished serialized bitmap. Regression test for a bug that caused us to
# pass a negative number into slices.Grow.

build rows=64 invert
0000000000000000000000000000000000000000000000000000000000000000
1
----
1111111111111111111111111111111111111111111111111111111111111111
Binary representation:
bitmap
 ├── 00-01: x 00                                                               # default bitmap encoding
 ├── 01-08: x 00000000000000                                                   # padding to align to 64-bit boundary
 ├── 08-16: b 1111111111111111111111111111111111111111111111111111111111111111 # bitmap word 0
 └── 16-24: b 0000000100000000000000000000000000000000000000000000000000000000 # bitmap summary word 0-63
