xref: /freebsd/share/man/man3/bitstring.3 (revision c7c3ef8949021696029fb73a513678578a9f8a46)
1afe61c15SRodney W. Grimes.\" Copyright (c) 1989, 1991, 1993
2afe61c15SRodney W. Grimes.\"	The Regents of the University of California.  All rights reserved.
3afe61c15SRodney W. Grimes.\"
4afe61c15SRodney W. Grimes.\" This code is derived from software contributed to Berkeley by
5afe61c15SRodney W. Grimes.\" Paul Vixie.
6afe61c15SRodney W. Grimes.\" Redistribution and use in source and binary forms, with or without
7afe61c15SRodney W. Grimes.\" modification, are permitted provided that the following conditions
8afe61c15SRodney W. Grimes.\" are met:
9afe61c15SRodney W. Grimes.\" 1. Redistributions of source code must retain the above copyright
10afe61c15SRodney W. Grimes.\"    notice, this list of conditions and the following disclaimer.
11afe61c15SRodney W. Grimes.\" 2. Redistributions in binary form must reproduce the above copyright
12afe61c15SRodney W. Grimes.\"    notice, this list of conditions and the following disclaimer in the
13afe61c15SRodney W. Grimes.\"    documentation and/or other materials provided with the distribution.
14dda5b397SEitan Adler.\" 3. Neither the name of the University nor the names of its contributors
15afe61c15SRodney W. Grimes.\"    may be used to endorse or promote products derived from this software
16afe61c15SRodney W. Grimes.\"    without specific prior written permission.
17afe61c15SRodney W. Grimes.\"
18afe61c15SRodney W. Grimes.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
19afe61c15SRodney W. Grimes.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20afe61c15SRodney W. Grimes.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21afe61c15SRodney W. Grimes.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
22afe61c15SRodney W. Grimes.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23afe61c15SRodney W. Grimes.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24afe61c15SRodney W. Grimes.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25afe61c15SRodney W. Grimes.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26afe61c15SRodney W. Grimes.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27afe61c15SRodney W. Grimes.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28afe61c15SRodney W. Grimes.\" SUCH DAMAGE.
29afe61c15SRodney W. Grimes.\"
301b82e02fSAlan Somers.\" Copyright (c) 2014,2016 Spectra Logic Corporation
318907f744SAlan Somers.\" All rights reserved.
328907f744SAlan Somers.\"
338907f744SAlan Somers.\" Redistribution and use in source and binary forms, with or without
348907f744SAlan Somers.\" modification, are permitted provided that the following conditions
358907f744SAlan Somers.\" are met:
368907f744SAlan Somers.\" 1. Redistributions of source code must retain the above copyright
378907f744SAlan Somers.\"    notice, this list of conditions, and the following disclaimer,
388907f744SAlan Somers.\"    without modification.
398907f744SAlan Somers.\" 2. Redistributions in binary form must reproduce at minimum a disclaimer
408907f744SAlan Somers.\"    substantially similar to the "NO WARRANTY" disclaimer below
418907f744SAlan Somers.\"    ("Disclaimer") and any redistribution must be conditioned upon
428907f744SAlan Somers.\"    including a substantially similar Disclaimer requirement for further
438907f744SAlan Somers.\"    binary redistribution.
448907f744SAlan Somers.\"
458907f744SAlan Somers.\" NO WARRANTY
468907f744SAlan Somers.\" THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
478907f744SAlan Somers.\" "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
488907f744SAlan Somers.\" LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
498907f744SAlan Somers.\" A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
508907f744SAlan Somers.\" HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
518907f744SAlan Somers.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
528907f744SAlan Somers.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
538907f744SAlan Somers.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
548907f744SAlan Somers.\" STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
558907f744SAlan Somers.\" IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
568907f744SAlan Somers.\" POSSIBILITY OF SUCH DAMAGES.
578907f744SAlan Somers.\"
58*c56f45f2SDag-Erling Smørgrav.Dd November 21, 2023
59afe61c15SRodney W. Grimes.Dt BITSTRING 3
603d45e180SRuslan Ermilov.Os
61afe61c15SRodney W. Grimes.Sh NAME
62afe61c15SRodney W. Grimes.Nm bit_alloc ,
63afe61c15SRodney W. Grimes.Nm bit_clear ,
641b82e02fSAlan Somers.Nm bit_count ,
65afe61c15SRodney W. Grimes.Nm bit_decl ,
668907f744SAlan Somers.Nm bit_ffc ,
67afe61c15SRodney W. Grimes.Nm bit_ffs ,
6884e2ae64SDoug Moore.Nm bit_ff_at ,
698907f744SAlan Somers.Nm bit_ffc_at ,
708907f744SAlan Somers.Nm bit_ffs_at ,
7152e8f6a3SEric Joyner.Nm bit_ffc_area ,
7252e8f6a3SEric Joyner.Nm bit_ffs_area ,
7384e2ae64SDoug Moore.Nm bit_ff_area_at ,
7452e8f6a3SEric Joyner.Nm bit_ffc_area_at ,
7552e8f6a3SEric Joyner.Nm bit_ffs_area_at ,
76afe61c15SRodney W. Grimes.Nm bit_nclear ,
77afe61c15SRodney W. Grimes.Nm bit_nset ,
7884e2ae64SDoug Moore.Nm bit_ntest ,
79afe61c15SRodney W. Grimes.Nm bit_set ,
808907f744SAlan Somers.Nm bit_test ,
818907f744SAlan Somers.Nm bitstr_size
828907f744SAlan Somers.Nd bit-string manipulation functions and macros
83afe61c15SRodney W. Grimes.Sh SYNOPSIS
8432eef9aeSRuslan Ermilov.In bitstring.h
85afe61c15SRodney W. Grimes.Ft bitstr_t *
86*c56f45f2SDag-Erling Smørgrav.Fn bit_alloc "size_t nbits"
8769a6a1d7SBruce Evans.Ft void
88*c56f45f2SDag-Erling Smørgrav.Fn bit_decl "bitstr_t *name" "size_t nbits"
8969a6a1d7SBruce Evans.Ft void
90*c56f45f2SDag-Erling Smørgrav.Fn bit_clear "bitstr_t *name" "size_t bit"
9169a6a1d7SBruce Evans.Ft void
92*c56f45f2SDag-Erling Smørgrav.Fn bit_count "bitstr_t *name" "size_t count" "size_t nbits" "ssize_t *value"
931b82e02fSAlan Somers.Ft void
94*c56f45f2SDag-Erling Smørgrav.Fn bit_ffc "bitstr_t *name" "size_t nbits" "ssize_t *value"
9569a6a1d7SBruce Evans.Ft void
96*c56f45f2SDag-Erling Smørgrav.Fn bit_ffs "bitstr_t *name" "size_t nbits" "ssize_t *value"
9769a6a1d7SBruce Evans.Ft void
98*c56f45f2SDag-Erling Smørgrav.Fn bit_ffc_at "bitstr_t *name" "size_t start" "size_t nbits" "ssize_t *value"
998907f744SAlan Somers.Ft void
100*c56f45f2SDag-Erling Smørgrav.Fn bit_ffs_at "bitstr_t *name" "size_t start" "size_t nbits" "ssize_t *value"
1018907f744SAlan Somers.Ft void
102*c56f45f2SDag-Erling Smørgrav.Fn bit_ff_at "bitstr_t *name" "size_t start" "size_t nbits" "int match" "ssize_t *value"
10384e2ae64SDoug Moore.Ft void
104*c56f45f2SDag-Erling Smørgrav.Fn bit_ffc_area "bitstr_t *name" "size_t nbits" "size_t size" "ssize_t *value"
10552e8f6a3SEric Joyner.Ft void
106*c56f45f2SDag-Erling Smørgrav.Fn bit_ffs_area "bitstr_t *name" "size_t nbits" "size_t size" "ssize_t *value"
10752e8f6a3SEric Joyner.Ft void
108*c56f45f2SDag-Erling Smørgrav.Fn bit_ffc_area_at "bitstr_t *name" "size_t start" "size_t nbits" "size_t size" "ssize_t *value"
10952e8f6a3SEric Joyner.Ft void
110*c56f45f2SDag-Erling Smørgrav.Fn bit_ffs_area_at "bitstr_t *name" "size_t start" "size_t nbits" "size_t size" "ssize_t *value"
11184e2ae64SDoug Moore.Ft void
112*c56f45f2SDag-Erling Smørgrav.Fn bit_ff_area_at "bitstr_t *name" "size_t start" "size_t nbits" "size_t size" "int match" "ssize_t *value"
113*c56f45f2SDag-Erling Smørgrav.Fn bit_foreach "bitstr_t *name" "size_t nbits" "size_t var"
114*c56f45f2SDag-Erling Smørgrav.Fn bit_foreach_at "bitstr_t *name" "size_t start" "size_t nbits" "size_t var"
115*c56f45f2SDag-Erling Smørgrav.Fn bit_foreach_unset "bitstr_t *name" "size_t nbits" "size_t var"
116*c56f45f2SDag-Erling Smørgrav.Fn bit_foreach_unset_at "bitstr_t *name" "size_t start" "size_t nbits" "size_t var"
11752e8f6a3SEric Joyner.Ft void
118*c56f45f2SDag-Erling Smørgrav.Fn bit_nclear "bitstr_t *name" "size_t start" "size_t stop"
11969a6a1d7SBruce Evans.Ft void
120*c56f45f2SDag-Erling Smørgrav.Fn bit_nset "bitstr_t *name" "size_t start" "size_t stop"
12184e2ae64SDoug Moore.Ft int
122*c56f45f2SDag-Erling Smørgrav.Fn bit_ntest "bitstr_t *name" "size_t start" "size_t stop" "int match"
12369a6a1d7SBruce Evans.Ft void
124*c56f45f2SDag-Erling Smørgrav.Fn bit_set "bitstr_t *name" "size_t bit"
12569a6a1d7SBruce Evans.Ft int
126*c56f45f2SDag-Erling Smørgrav.Fn bitstr_size "size_t nbits"
12769a6a1d7SBruce Evans.Ft int
128*c56f45f2SDag-Erling Smørgrav.Fn bit_test "bitstr_t *name" "size_t bit"
129afe61c15SRodney W. Grimes.Sh DESCRIPTION
130afe61c15SRodney W. GrimesThese macros operate on strings of bits.
131afe61c15SRodney W. Grimes.Pp
1328907f744SAlan SomersThe function
133afe61c15SRodney W. Grimes.Fn bit_alloc
134afe61c15SRodney W. Grimesreturns a pointer of type
135afe61c15SRodney W. Grimes.Dq Fa "bitstr_t *"
136afe61c15SRodney W. Grimesto sufficient space to store
137afe61c15SRodney W. Grimes.Fa nbits
138afe61c15SRodney W. Grimesbits, or
139afe61c15SRodney W. Grimes.Dv NULL
140afe61c15SRodney W. Grimesif no space is available.
1418907f744SAlan SomersIf successful, the returned bit string is initialized with all bits cleared.
142afe61c15SRodney W. Grimes.Pp
143afe61c15SRodney W. GrimesThe macro
144afe61c15SRodney W. Grimes.Fn bit_decl
1458907f744SAlan Somersdeclares a bit string with sufficient space to store
146afe61c15SRodney W. Grimes.Fa nbits
1478907f744SAlan Somersbits.
1488907f744SAlan Somers.Fn bit_decl
1498907f744SAlan Somersmay be used to include statically sized bit strings in structure
1508907f744SAlan Somersdefinitions or to create bit strings on the stack.
1518907f744SAlan SomersUsers of this macro are responsible for initialization of the bit string,
1528907f744SAlan Somerstypically via a global initialization of the containing struct or use of the
1538907f744SAlan Somers.Fn bit_nset
1548907f744SAlan Somersor
1558907f744SAlan Somers.Fn bin_nclear
1568907f744SAlan Somersfunctions.
157afe61c15SRodney W. Grimes.Pp
158afe61c15SRodney W. GrimesThe macro
159afe61c15SRodney W. Grimes.Fn bitstr_size
1608907f744SAlan Somersreturns the number of bytes necessary to store
161afe61c15SRodney W. Grimes.Fa nbits
162afe61c15SRodney W. Grimesbits.
163afe61c15SRodney W. GrimesThis is useful for copying bit strings.
164afe61c15SRodney W. Grimes.Pp
1658907f744SAlan SomersThe functions
166afe61c15SRodney W. Grimes.Fn bit_clear
167afe61c15SRodney W. Grimesand
168afe61c15SRodney W. Grimes.Fn bit_set
169afe61c15SRodney W. Grimesclear or set the zero-based numbered bit
170afe61c15SRodney W. Grimes.Fa bit ,
171afe61c15SRodney W. Grimesin the bit string
172afe61c15SRodney W. Grimes.Ar name .
173afe61c15SRodney W. Grimes.Pp
174afe61c15SRodney W. GrimesThe
175afe61c15SRodney W. Grimes.Fn bit_nset
176afe61c15SRodney W. Grimesand
177afe61c15SRodney W. Grimes.Fn bit_nclear
1788907f744SAlan Somersfunctions
179afe61c15SRodney W. Grimesset or clear the zero-based numbered bits from
180afe61c15SRodney W. Grimes.Fa start
1810b607240SJohn-Mark Gurneythrough
182afe61c15SRodney W. Grimes.Fa stop
183afe61c15SRodney W. Grimesin the bit string
184afe61c15SRodney W. Grimes.Ar name .
185afe61c15SRodney W. Grimes.Pp
186afe61c15SRodney W. GrimesThe
187afe61c15SRodney W. Grimes.Fn bit_test
1888907f744SAlan Somersfunction
189afe61c15SRodney W. Grimesevaluates to non-zero if the zero-based numbered bit
190afe61c15SRodney W. Grimes.Fa bit
191afe61c15SRodney W. Grimesof bit string
192afe61c15SRodney W. Grimes.Fa name
193afe61c15SRodney W. Grimesis set, and zero otherwise.
194afe61c15SRodney W. Grimes.Pp
19584e2ae64SDoug MooreThe
19684e2ae64SDoug Moore.Fn bit_ntest
19784e2ae64SDoug Moorefunction
19884e2ae64SDoug Mooreevaluates to non-zero if the zero-based numbered bits from
19984e2ae64SDoug Moore.Fa start
20084e2ae64SDoug Moorethrough
20184e2ae64SDoug Moore.Fa stop
20284e2ae64SDoug Moorein the bit string
20384e2ae64SDoug Moore.Ar name
20484e2ae64SDoug Mooreall have the value
20584e2ae64SDoug Moore.Ar match .
20684e2ae64SDoug Moore.Pp
2078907f744SAlan SomersThe function
208afe61c15SRodney W. Grimes.Fn bit_ffc
209afe61c15SRodney W. Grimesstores in the location referenced by
210afe61c15SRodney W. Grimes.Fa value
211afe61c15SRodney W. Grimesthe zero-based number of the first bit not set in the array of
212afe61c15SRodney W. Grimes.Fa nbits
213afe61c15SRodney W. Grimesbits referenced by
214afe61c15SRodney W. Grimes.Fa name .
215afe61c15SRodney W. GrimesIf all bits are set, the location referenced by
216afe61c15SRodney W. Grimes.Fa value
217afe61c15SRodney W. Grimesis set to \-1.
218afe61c15SRodney W. Grimes.Pp
2198907f744SAlan SomersThe
2208907f744SAlan Somers.Fn bit_ffs
2218907f744SAlan Somersfunction
2228907f744SAlan Somersstores in the location referenced by
2238907f744SAlan Somers.Fa value
2248907f744SAlan Somersthe zero-based number of the first bit set in the array of
2258907f744SAlan Somers.Fa nbits
2268907f744SAlan Somersbits referenced by
2278907f744SAlan Somers.Fa name .
2288907f744SAlan SomersIf no bits are set, the location referenced by
2298907f744SAlan Somers.Fa value
2308907f744SAlan Somersis set to \-1.
2318907f744SAlan Somers.Pp
2328907f744SAlan SomersThe function
2338907f744SAlan Somers.Fn bit_ffc_at
2348907f744SAlan Somersstores in the location referenced by
2358907f744SAlan Somers.Fa value
2368907f744SAlan Somersthe zero-based number of the first bit not set in the array of
2378907f744SAlan Somers.Fa nbits
2388907f744SAlan Somersbits referenced by
2398907f744SAlan Somers.Fa name ,
2408907f744SAlan Somersat or after the zero-based bit index
2418907f744SAlan Somers.Fa start .
2428907f744SAlan SomersIf all bits at or after
2438907f744SAlan Somers.Fa start
2448907f744SAlan Somersare set, the location referenced by
2458907f744SAlan Somers.Fa value
2468907f744SAlan Somersis set to \-1.
2478907f744SAlan Somers.Pp
2488907f744SAlan SomersThe
2498907f744SAlan Somers.Fn bit_ffs_at
2508907f744SAlan Somersfunction
2518907f744SAlan Somersstores in the location referenced by
2528907f744SAlan Somers.Fa value
2538907f744SAlan Somersthe zero-based number of the first bit set in the array of
2548907f744SAlan Somers.Fa nbits
2558907f744SAlan Somersbits referenced by
2568907f744SAlan Somers.Fa name ,
2578907f744SAlan Somersat or after the zero-based bit index
2588907f744SAlan Somers.Fa start .
2598907f744SAlan SomersIf no bits are set after
2608907f744SAlan Somers.Fa start ,
2618907f744SAlan Somersthe location referenced by
2628907f744SAlan Somers.Fa value
2638907f744SAlan Somersis set to \-1.
2648907f744SAlan Somers.Pp
2651b82e02fSAlan SomersThe
26684e2ae64SDoug Moore.Fn bit_ff_at
26784e2ae64SDoug Moorefunction
26884e2ae64SDoug Moorestores in the location referenced by
26984e2ae64SDoug Moore.Fa value
27084e2ae64SDoug Moorethe zero-based number of the first bit in the array of
27184e2ae64SDoug Moore.Fa nbits
27284e2ae64SDoug Moorebits referenced by
27384e2ae64SDoug Moore.Fa name ,
27484e2ae64SDoug Mooreat or after the zero-based bit index
27584e2ae64SDoug Moore.Fa start
27684e2ae64SDoug Moorethat has value
27784e2ae64SDoug Moore.Fa match .
27884e2ae64SDoug MooreIf no bits after
27984e2ae64SDoug Moore.Fa start
28084e2ae64SDoug Moorematch that value, the location referenced by
28184e2ae64SDoug Moore.Fa value
28284e2ae64SDoug Mooreis set to \-1.
28384e2ae64SDoug Moore.Pp
28484e2ae64SDoug MooreThe
28552e8f6a3SEric Joyner.Fn bit_ffc_area
28652e8f6a3SEric Joynerfunction stores in the location referenced by
28752e8f6a3SEric Joyner.Fa value
28852e8f6a3SEric Joynerthe zero-based number of the first bit beginning a sequence of unset bits of
28952e8f6a3SEric Joynerat least
29052e8f6a3SEric Joyner.Fa size
29152e8f6a3SEric Joynerunset bits in the array of
29252e8f6a3SEric Joyner.Fa nbits
29352e8f6a3SEric Joynerbits referenced by
29452e8f6a3SEric Joyner.Fa name .
29552e8f6a3SEric JoynerIf no sequence of contiguous unset bits of the specified
29652e8f6a3SEric Joyner.Fa size
29752e8f6a3SEric Joynercan be found, the location referenced by
29852e8f6a3SEric Joyner.Fa value
29952e8f6a3SEric Joyneris set to \-1.
30052e8f6a3SEric Joyner.Pp
30152e8f6a3SEric JoynerThe
30252e8f6a3SEric Joyner.Fn bit_ffs_area
30352e8f6a3SEric Joynerfunction stores in the location referenced by
30452e8f6a3SEric Joyner.Fa value
30552e8f6a3SEric Joynerthe zero-based number of the first bit beginning a sequence of set bits of
30652e8f6a3SEric Joynerat least
30752e8f6a3SEric Joyner.Fa size
30852e8f6a3SEric Joynerset bits in the array of
30952e8f6a3SEric Joyner.Fa nbits
31052e8f6a3SEric Joynerbits referenced by
31152e8f6a3SEric Joyner.Fa name .
31252e8f6a3SEric JoynerIf no sequence of contiguous set bits of the specified
31352e8f6a3SEric Joyner.Fa size
31452e8f6a3SEric Joynercan be found, the location referenced by
31552e8f6a3SEric Joyner.Fa value
31652e8f6a3SEric Joyneris set to \-1.
31752e8f6a3SEric Joyner.Pp
31852e8f6a3SEric JoynerThe
31952e8f6a3SEric Joyner.Fn bit_ffc_area_at
32052e8f6a3SEric Joynerfunction stores in the location referenced by
32152e8f6a3SEric Joyner.Fa value
32252e8f6a3SEric Joynerthe zero-based number of the first bit beginning a sequence of unset bits of
32352e8f6a3SEric Joynerat least
32452e8f6a3SEric Joyner.Fa size
32552e8f6a3SEric Joynerunset bits in the array of
32652e8f6a3SEric Joyner.Fa nbits
32752e8f6a3SEric Joynerbits referenced by
32852e8f6a3SEric Joyner.Fa name ,
32952e8f6a3SEric Joynerat or after the zero-based bit index
33052e8f6a3SEric Joyner.Fa start .
33152e8f6a3SEric JoynerIf no sequence of contiguous unset bits of the specified
33252e8f6a3SEric Joyner.Fa size
33352e8f6a3SEric Joynercan be found at or after
33452e8f6a3SEric Joyner.Fa start ,
33552e8f6a3SEric Joynerthe location referenced by
33652e8f6a3SEric Joyner.Fa value
33752e8f6a3SEric Joyneris set to \-1.
33852e8f6a3SEric Joyner.Pp
33952e8f6a3SEric JoynerThe
34052e8f6a3SEric Joyner.Fn bit_ffs_area_at
34152e8f6a3SEric Joynerfunction stores in the location referenced by
34252e8f6a3SEric Joyner.Fa value
34352e8f6a3SEric Joynerthe zero-based number of the first bit beginning a sequence of set bits of
34452e8f6a3SEric Joynerat least
34552e8f6a3SEric Joyner.Fa size
34652e8f6a3SEric Joynerset bits in the array of
34752e8f6a3SEric Joyner.Fa nbits
34852e8f6a3SEric Joynerbits referenced by
34952e8f6a3SEric Joyner.Fa name ,
35052e8f6a3SEric Joynerat or after the zero-based bit index
35152e8f6a3SEric Joyner.Fa start .
35252e8f6a3SEric JoynerIf no sequence of contiguous set bits of the specified
35352e8f6a3SEric Joyner.Fa size
35452e8f6a3SEric Joynercan be found at or after
35552e8f6a3SEric Joyner.Fa start ,
35652e8f6a3SEric Joynerthe location referenced by
35752e8f6a3SEric Joyner.Fa value
35852e8f6a3SEric Joyneris set to \-1.
35952e8f6a3SEric Joyner.Pp
36052e8f6a3SEric JoynerThe
36184e2ae64SDoug Moore.Fn bit_ff_area_at
36284e2ae64SDoug Moorefunction stores in the location referenced by
36384e2ae64SDoug Moore.Fa value
36484e2ae64SDoug Moorethe zero-based number of the first bit beginning a sequence of bits of
36584e2ae64SDoug Mooreat least
36684e2ae64SDoug Moore.Fa size
36784e2ae64SDoug Moorebits in the array of
36884e2ae64SDoug Moore.Fa nbits
36984e2ae64SDoug Moorebits referenced by
37084e2ae64SDoug Moore.Fa name ,
37184e2ae64SDoug Mooreat or after the zero-based bit index
37284e2ae64SDoug Moore.Fa start
37384e2ae64SDoug Moorein which all bits have the value
37484e2ae64SDoug Moore.Fa match .
37584e2ae64SDoug MooreIf no sequence of contiguous such bits of the specified
37684e2ae64SDoug Moore.Fa size
37784e2ae64SDoug Moorecan be found at or after
37884e2ae64SDoug Moore.Fa start ,
37984e2ae64SDoug Moorethe location referenced by
38084e2ae64SDoug Moore.Fa value
38184e2ae64SDoug Mooreis set to \-1.
38284e2ae64SDoug Moore.Pp
38384e2ae64SDoug MooreThe
3841b82e02fSAlan Somers.Fn bit_count
3851b82e02fSAlan Somersfunction stores in the location referenced by
3861b82e02fSAlan Somers.Fa value
3871b82e02fSAlan Somersthe number of bits set in the array of
3881b82e02fSAlan Somers.Fa nbits
3891b82e02fSAlan Somersbits referenced by
3901b82e02fSAlan Somers.Fa name ,
3911b82e02fSAlan Somersat or after the zero-based bit index
3921b82e02fSAlan Somers.Fa start .
3931b82e02fSAlan Somers.Pp
39414a4d6d0SVladimir KondratyevThe macro
39514a4d6d0SVladimir Kondratyev.Fn bit_foreach
39614a4d6d0SVladimir Kondratyevtraverses all set bits in the array of
39714a4d6d0SVladimir Kondratyev.Fa nbits
39814a4d6d0SVladimir Kondratyevreferenced by
39914a4d6d0SVladimir Kondratyev.Fa name
40014a4d6d0SVladimir Kondratyevin the forward direction, assigning each location in turn to
40114a4d6d0SVladimir Kondratyev.Fa var .
40214a4d6d0SVladimir Kondratyev.Pp
40314a4d6d0SVladimir KondratyevThe macro
40414a4d6d0SVladimir Kondratyev.Fn bit_foreach_at
40514a4d6d0SVladimir Kondratyevtraverses all set bits in the array of
40614a4d6d0SVladimir Kondratyev.Fa nbits
40714a4d6d0SVladimir Kondratyevreferenced by
40814a4d6d0SVladimir Kondratyev.Fa name
40914a4d6d0SVladimir Kondratyevin the forward direction at or after the zero-based bit index
41014a4d6d0SVladimir Kondratyev.Fa start ,
41114a4d6d0SVladimir Kondratyevassigning each location in turn to
41214a4d6d0SVladimir Kondratyev.Fa var .
41314a4d6d0SVladimir Kondratyev.Pp
41414a4d6d0SVladimir KondratyevThe macro
41514a4d6d0SVladimir Kondratyev.Fn bit_foreach_unset
41614a4d6d0SVladimir Kondratyevtraverses all unset bits in the array of
41714a4d6d0SVladimir Kondratyev.Fa nbits
41814a4d6d0SVladimir Kondratyevreferenced by
41914a4d6d0SVladimir Kondratyev.Fa name
42014a4d6d0SVladimir Kondratyevin the forward direction, assigning each location in turn to
42114a4d6d0SVladimir Kondratyev.Fa var .
42214a4d6d0SVladimir Kondratyev.Pp
42314a4d6d0SVladimir KondratyevThe macro
42414a4d6d0SVladimir Kondratyev.Fn bit_foreach_unset_at
42514a4d6d0SVladimir Kondratyevtraverses all unset bits in the array of
42614a4d6d0SVladimir Kondratyev.Fa nbits
42714a4d6d0SVladimir Kondratyevreferenced by
42814a4d6d0SVladimir Kondratyev.Fa name
42914a4d6d0SVladimir Kondratyevin the forward direction at or after the zero-based bit index
43014a4d6d0SVladimir Kondratyev.Fa start ,
43114a4d6d0SVladimir Kondratyevassigning each location in turn to
43214a4d6d0SVladimir Kondratyev.Fa var .
43314a4d6d0SVladimir Kondratyev.Pp
4348907f744SAlan SomersThe arguments in bit string macros are evaluated only once and may safely
435afe61c15SRodney W. Grimeshave side effects.
436251c176fSRuslan Ermilov.Sh EXAMPLES
437afe61c15SRodney W. Grimes.Bd -literal -offset indent
438afe61c15SRodney W. Grimes#include <limits.h>
439afe61c15SRodney W. Grimes#include <bitstring.h>
440afe61c15SRodney W. Grimes
4413136363fSRuslan Ermilov\&...
442afe61c15SRodney W. Grimes#define	LPR_BUSY_BIT		0
443afe61c15SRodney W. Grimes#define	LPR_FORMAT_BIT		1
444afe61c15SRodney W. Grimes#define	LPR_DOWNLOAD_BIT	2
4453136363fSRuslan Ermilov\&...
446afe61c15SRodney W. Grimes#define	LPR_AVAILABLE_BIT	9
447afe61c15SRodney W. Grimes#define	LPR_MAX_BITS		10
448afe61c15SRodney W. Grimes
449afe61c15SRodney W. Grimesmake_lpr_available()
450afe61c15SRodney W. Grimes{
451afe61c15SRodney W. Grimes	bitstr_t bit_decl(bitlist, LPR_MAX_BITS);
452afe61c15SRodney W. Grimes	...
453afe61c15SRodney W. Grimes	bit_nclear(bitlist, 0, LPR_MAX_BITS - 1);
454afe61c15SRodney W. Grimes	...
455afe61c15SRodney W. Grimes	if (!bit_test(bitlist, LPR_BUSY_BIT)) {
456afe61c15SRodney W. Grimes		bit_clear(bitlist, LPR_FORMAT_BIT);
457afe61c15SRodney W. Grimes		bit_clear(bitlist, LPR_DOWNLOAD_BIT);
458afe61c15SRodney W. Grimes		bit_set(bitlist, LPR_AVAILABLE_BIT);
459afe61c15SRodney W. Grimes	}
460afe61c15SRodney W. Grimes}
461afe61c15SRodney W. Grimes.Ed
462afe61c15SRodney W. Grimes.Sh SEE ALSO
4637ebf4122SConrad Meyer.Xr malloc 3 ,
4647ebf4122SConrad Meyer.Xr bitset 9
465afe61c15SRodney W. Grimes.Sh HISTORY
466afe61c15SRodney W. GrimesThe
467afe61c15SRodney W. Grimes.Nm bitstring
46821421932SMike Pritchardfunctions first appeared in
46921421932SMike Pritchard.Bx 4.4 .
470