Commit Graph

2 Commits

Author SHA1 Message Date
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
Peter Wang
a59a8bbe1d Fix bitmap predicates which did not work correctly with empty bitmaps.
Branches: main

Fix bitmap predicates which did not work correctly with empty bitmaps.

Note that `bitmap.to_string' now returns "<0:>" for an empty bitmap instead
of "<0:00>".

library/bitmap.m:
        Add `in_range_rexcl' to check an index is in the range [0, num_bits).

        Fix bounds checks on empty bitmaps in `^ bits' and `copy_bytes'.

        Simplify other bounds checks using `in_range_rexcl'.

        Make `byte_index_for_bit' return -1 if its argument is negative,
        instead of 0.  `byte_index_for_bit(NumBits - 1)' is used to get the
        last byte index, so now loops over empty bitmaps will stop immediately
        as the initial index must be greater than -1.

        Make some code neater.

tests/hard_coded/Mmakefile:
tests/hard_coded/bitmap_empty.exp:
tests/hard_coded/bitmap_empty.m:
        Add a test case.

NEWS:
        Mention changed behaviour of `bitmap.to_string'.
2010-03-02 00:32:37 +00:00