-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBitSet.h
More file actions
110 lines (90 loc) · 2.89 KB
/
BitSet.h
File metadata and controls
110 lines (90 loc) · 2.89 KB
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
/*
* File: BitSet.h
* Creator: George Ferguson
* Created: Fri Jul 1 09:41:51 2016
* Time-stamp: <Fri Aug 4 09:31:27 EDT 2017 ferguson>
*
* A BitSet represents a set of integers using bits of an int.
* This makes most of the set operations constant-time.
* The maximum value that can be stored in the set is limited
* by the number of bits in the biggest int we can get
* (typically 64, sometimes 32).
*/
#ifndef _BitSet_h
#define _BitSet_h
#include <stdbool.h>
typedef struct BitSet *BitSet;
/**
* Return the largest value that can be stored in a BitSet.
* BitSets can store elements with values from 0 to this value.
*/
extern int BitSet_maxValue();
/**
* Allocate, initialize and return a new (empty) BitSet.
*/
extern BitSet new_BitSet();
/**
* Free the memory used for the given Bitset.
*/
extern void BitSet_free(BitSet this);
/**
* Return true if the given BitSet is empty.
*/
extern bool BitSet_isEmpty(const BitSet this);
/**
* Add given element (int) to the given BitSet (if it's not already there).
* The maximum element value that can be stored in a BitSet is limited
* by the number of bits in a long int (typically 64, sometimes 32).
*/
extern void BitSet_insert(BitSet this, int value);
/**
* Return true if the given BitSet contains the given int value.
*/
extern bool BitSet_lookup(const BitSet this, int value);
/**
* Add the contents of the second BitSet to the first BitSet (adding those elements
* that aren't already in set1). This will modify the first set unless the second
* set is empty or all its elements are already in in the first set.
*/
extern void BitSet_union(BitSet this, const BitSet other);
/**
* Return true if the first BitSet contains every member of the second
* BitSet.
*/
extern bool BitSet_containsAll(BitSet this, BitSet other);
/**
* Return true if the two given BitSet contain exactly the same members,
* otherwise false.
*/
extern bool BitSet_equals(BitSet this, BitSet other);
/**
* Call the given function on each element of given BitSet, passing the
* int value to the function.
*/
extern void IntSet_iterate(const BitSet this, void (*func)(int));
typedef struct BitSetIterator *BitSetIterator;
/**
* Return an BitSetIterator for the given BitSet.
* Don't forget to free() this when you're done iterating.
*/
extern BitSetIterator BitSet_iterator(const BitSet set);
/**
* Return true if the given BitSetIterator will return another element
* if BitSetIterator_next() is called.
*/
extern bool BitSetIterator_hasNext(const BitSetIterator this);
/**
* Return the next int from the given BitSetIterator and increment it
* to point to the next element.
*/
extern int BitSetIterator_next(BitSetIterator this);
/**
* Print the given BitSet to stdout.
*/
extern void BitSet_print(BitSet this);
/**
* Return the string representation of the given BitSet.
* Don't forget to free() this string.
*/
extern char *BitSet_toString(BitSet this);
#endif