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

77 lines
2.4 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
2022-11-24 05:20:43 -05:00
// VERSION: 0.2.6
2020-11-27 05:33:55 -05:00
// 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
2021-01-29 06:31:58 -05:00
#include "Arduino.h"
2022-11-24 05:20:43 -05:00
#define SET_LIB_VERSION (F("0.2.6"))
2021-01-29 06:31:58 -05:00
2014-11-18 13:28:12 -05:00
class Set
{
public:
2022-11-24 05:20:43 -05:00
explicit Set(const bool clear = true); // create empty Set
Set(const Set &t); // create copy Set
void clear(); // clear the Set
void clr() { clear(); }; // will become obsolete 0.3.0
void invert(); // flip all elements in the Set
void addAll(); // add all elements
uint16_t count() const; // return the #elements
2021-01-29 06:31:58 -05:00
bool isEmpty();
bool isFull();
2022-11-24 05:20:43 -05:00
void add(const uint8_t value); // add element to the Set
void sub(const uint8_t value); // remove element from Set
void invert(const uint8_t value); // flip element in Set
bool has(const uint8_t value); // element is in Set
2021-01-29 06:31:58 -05:00
2014-11-18 13:28:12 -05:00
2022-11-24 05:20:43 -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
2022-11-24 05:20:43 -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
2021-01-29 06:31:58 -05:00
2022-11-24 05:20:43 -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
2021-01-29 06:31:58 -05:00
2022-11-24 05:20:43 -05:00
// iterating through the Set
// returns value or -1 if not exist
int setCurrent(const uint8_t current); // set element as current
int first(); // find first element
int next(); // find next element
int prev(); // find previous element
int last(); // find last element
int getNth(const uint8_t n); // find Nth element in a set (from start)
2021-12-28 04:38:33 -05:00
2014-11-18 13:28:12 -05:00
private:
uint8_t _mem[32]; // can hold 0..255
2021-12-28 04:38:33 -05:00
uint8_t _masks[8] = {1, 2, 4, 8, 16, 32, 64, 128};
2020-11-27 05:33:55 -05:00
int _current = -1;
2022-11-24 05:20:43 -05:00
int findNext(const uint8_t p, const uint8_t q); // helper for first, next
int findPrev(const uint8_t p, const uint8_t q); // helper for last, prev
2014-11-18 13:28:12 -05:00
};
2020-11-27 05:33:55 -05:00
2021-12-28 04:38:33 -05:00
2020-11-27 05:33:55 -05:00
// -- END OF FILE --
2021-12-28 04:38:33 -05:00