-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbitset.h
55 lines (44 loc) · 1.51 KB
/
bitset.h
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
#ifndef BITSET_H
#define BITSET_H
#include <stdbool.h>
#include <stddef.h>
typedef struct bitset {
int *arr;
size_t len;
} bitset;
/* Return a bitset of size and value based on val */
bitset *BitsetMake(const size_t size, unsigned long val);
/* Free bitset */
void BitsetDestroy(bitset *b);
/* Get bit at particular position */
int BitsetGet(const bitset *b, const size_t pos);
/* See if bits are:
* All are true
* Any being true
* None are true */
bool BitsetAllTrue(const bitset *b);
bool BitsetAnyTrue(const bitset *b);
bool BitsetNoneTrue(const bitset *b);
/* Return the amount of true or false */
int BitsetAmountTrue(const bitset *b);
int BitsetAmountFalse(const bitset *b);
/* Set all to be true/false */
void BitsetSetTrue(const bitset *b);
void BitsetSetFalse(const bitset *b);
/* Set a certain bit at pos to val */
void BitsetSet(const bitset *b, const size_t pos, const bool val);
/* Flip all bits or flip at pos */
void BitsetFlip(const bitset *b);
void BitsetFlipAt(const bitset *b, const size_t pos);
/* Converts the bitset into string and write into buf */
void BitsetToString(const bitset *b, char *buf, const char zero,
const char one);
/* Converts the bitset into unsigned long */
unsigned long BitsetToULong(const bitset *b);
/* bitwise operations */
void BitsetAND(bitset *b, const bitset *other);
void BitsetOR(bitset *b, const bitset *other);
void BitsetXOR(bitset *b, const bitset *other);
void BitsetLeftShift(bitset *b, const size_t pos);
void BitsetRightShift(bitset *b, const size_t pos);
#endif