+ 0.1.04 support for + - *,

+ clean up code
+ first stable version.
This commit is contained in:
rob tillaart 2014-11-16 19:10:49 +01:00
parent 90e6127c27
commit f180f8100a
2 changed files with 35 additions and 20 deletions

View File

@ -1,11 +1,12 @@
//
// FILE: set.cpp
// AUTHOR: Rob Tillaart
// VERSION: 0.1.03
// VERSION: 0.1.04
// PURPOSE: SET library for Arduino
// URL:
//
// HISTORY:
// 0.1.04 support for + - *, some optimizations
// 0.1.03 changed &= to *= to follow Pascal conventions
// 0.1.02 documentation
// 0.1.01 extending/refactor etc (09/11/2014)
@ -27,7 +28,7 @@ set::set()
set::set(set &t)
{
for (int i=0; i<32; i++)
for (uint8_t i=0; i<32; i++)
{
_mem[i] = t._mem[i];
}
@ -161,12 +162,35 @@ int set::last()
//
// OPERATORS
//
void set::operator = (set &t) // assign
set set::operator + (set &t) // union
{
set s(t);
for (uint8_t i=0; i<32; i++)
{
_mem[i] = t._mem[i];
s._mem[i] |= this->_mem[i];
}
return s;
}
set set::operator - (set &t) // union
{
set s(t);
for (uint8_t i=0; i<32; i++)
{
s._mem[i] &= ~(this->_mem[i]);
}
return s;
}
set set::operator * (set &t) // union
{
set s(t);
for (uint8_t i=0; i<32; i++)
{
s._mem[i] &= this->_mem[i];
}
return s;
}
void set::operator += (set &t) // union

View File

@ -1,7 +1,7 @@
//
// FILE: set.h
// AUTHOR: Rob Tillaart
// VERSION: 0.1.03
// VERSION: 0.1.04
// PURPOSE: SET library for Arduino
// URL:
//
@ -18,32 +18,28 @@
#include <Arduino.h>
#endif
#define SET_LIB_VERSION "0.1.03"
#define SET_LIB_VERSION "0.1.04"
class set
{
public:
set(); // create empty set
set(set &t); // create copy set
// TODO ??
// set(uint8_t*, uint8_t); // constructor from uint8_t array
// set(uint8_t size); // constructor with restricted size
void clr(); // clear the set
void invert(); // flip all elements in the set
uint8_t count(); // return the #elements
inline bool isEmpty() { return count() == 0; };
// TODO
// inline uint8_t size() { return _size; };
// inline bool isfull() { return count() == 256; };
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
void operator = (set &t); // assignment
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
@ -53,20 +49,15 @@ public:
bool operator <= (set&); // is subset
// iterating through the set
// returns value
// or -1 if not exist
// 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
// uint8_t _cnt;
// uint8_t _size;
int _current;
};
#endif
//