summaryrefslogtreecommitdiff
path: root/doc/bitmaps.rst
blob: 18a992de22922ea41104bec15df51bf5f81d0f0a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
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;
	}