Skip to content

Commit bd7109b

Browse files
committed
bitmap documentation
1 parent 97a0ecc commit bd7109b

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

include/scl/bitmap.h

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ namespace scl {
3636
* behaves a bit more like a "fixed-length vector of bits". The main
3737
* differentiator is that Bitmap implements various element-wise operations.
3838
*
39-
* A Bitmap is always a multiple of Bitmap::BlockType. One consequence of this
40-
* is that its "true size" must be tracked externally.
39+
* Bitmap is a useful class for protocols that makes use of indicator sets,
40+
* because that's effectively what Bitmap is.
4141
*
4242
* @code
4343
* Bitmap bm(10); // this creates a Bitmap with space for 10 bits, with
@@ -53,7 +53,8 @@ namespace scl {
5353
* assert(!bm.at(1));
5454
*
5555
* std::cout << bm;
56-
* // 0000000000000001
56+
* // prints "0000000000000001"
57+
* // note that a multiple of sizeof(Bitmap::BlockType) is printed.
5758
*
5859
* Bitmap bm1(10);
5960
* Bitmap bm2(10);
@@ -68,6 +69,19 @@ namespace scl {
6869
* assert((bm1 | bm2).count() == 3);
6970
*
7071
* assert((~bm1).count() == 8);
72+
*
73+
* // Bitmap::set performs no bounds checking, so the following is perfectly
74+
* // fine. However, it will lead to weird behaviour. For example
75+
*
76+
* Bitmap bm_oob(10);
77+
* bm_oob.set(10, true);
78+
* assert(bm_oob.count() == 1);
79+
* assert((~bm_oob).count() == 10);
80+
*
81+
* // Negation does not touch the bits beyond Bitmap::size in order to ensure
82+
* // that Bitmap::count works as expected. So if we assign bits beyond
83+
* // Bitmap::size then Bitmap::count might not work correctly anymore :)
84+
*
7185
* @endcode
7286
*/
7387
class Bitmap {

0 commit comments

Comments
 (0)