Papageno
An Advanced Pattern Matching Library
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros
ppg_bitfield.h
1 /* Copyright 2017 noseglasses <shinynoseglasses@gmail.com>
2  *
3  * This program is free software: you can redistribute it and/or modify
4  * it under the terms of the GNU Lesser General Public License as published by
5  * the Free Software Foundation, either version 3 of the License, or
6  * (at your option) any later version.
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU Lesser General Public License for more details.
12  *
13  * You should have received a copy of the GNU Lesser General Public License
14  * along with this program. If not, see <http://www.gnu.org/licenses/>.
15  */
16 
17 #ifndef PPG_BITFIELD_H
18 #define PPG_BITFIELD_H
19 
20 #include "ppg_settings.h"
21 
22 #include <stdint.h>
23 #include <stdbool.h>
24 
25 typedef uint8_t PPG_Bitfield_Storage_Type;
26 
29 typedef struct {
30 
31  // Use a bitarray to store input state
32  //
33  PPG_Bitfield_Storage_Type *bitarray;
34 
35  uint8_t n_bits;
36 
37 } PPG_Bitfield;
38 
46 void ppg_bitfield_init(PPG_Bitfield *bitfield);
47 
54 void ppg_bitfield_resize(PPG_Bitfield *bitfield,
55  uint8_t n_bits,
56  bool keep_content);
57 
62 PPG_Count ppg_bitfield_get_num_cells(PPG_Bitfield *bitfield);
63 PPG_Count ppg_bitfield_get_num_cells_from_bits(uint8_t n_bits);
64 
70 void ppg_bitfield_clear(PPG_Bitfield *bitfield);
71 
77 bool ppg_bitfield_get_bit(PPG_Bitfield *bitfield,
78  PPG_Count pos);
79 
86 void ppg_bitfield_set_bit(PPG_Bitfield *bitfield,
87  PPG_Count pos,
88  bool state);
89 
97 void ppg_bitfield_copy(PPG_Bitfield *source, PPG_Bitfield *target);
98 
103 void ppg_bitfield_destroy(PPG_Bitfield *bitfield);
104 
105 #endif
A bitfield data type that can efficiently store boolean variables.
Definition: ppg_bitfield.h:29
uint8_t n_bits
The number of bits that are considered as mutable.
Definition: ppg_bitfield.h:35
PPG_Bitfield_Storage_Type * bitarray
The actual storage.
Definition: ppg_bitfield.h:33