Lely core libraries  2.3.4
bitset.h File Reference

This header file is part of the utilities library; it contains the bitset declarations. More...

#include <lely/util/util.h>
Include dependency graph for bitset.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  bitset
 A variable-sized bitset. More...
 

Functions

int bitset_init (struct bitset *set, int size)
 Initializes a bitset. More...
 
void bitset_fini (struct bitset *set)
 Finalizes a bitset. More...
 
int bitset_size (const struct bitset *set)
 Returns the size (in number of bits) of set.
 
int bitset_resize (struct bitset *set, int size)
 Resizes a bitset. More...
 
int bitset_test (const struct bitset *set, int n)
 Returns 1 if bit n in set is set, and 0 otherwise.
 
void bitset_set (struct bitset *set, int n)
 Sets bit n in set.
 
void bitset_set_all (struct bitset *set)
 Sets all bits in set.
 
void bitset_clr (struct bitset *set, int n)
 Clears bit n in set.
 
void bitset_clr_all (struct bitset *set)
 Clears all bits in set.
 
void bitset_compl (struct bitset *set)
 Flip all bits in set.
 
int bitset_ffs (const struct bitset *set)
 Returns the index (starting from one) of the first set bit in set, or 0 if all bits are zero.
 
int bitset_ffz (const struct bitset *set)
 Returns the index (starting from one) of the first zero bit in set, or 0 if all bits are set.
 
int bitset_fns (const struct bitset *set, int n)
 Returns the index (starting from one) of the first set bit higher or equal to n in set, or 0 if all bits starting from n are zero.
 
int bitset_fnz (const struct bitset *set, int n)
 Returns the index (starting from one) of the first zero bit higher or equal to n in set, or 0 if all bits starting from n are set.
 

Detailed Description

This header file is part of the utilities library; it contains the bitset declarations.

Author
J. S. Seldenthuis jseld.nosp@m.enth.nosp@m.uis@l.nosp@m.ely..nosp@m.com

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Definition in file bitset.h.

Function Documentation

◆ bitset_init()

int bitset_init ( struct bitset set,
int  size 
)

Initializes a bitset.

On success, all bits are cleared.

Parameters
seta pointer to a bitset.
sizethe requested size (in number of bits) of the set. This number is rounded up to the nearest multiple of sizeof(int) * CHAR_BIT.
Returns
0 on success, or -1 on error. In the latter case, the error number can be obtained with get_errc().
See also
bitset_fini()

Definition at line 39 of file bitset.c.

◆ bitset_fini()

void bitset_fini ( struct bitset set)

Finalizes a bitset.

See also
bitset_init().

Definition at line 60 of file bitset.c.

◆ bitset_resize()

int bitset_resize ( struct bitset set,
int  size 
)

Resizes a bitset.

On success, if the set has grown, all new bits are cleared.

Parameters
seta pointer to a bitset.
sizethe requester size (in number of bits) of the set. This number is rounded up to the nearest multiple of sizeof(int) * CHAR_BIT.
Returns
the new size (in number of bits) of the bitset, or 0 on error. In the latter case, the error number can be obtained with get_errc().

Definition at line 76 of file bitset.c.