forked from RobTillaart/Arduino
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSet.h
More file actions
67 lines (55 loc) · 1.68 KB
/
Set.h
File metadata and controls
67 lines (55 loc) · 1.68 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
//
// FILE: Set.h
// AUTHOR: Rob Tillaart
// VERSION: 0.1.07
// PURPOSE: SET library for Arduino
// URL:
//
// HISTORY:
// see Set.cpp file
//
#ifndef Set_h
#define Set_h
#if ARDUINO < 100
#include <WProgram.h>
#else
#include <Arduino.h>
#endif
#define SET_LIB_VERSION "0.1.07"
class Set
{
public:
Set(bool clear = true); // create empty Set
Set(const Set &t); // create copy Set
void clr(); // clear the Set
void invert(); // flip all elements in the Set
uint8_t count(); // return the #elements
void add(uint8_t); // add element to the Set
void sub(uint8_t); // remove element from Set
void invert(uint8_t); // flip element in Set
bool has(uint8_t); // element is in Set
Set operator + (Set &t); // union
Set operator - (Set &t); // diff
Set operator * (Set &t); // intersection
void operator += (Set &t); // union
void operator -= (Set &t); // diff
void operator *= (Set &t); // intersection
bool operator == (Set&); // equal
bool operator != (Set&); // not equal
bool operator <= (Set&); // is subSet
// iterating through the Set
// returns value or -1 if not exist
int first(); // find first element
int next(); // find next element
int prev(); // find previous element
int last(); // find last element
private:
uint8_t _mem[32]; // can hold 0..255
int _current;
int findNext(uint8_t, uint8_t); // helper for first, next
int findPrev(uint8_t, uint8_t); // helper for last, prev
};
#endif
//
// END OF FILE
//