Files
mercury/tests/hard_coded/bitmap_test.exp
Julien Fischer f76e0407e5 Fix some error reporting in bitmap module.
The functions byte/2 and 'byte :='/2 both throw a bitmap_error/1 exception if
the given byte index is out of bounds.  The error message returned as part of
the exception reports the byte index that is out of bounds but then gives the
valid bounds of *bit* indexes in the bitmap.   There are two possible fixes:

     1. report the out of bounds index as the bit index of the start of the byte.
     2. report the valid bounds of the of byte indexes in the bitmap.

This change implements the latter.

Style and formatting fixes to the bitmap module.

library/bitmap.m:
     Make the above fix.

     Add separate predicates for reporting out of bounds bit and byte
     indexes.

     Do not provide erroneous functions that duplicate the functionality of,
     or forward their work, to erroneous predicates of the same name.

     Add the predicate is_empty/1.

     Remove some unnecessary module qualification.

     Use state variable notation in more spots.

tests/hard_coded/Mmakefile:
tests/hard_coded/bitmap_bytes.{m,exp}:
     Add a new test for byte lookups in bitmaps -- this wasn't covered
     by the existing test cases.

tests/hard_coded/bitmap_empty.exp:
tests/hard_coded/btimap_test.exp:
     Conform to the above changes.

NEWS:
     Announce the addition of bitmap.is_empty/1.
2017-12-29 00:44:51 -05:00

250 lines
18 KiB
Plaintext

