summaryrefslogtreecommitdiff
path: root/doc/libstddjb/bitarray.html
blob: 03f81dfeb2061d2a10adda5d366ed7cf1090cf46 (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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
<html>
  <head>
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <meta http-equiv="Content-Language" content="en" />
    <title>skalibs: the bitarray library interface</title>
    <meta name="Description" content="skalibs: the bitarray library interface" />
    <meta name="Keywords" content="skalibs c unix bitarray library libstddjb" />
    <!-- <link rel="stylesheet" type="text/css" href="http://skarnet.org/default.css" /> -->
  </head>
<body>

<p>
<a href="index.html">libstddjb</a><br />
<a href="../libskarnet.html">libskarnet</a><br />
<a href="../index.html">skalibs</a><br />
<a href="http://skarnet.org/software/">Software</a><br />
<a href="http://skarnet.org/">skarnet.org</a>
</p>

<h1> The <tt>bitarray</tt> library interface </h1>

<p>
 The following functions are declared in the <tt>skalibs/bitarray.h</tt> header,
and implemented in the <tt>libskarnet.a</tt> or <tt>libskarnet.so</tt> library.
</p>

<h2> General information </h2>

<p>
 <tt>bitarray</tt> is a set of primitives to operate efficiently on
large bitfields.
</p>

<p>
 A bitfield is represented by a pre-allocated block of
<tt>unsigned char</tt>; <tt>bitarray</tt> does not care if that
block has been BSS-, stack- or heap-allocated. Bitfields that
can grow in size should be stored in a
<a href="stralloc.html">stralloc</a>.
</p>

<p>
 Bits in a bitfield of length <em>n</em> are numbered from 0 to <em>n</em>-1.
</p>

<h2> Functions </h2>

<p>
<code> unsigned int bitarray_div8 (unsigned int n) </code> <br />
Returns the minimum number of bytes needed to store a field of <em>n</em> bits.

</p>

<p>
<code> void bitarray_clearsetn (unsigned char *s, unsigned int start, unsigned int len, int h) </code> <br />
Sets (if <em>h</em> is nonzero) or clears (if <em>h</em> is zero)
<em>len</em> bits in field <em>s</em>, starting at bit <em>start</em>.
</p>

<p>
<code> void bitarray_clearn (unsigned char *s, unsigned int start, unsigned int len) </code> <br />
Clears <em>len</em> bits in field <em>s</em>, starting at bit <em>start</em>.
</p>

<p>
<code> void bitarray_setn (unsigned char *s, unsigned int start, unsigned int len) </code> <br />
Sets <em>len</em> bits in field <em>s</em>, starting at bit <em>start</em>.
</p>

<p>
<code> int bitarray_peek (unsigned char const *s, unsigned int n) </code> <br />
Returns the value of the <em>n</em>th bit in field <em>s</em>.
</p>

<p>
<code> void bitarray_poke (unsigned char *s, unsigned int n, int h) </code> <br />
Sets (if <em>h</em> is nonzero) or clears (if <em>h</em> is zero)
the <em>n</em>th bit in field <em>s</em>.
</p>

<p>
<code> void bitarray_clear (unsigned char *s, unsigned int n) </code> <br />
Clears the <em>n</em>th bit in field <em>s</em>.
</p>

<p>
<code> void bitarray_set (unsigned char *s, unsigned int n) </code> <br />
Sets the <em>n</em>th bit in field <em>s</em>.
</p>

<p>
<code> int bitarray_testandpoke (unsigned char *s, unsigned int n, int h) </code> <br />
Sets (if <em>h</em> is nonzero) or clears (if <em>h</em> is zero)
the <em>n</em>th bit in field <em>s</em>,
and returns the previous value of that bit.
</p>

<p>
<code> int bitarray_testandclear (unsigned char *s, unsigned int n) </code> <br />
Clear the <em>n</em>th bit in field <em>s</em>,
and returns the previous value of that bit.
</p>

<p>
<code> int bitarray_testandset (unsigned char *s, unsigned int n) </code> <br />
Sets the <em>n</em>th bit in field <em>s</em>,
and returns the previous value of that bit.
</p>

<p>
<code> unsigned int bitarray_first (unsigned char const *s, unsigned int len, int h) </code> <br />
Returns the number of the first set (if <em>h</em> is nonzero) or clear
(if <em>h</em> is zero) bit in <em>s</em>, <em>len</em> being
the total number of bits. If all bits in <em>s</em> are the negation of
<em>h</em>, then <em>len</em> is returned.
</p>

<p>
<code> unsigned int bitarray_firstclear (unsigned char const *s, unsigned int len) </code> <br />
Returns the number of the first clear bit in <em>s</em>, <em>len</em> being
the total number of bits. If all bits in <em>s</em> are set, <em>len</em> is returned.
</p>

<p>
<code> unsigned int bitarray_firstset (unsigned char const *s, unsigned int len) </code> <br />
Returns the number of the first set bit in <em>s</em>, <em>len</em> being
the total number of bits. If all bits in <em>s</em> are clear, <em>len</em> is returned.
</p>

</body>
</html>