GY-63_MS5611/libraries/Set/Set.h

68 lines
2.0 KiB
C
Raw Normal View History

2020-11-27 05:33:55 -05:00
#pragma once
2014-11-18 13:28:12 -05:00
//
2020-11-27 05:33:55 -05:00
// FILE: set.h
2014-11-18 13:28:12 -05:00
// AUTHOR: Rob Tillaart
2020-11-27 05:33:55 -05:00
// VERSION: 0.2.1
// DATE: 2014-09-11
2014-11-18 13:28:12 -05:00
// PURPOSE: SET library for Arduino
2020-11-27 05:33:55 -05:00
// URL: https://github.com/RobTillaart/SET
2014-11-18 13:28:12 -05:00
//
// HISTORY:
// see Set.cpp file
//
#include <Arduino.h>
2020-11-27 05:33:55 -05:00
#define SET_LIB_VERSION "0.2.1"
2014-11-18 13:28:12 -05:00
class Set
{
public:
explicit Set(const bool clear = true); // create empty Set
Set(const Set &t); // create copy Set
2014-11-18 13:28:12 -05:00
void clr(); // clear the Set
void invert(); // flip all elements in the Set
2017-07-16 14:09:23 -04:00
uint16_t count() const; // return the #elements
bool isEmpty();
2017-07-16 14:09:23 -04:00
bool isFull();
void add(const uint8_t); // add element to the Set
void sub(const uint8_t); // remove element from Set
void invert(const uint8_t); // flip element in Set
bool has(const uint8_t); // element is in Set
2014-11-18 13:28:12 -05:00
Set operator + (const Set &); // union
Set operator - (const Set &); // diff
Set operator * (const Set &); // intersection
2014-11-18 13:28:12 -05:00
void operator += (const Set &); // union
void operator -= (const Set &); // diff
void operator *= (const Set &); // intersection
2014-11-18 13:28:12 -05:00
bool operator == (const Set &) const; // equal
bool operator != (const Set &) const; // not equal
bool operator <= (const Set &) const; // is subSet,
// a superSet b is not implemented as one could
// say b subSet a (b <= a)
// a <= b
2014-11-18 13:28:12 -05:00
// 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
2014-11-18 13:28:12 -05:00
private:
uint8_t _mem[32]; // can hold 0..255
uint8_t masks[8] = {1, 2, 4, 8, 16, 32, 64, 128};
2020-11-27 05:33:55 -05:00
int _current = -1;
int findNext(const uint8_t, const uint8_t); // helper for first, next
int findPrev(const uint8_t, const uint8_t); // helper for last, prev
2014-11-18 13:28:12 -05:00
};
2020-11-27 05:33:55 -05:00
// -- END OF FILE --