diff options
author | Jörg Frings-Fürst <debian@jff-webhosting.net> | 2023-02-10 15:27:06 +0100 |
---|---|---|
committer | Jörg Frings-Fürst <debian@jff-webhosting.net> | 2023-02-10 15:27:06 +0100 |
commit | 7501bff8432444b7ae8e7f3d9289c0d61f3f0b64 (patch) | |
tree | bd53603f464c3747e897a8996158a0fef7b41bc3 /doc/bitmaps.rst | |
parent | 0f124df68d87c9073f76efeff1a901a69b1f3e13 (diff) | |
parent | 9e9336185f86bd97ff22f54e4d561c2cccccecf5 (diff) |
Merge branch 'release/debian/4.10-1'debian/4.10-1
Diffstat (limited to 'doc/bitmaps.rst')
-rw-r--r-- | doc/bitmaps.rst | 49 |
1 files changed, 49 insertions, 0 deletions
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 <libHX/misc.h> + + 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 <stdlib.h> + #include <string.h> + #include <libHX/misc.h> + + 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; + } |