Single byte bitmap
1111
yes
1011
no
1001
1001
0101
0101
Multi-byte bitmap
00000000.00000000.0000
01000000.00000000.0000
01010010.10101000.0100
1010010101
101010000100
01010001.01010111.1000
01010011.01010111.1000
10101100.10101000.0111
<32:ACA87FFF>
"<32:ACA87FFF>"
Longer bitmap
10111001.01000110.10111001.01000110.10111001.01000110.10111001.01000110.10111001.01000110.10111001.01000110.10111001.01000110.10111001.01000110.10111001.01000110.10111001.01000110
10111010.10111001.01111001.01000110.10111001.01000110.10111001.01000110.10111001.01000110.10111001.01000110.10111001.01000110.10111001.01000110.10111001.01000110.10111001.01000110
non-overlapping copy_bits
10111010.10111001.01111001.01000110.10111001.01000110.10111001.01000110.10010111.10010100.01101011.10010100.10111001.01000110.10111001.01000110.10111001.01000110.10111001.01000110
testing builtin.copy
10111010.10111001.01111001.01000110.10111001.01000110.10111001.01000110.10010111.10010100.01101011.10010100.10111001.01000110.10111001.01000110.10111001.01000110.10111001.01000110
Copy succeeded
Test simple aligned byte block copy.
Copy 8 64 32
Copy to zeroed bitmap
00000000.00000000.00000000.00000000.00000000.00000000.00000000.00000000.01000110.10111001.01000110.10111001.00000000.00000000.00000000.00000000.00000000.00000000.00000000.00000000.0000000
Copy to filled bitmap
11111111.11111111.11111111.11111111.11111111.11111111.11111111.11111111.01000110.10111001.01000110.10111001.11111111.11111111.11111111.11111111.11111111.11111111.11111111.11111111.1111111
Copy to alternating bitmap
10101010.01010101.10101010.01010101.10101010.01010101.10101010.01010101.01000110.10111001.01000110.10111001.10101010.01010101.10101010.01010101.10101010.01010101.10101010.01010101.0101010
Copy to same bitmap
10111001.01000110.10111001.01000110.10111001.01000110.10111001.01000110.01000110.10111001.01000110.10111001.10111001.01000110.10111001.01000110.10111001.01000110.10111001.01000110.0111001
Test byte block copy with extra bits on ends.
Copy 6 62 36
Copy to zeroed bitmap
00000000.00000000.00000000.00000000.00000000.00000000.00000000.00000001.01000110.10111001.01000110.10111001.01000000.00000000.00000000.00000000.00000000.00000000.00000000.00000000.0000000
Copy to filled bitmap
11111111.11111111.11111111.11111111.11111111.11111111.11111111.11111101.01000110.10111001.01000110.10111001.01111111.11111111.11111111.11111111.11111111.11111111.11111111.11111111.1111111
Copy to alternating bitmap
10101010.01010101.10101010.01010101.10101010.01010101.10101010.01010101.01000110.10111001.01000110.10111001.01101010.01010101.10101010.01010101.10101010.01010101.10101010.01010101.0101010
Copy to same bitmap
10111001.01000110.10111001.01000110.10111001.01000110.10111001.01000101.01000110.10111001.01000110.10111001.01111001.01000110.10111001.01000110.10111001.01000110.10111001.01000110.0111001
Test unaligned copy.
Copy 7 64 32
Copy to zeroed bitmap
00000000.00000000.00000000.00000000.00000000.00000000.00000000.00000000.10100011.01011100.10100011.01011100.00000000.00000000.00000000.00000000.00000000.00000000.00000000.00000000.0000000
Copy to filled bitmap
11111111.11111111.11111111.11111111.11111111.11111111.11111111.11111111.10100011.01011100.10100011.01011100.11111111.11111111.11111111.11111111.11111111.11111111.11111111.11111111.1111111
Copy to alternating bitmap
10101010.01010101.10101010.01010101.10101010.01010101.10101010.01010101.10100011.01011100.10100011.01011100.10101010.01010101.10101010.01010101.10101010.01010101.10101010.01010101.0101010
Copy to same bitmap
10111001.01000110.10111001.01000110.10111001.01000110.10111001.01000110.10100011.01011100.10100011.01011100.10111001.01000110.10111001.01000110.10111001.01000110.10111001.01000110.0111001
Test unaligned copy with extra bits on ends.
Copy 7 67 36
Copy to zeroed bitmap
00000000.00000000.00000000.00000000.00000000.00000000.00000000.00000000.00010100.01101011.10010100.01101011.10010100.00000000.00000000.00000000.00000000.00000000.00000000.00000000.0000000
Copy to filled bitmap
11111111.11111111.11111111.11111111.11111111.11111111.11111111.11111111.11110100.01101011.10010100.01101011.10010101.11111111.11111111.11111111.11111111.11111111.11111111.11111111.1111111
Copy to alternating bitmap
10101010.01010101.10101010.01010101.10101010.01010101.10101010.01010101.10110100.01101011.10010100.01101011.10010100.01010101.10101010.01010101.10101010.01010101.10101010.01010101.0101010
Copy to same bitmap
10111001.01000110.10111001.01000110.10111001.01000110.10111001.01000110.10110100.01101011.10010100.01101011.10010101.01000110.10111001.01000110.10111001.01000110.10111001.01000110.0111001
Test overlapping aligned byte block copy.
Copy 8 0 36
Copy to zeroed bitmap
01000110.10111001.01000110.10111001.01000000.00000000.00000000.00000000.00000000.00000000.00000000.00000000.00000000.00000000.00000000.00000000.00000000.00000000.00000000.00000000.0000000
Copy to filled bitmap
01000110.10111001.01000110.10111001.01001111.11111111.11111111.11111111.11111111.11111111.11111111.11111111.11111111.11111111.11111111.11111111.11111111.11111111.11111111.11111111.1111111
Copy to alternating bitmap
01000110.10111001.01000110.10111001.01001010.01010101.10101010.01010101.10101010.01010101.10101010.01010101.10101010.01010101.10101010.01010101.10101010.01010101.10101010.01010101.0101010
Copy to same bitmap
01000110.10111001.01000110.10111001.01001001.01000110.10111001.01000110.10111001.01000110.10111001.01000110.10111001.01000110.10111001.01000110.10111001.01000110.10111001.01000110.0111001
Test overlapping aligned byte block copy.
Copy 0 8 36
Copy to zeroed bitmap
00000000.10111001.01000110.10111001.01000110.10110000.00000000.00000000.00000000.00000000.00000000.00000000.00000000.00000000.00000000.00000000.00000000.00000000.00000000.00000000.0000000
Copy to filled bitmap
11111111.10111001.01000110.10111001.01000110.10111111.11111111.11111111.11111111.11111111.11111111.11111111.11111111.11111111.11111111.11111111.11111111.11111111.11111111.11111111.1111111
Copy to alternating bitmap
10101010.10111001.01000110.10111001.01000110.10110101.10101010.01010101.10101010.01010101.10101010.01010101.10101010.01010101.10101010.01010101.10101010.01010101.10101010.01010101.0101010
Copy to same bitmap
10111001.10111001.01000110.10111001.01000110.10110110.10111001.01000110.10111001.01000110.10111001.01000110.10111001.01000110.10111001.01000110.10111001.01000110.10111001.01000110.0111001
Test overlapping unaligned copy.
Copy 2 1 36
Copy to zeroed bitmap
01110010.10001101.01110010.10001101.01110000.00000000.00000000.00000000.00000000.00000000.00000000.00000000.00000000.00000000.00000000.00000000.00000000.00000000.00000000.00000000.0000000
Copy to filled bitmap
11110010.10001101.01110010.10001101.01110111.11111111.11111111.11111111.11111111.11111111.11111111.11111111.11111111.11111111.11111111.11111111.11111111.11111111.11111111.11111111.1111111
Copy to alternating bitmap
11110010.10001101.01110010.10001101.01110010.01010101.10101010.01010101.10101010.01010101.10101010.01010101.10101010.01010101.10101010.01010101.10101010.01010101.10101010.01010101.0101010
Copy to same bitmap
11110010.10001101.01110010.10001101.01110001.01000110.10111001.01000110.10111001.01000110.10111001.01000110.10111001.01000110.10111001.01000110.10111001.01000110.10111001.01000110.0111001
Test overlapping unaligned copy.
Copy 1 2 36
Copy to zeroed bitmap
00011100.10100011.01011100.10100011.01011100.00000000.00000000.00000000.00000000.00000000.00000000.00000000.00000000.00000000.00000000.00000000.00000000.00000000.00000000.00000000.0000000
Copy to filled bitmap
11011100.10100011.01011100.10100011.01011111.11111111.11111111.11111111.11111111.11111111.11111111.11111111.11111111.11111111.11111111.11111111.11111111.11111111.11111111.11111111.1111111
Copy to alternating bitmap
10011100.10100011.01011100.10100011.01011110.01010101.10101010.01010101.10101010.01010101.10101010.01010101.10101010.01010101.10101010.01010101.10101010.01010101.10101010.01010101.0101010
Copy to same bitmap
10011100.10100011.01011100.10100011.01011101.01000110.10111001.01000110.10111001.01000110.10111001.01000110.10111001.01000110.10111001.01000110.10111001.01000110.10111001.01000110.0111001
Test copy to same position.
Copy 1 1 36
Copy to zeroed bitmap
00111001.01000110.10111001.01000110.10111000.00000000.00000000.00000000.00000000.00000000.00000000.00000000.00000000.00000000.00000000.00000000.00000000.00000000.00000000.00000000.0000000
Copy to filled bitmap
10111001.01000110.10111001.01000110.10111111.11111111.11111111.11111111.11111111.11111111.11111111.11111111.11111111.11111111.11111111.11111111.11111111.11111111.11111111.11111111.1111111
Copy to alternating bitmap
10111001.01000110.10111001.01000110.10111010.01010101.10101010.01010101.10101010.01010101.10101010.01010101.10101010.01010101.10101010.01010101.10101010.01010101.10101010.01010101.0101010
Copy to same bitmap
10111001.01000110.10111001.01000110.10111001.01000110.10111001.01000110.10111001.01000110.10111001.01000110.10111001.01000110.10111001.01000110.10111001.01000110.10111001.01000110.0111001
Test copy to end of bitmap.
Copy 0 1 166
Copy to zeroed bitmap
01011100.10100011.01011100.10100011.01011100.10100011.01011100.10100011.01011100.10100011.01011100.10100011.01011100.10100011.01011100.10100011.01011100.10100011.01011100.10100011.0011100
Copy to filled bitmap
11011100.10100011.01011100.10100011.01011100.10100011.01011100.10100011.01011100.10100011.01011100.10100011.01011100.10100011.01011100.10100011.01011100.10100011.01011100.10100011.0011100
Copy to alternating bitmap
11011100.10100011.01011100.10100011.01011100.10100011.01011100.10100011.01011100.10100011.01011100.10100011.01011100.10100011.01011100.10100011.01011100.10100011.01011100.10100011.0011100
Copy to same bitmap
11011100.10100011.01011100.10100011.01011100.10100011.01011100.10100011.01011100.10100011.01011100.10100011.01011100.10100011.01011100.10100011.01011100.10100011.01011100.10100011.0011100
Test zero bit copies.
Copy 0 1 0
Copy to zeroed bitmap
00000000.00000000.00000000.00000000.00000000.00000000.00000000.00000000.00000000.00000000.00000000.00000000.00000000.00000000.00000000.00000000.00000000.00000000.00000000.00000000.0000000
Copy to filled bitmap
11111111.11111111.11111111.11111111.11111111.11111111.11111111.11111111.11111111.11111111.11111111.11111111.11111111.11111111.11111111.11111111.11111111.11111111.11111111.11111111.1111111
Copy to alternating bitmap
10101010.01010101.10101010.01010101.10101010.01010101.10101010.01010101.10101010.01010101.10101010.01010101.10101010.01010101.10101010.01010101.10101010.01010101.10101010.01010101.0101010
Copy to same bitmap
10111001.01000110.10111001.01000110.10111001.01000110.10111001.01000110.10111001.01000110.10111001.01000110.10111001.01000110.10111001.01000110.10111001.01000110.10111001.01000110.0111001
Copy 0 167 0
Copy to zeroed bitmap
00000000.00000000.00000000.00000000.00000000.00000000.00000000.00000000.00000000.00000000.00000000.00000000.00000000.00000000.00000000.00000000.00000000.00000000.00000000.00000000.0000000
Copy to filled bitmap
11111111.11111111.11111111.11111111.11111111.11111111.11111111.11111111.11111111.11111111.11111111.11111111.11111111.11111111.11111111.11111111.11111111.11111111.11111111.11111111.1111111
Copy to alternating bitmap
10101010.01010101.10101010.01010101.10101010.01010101.10101010.01010101.10101010.01010101.10101010.01010101.10101010.01010101.10101010.01010101.10101010.01010101.10101010.01010101.0101010
Copy to same bitmap
10111001.01000110.10111001.01000110.10111001.01000110.10111001.01000110.10111001.01000110.10111001.01000110.10111001.01000110.10111001.01000110.10111001.01000110.10111001.01000110.0111001
union(zeroes, pattern) = 10111001
union(ones, pattern) = 11111111
union(pattern, ones) = 11111111
union(pattern, zeroes) = 10111001
union(pattern, alternating) = 10111011
union(pattern, pattern) = 10111001
union(alternating, alternating) = 10101010
union(zeroes, pattern) = 10111001.01000110.10111001.01000110.10111001.01000110.10111001.01000110
union(ones, pattern) = 11111111.11111111.11111111.11111111.11111111.11111111.11111111.11111111
union(pattern, ones) = 11111111.11111111.11111111.11111111.11111111.11111111.11111111.11111111
union(pattern, zeroes) = 10111001.01000110.10111001.01000110.10111001.01000110.10111001.01000110
union(pattern, alternating) = 10111011.01010111.10111011.01010111.10111011.01010111.10111011.01010111
union(pattern, pattern) = 10111001.01000110.10111001.01000110.10111001.01000110.10111001.01000110
union(alternating, alternating) = 10101010.01010101.10101010.01010101.10101010.01010101.10101010.01010101
intersect(zeroes, pattern) = 00000000
intersect(ones, pattern) = 10111001
intersect(pattern, ones) = 10111001
intersect(pattern, zeroes) = 00000000
intersect(pattern, alternating) = 10101000
intersect(pattern, pattern) = 10111001
intersect(alternating, alternating) = 10101010
intersect(zeroes, pattern) = 00000000.00000000.00000000.00000000.00000000.00000000.00000000.00000000
intersect(ones, pattern) = 10111001.01000110.10111001.01000110.10111001.01000110.10111001.01000110
intersect(pattern, ones) = 10111001.01000110.10111001.01000110.10111001.01000110.10111001.01000110
intersect(pattern, zeroes) = 00000000.00000000.00000000.00000000.00000000.00000000.00000000.00000000
intersect(pattern, alternating) = 10101000.01000100.10101000.01000100.10101000.01000100.10101000.01000100
intersect(pattern, pattern) = 10111001.01000110.10111001.01000110.10111001.01000110.10111001.01000110
intersect(alternating, alternating) = 10101010.01010101.10101010.01010101.10101010.01010101.10101010.01010101
difference(zeroes, pattern) = 00000000
difference(ones, pattern) = 01000110
difference(pattern, ones) = 00000000
difference(pattern, zeroes) = 10111001
difference(pattern, alternating) = 00010001
difference(pattern, pattern) = 00000000
difference(alternating, alternating) = 00000000
difference(zeroes, pattern) = 00000000.00000000.00000000.00000000.00000000.00000000.00000000.00000000
difference(ones, pattern) = 01000110.10111001.01000110.10111001.01000110.10111001.01000110.10111001
difference(pattern, ones) = 00000000.00000000.00000000.00000000.00000000.00000000.00000000.00000000
difference(pattern, zeroes) = 10111001.01000110.10111001.01000110.10111001.01000110.10111001.01000110
difference(pattern, alternating) = 00010001.00000010.00010001.00000010.00010001.00000010.00010001.00000010
difference(pattern, pattern) = 00000000.00000000.00000000.00000000.00000000.00000000.00000000.00000000
difference(alternating, alternating) = 00000000.00000000.00000000.00000000.00000000.00000000.00000000.00000000
xor(zeroes, pattern) = 10111001
xor(ones, pattern) = 01000110
xor(pattern, ones) = 01000110
xor(pattern, zeroes) = 10111001
xor(pattern, alternating) = 00010011
xor(pattern, pattern) = 00000000
xor(alternating, alternating) = 00000000
xor(zeroes, pattern) = 10111001.01000110.10111001.01000110.10111001.01000110.10111001.01000110
xor(ones, pattern) = 01000110.10111001.01000110.10111001.01000110.10111001.01000110.10111001
xor(pattern, ones) = 01000110.10111001.01000110.10111001.01000110.10111001.01000110.10111001
xor(pattern, zeroes) = 10111001.01000110.10111001.01000110.10111001.01000110.10111001.01000110
xor(pattern, alternating) = 00010011.00010011.00010011.00010011.00010011.00010011.00010011.00010011
xor(pattern, pattern) = 00000000.00000000.00000000.00000000.00000000.00000000.00000000.00000000
xor(alternating, alternating) = 00000000.00000000.00000000.00000000.00000000.00000000.00000000.00000000
ordering(zeroes, pattern) = '<'
ordering(ones, pattern) = '>'
ordering(pattern, ones) = '<'
ordering(pattern, zeroes) = '>'
ordering(pattern, alternating) = '>'
ordering(pattern, pattern) = '='
ordering(alternating, alternating) = '='
ordering(zeroes, pattern) = '<'
ordering(ones, pattern) = '>'
ordering(pattern, ones) = '<'
ordering(pattern, zeroes) = '>'
ordering(pattern, alternating) = '>'
ordering(pattern, pattern) = '='
ordering(alternating, alternating) = '='
test_unify(zeroes, pattern) = no
test_unify(ones, pattern) = no
test_unify(pattern, ones) = no
test_unify(pattern, zeroes) = no
test_unify(pattern, alternating) = no
test_unify(pattern, pattern) = yes
test_unify(alternating, alternating) = yes
test_unify(zeroes, pattern) = no
test_unify(ones, pattern) = no
test_unify(pattern, ones) = no
test_unify(pattern, zeroes) = no
test_unify(pattern, alternating) = no
test_unify(pattern, pattern) = yes
test_unify(alternating, alternating) = yes
BMa = "<64:FFFFFFFFB725FFFF>".
BMb = "<47:FFF6B4BFFFFE>".
First read succeeded
Second read succeeded
First read succeeded
Second read succeeded
Found exception as expected: bitmap_error("bitmap.bit: bit index -1 is out of bounds [0, 64).")
Found exception as expected: bitmap_error("bitmap.bit: bit index 64 is out of bounds [0, 64).")
Found exception as expected: bitmap_error("bitmap.bit: bit index 73 is out of bounds [0, 64).")
Found exception as expected: bitmap_error("copy_bits (source): 32 bits starting at bit -1 is out of bounds [0, 64).")
Found exception as expected: bitmap_error("copy_bits (source): 32 bits starting at bit 33 is out of bounds [0, 64).")
Found exception as expected: bitmap_error("copy_bits (destination): 32 bits starting at bit 33 is out of bounds [0, 64).")
Found exception as expected: bitmap_error("bitmap.bits: bit index -1 is out of bounds [0, 64).")
Found exception as expected: bitmap_error("bitmap.bits: bit index 33 is out of bounds [0, 64).")
Found exception as expected: bitmap_error("bitmap.bits: number of bits must be between 0 and `int.bits_per_int\'.")
Found exception as expected: bitmap_error("bitmap.bits: number of bits must be between 0 and `int.bits_per_int\'.")
Found exception as expected: bitmap_error("bitmap.bits: bit index 65 is out of bounds [0, 64).")
Found exception as expected: bitmap_error("bitmap.bits: bit index -1 is out of bounds [0, 64).")