From 532d4a24e2013262dfa41fd85c06a9715c99abf7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Frings-F=C3=BCrst?= Date: Mon, 24 Oct 2022 21:03:42 +0200 Subject: New upstream version 4.7 --- doc/bitmaps.rst | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 doc/bitmaps.rst (limited to 'doc/bitmaps.rst') diff --git a/doc/bitmaps.rst b/doc/bitmaps.rst new file mode 100644 index 0000000..18a992d --- /dev/null +++ b/doc/bitmaps.rst @@ -0,0 +1,49 @@ +======= +Bitmaps +======= + +.. code-block:: c + + #include + + size_t HXbitmap_size(type array, unsigned int bits); + void HXbitmap_set(type *bmap, unsigned int bit); + void HXbitmap_clear(type *bmap, unsigned int bit); + bool HXbitmap_test(type *bmap, unsigned int bit); + +All of these four are implemented as macros, so they can be used with any +integer type that is desired to be used. + +``HXbitmap_size`` + Returns the amount of ``type``-based integers that would be needed to + hold an array of the requested amount of bits. + +``HXbitmap_set`` + Sets the specific bit in the bitmap. + +``HXbitmap_clear`` + Clears the specific bit in this bitmap. + +``HXbitmap_test`` + Tests for the specific bit and returns true if it is set, otherwise + false. + + +Example +======= + +.. code-block:: c + + #include + #include + #include + + int main(void) + { + unsigned long bitmap[HXbitmap_size(unsigned long, 128)]; + + memset(bitmap, 0, sizeof(bitmap)); + HXbitmap_set(bitmap, 49); + return HXbitmap_get(bitmap, HX_irand(0, 128)) ? + EXIT_SUCCESS : EXIT_FAILURE; + } -- cgit v1.2.3