|
1 | 1 | // |
2 | 2 | // FILE: set.h |
3 | 3 | // AUTHOR: Rob Tillaart |
4 | | -// VERSION: 0.1.01 |
| 4 | +// VERSION: 0.1.02 |
5 | 5 | // PURPOSE: SET library for Arduino |
6 | 6 | // URL: |
7 | 7 | // |
|
18 | 18 | #include <Arduino.h> |
19 | 19 | #endif |
20 | 20 |
|
21 | | -#define SET_LIB_VERSION "0.1.01" |
| 21 | +#define SET_LIB_VERSION "0.1.02" |
22 | 22 |
|
23 | 23 | class set |
24 | 24 | { |
25 | 25 | public: |
26 | | - set(); |
27 | | - set(set&); |
| 26 | + set(); // create empty set |
| 27 | + set(set &t); // create copy set |
28 | 28 |
|
29 | | - void clr(); |
30 | | - void invert(); |
31 | | - uint8_t count(); |
| 29 | + void clr(); // clear the set |
| 30 | + void invert(); // flip all elements in the set |
| 31 | + uint8_t count(); // return the #elements |
32 | 32 |
|
33 | | - void add(uint8_t); |
34 | | - void sub(uint8_t); |
35 | | - void invert(uint8_t); |
36 | | - bool has(uint8_t); |
| 33 | + void add(uint8_t); // add element to the set |
| 34 | + void sub(uint8_t); // remove element from set |
| 35 | + void invert(uint8_t); // flip element in set |
| 36 | + bool has(uint8_t); // element is in set |
37 | 37 |
|
38 | | - void operator = (set &t); // assign |
39 | | - void operator += (set &t); |
40 | | - void operator -= (set &t); |
41 | | - void operator &= (set &t); |
| 38 | + void operator = (set &t); // assignment |
| 39 | + void operator += (set &t); // union |
| 40 | + void operator -= (set &t); // diff |
| 41 | + void operator &= (set &t); // intersection |
42 | 42 |
|
43 | | - bool operator == (set&); |
44 | | - bool operator != (set&); |
45 | | - bool operator <= (set&); |
| 43 | + bool operator == (set&); // equal |
| 44 | + bool operator != (set&); // not equal |
| 45 | + bool operator <= (set&); // is subset |
46 | 46 |
|
47 | | - int first(); |
48 | | - int next(); |
49 | | - int prev(); |
50 | | - int last(); |
| 47 | + // iterating through the set |
| 48 | + // returns value |
| 49 | + // or -1 if not exist |
| 50 | + int first(); // find first element |
| 51 | + int next(); // find next element |
| 52 | + int prev(); // find previous element |
| 53 | + int last(); // find last element |
51 | 54 |
|
52 | | - // TODO |
| 55 | + // TODO ?? |
53 | 56 | // set(uint8_t*, uint8_t); // constructor from uint8_t array |
54 | | - // uint8_t size(); |
55 | | - // iterator - begin, next |
56 | | - |
57 | | - // uint8_t max(); |
58 | | - // uint8_t min(); |
| 57 | + // inline uint8_t size() { return _size; }; |
59 | 58 | // inline bool empty() { return count() == 0; }; |
60 | | - // inline bool full() { return count() == 256; }; |
| 59 | + // inline bool full() { return count() == _size; }; |
61 | 60 |
|
62 | 61 | private: |
63 | 62 | uint8_t _mem[32]; // can hold 0..255 |
|
0 commit comments