0.2.6 SET

This commit is contained in:
rob tillaart 2022-11-24 11:20:43 +01:00
parent 47196dbab8
commit 992a734480
7 changed files with 152 additions and 83 deletions

View File

@ -1,11 +1,27 @@
platforms:
rpipico:
board: rp2040:rp2040:rpipico
package: rp2040:rp2040
gcc:
features:
defines:
- ARDUINO_ARCH_RP2040
warnings:
flags:
packages:
rp2040:rp2040:
url: https://github.com/earlephilhower/arduino-pico/releases/download/global/package_rp2040_index.json
compile:
# Choosing to run compilation tests on 2 different Arduino platforms
platforms:
- uno
- due
- zero
- leonardo
# - due
# - zero
# - leonardo
- m4
- esp32
- esp8266
- mega2560
# - mega2560
- rpipico

View File

@ -0,0 +1,77 @@
# Change Log SET
All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).
## [0.2.6] - 2022-10-28
- Add RP2040 support to build-CI.
- Add CHANGELOG.md
## [0.2.5] - 2021-12-28
- update library.json
- update readme
- update license
- minor edits
## [0.2.4] - 2021-05-06
- getNth(n)
## [0.2.3] - 2021-05-05
- Add addAll (256 elements)
- setCurrent
## [0.2.2] - 2021-01-07
- Arduino-CI, unit test
## [0.2.1] - 2020-06-19
- fix library.json
## [0.2.0] - 2020-05-02
- refactored
- removed pre 1.0 support
----
## [0.1.11] - 2017-07-16
- fix count() --> 16 bit when set is full !
## [0.1.10] - 2017-07-16
- performance refactor
- isEmpty()
## [0.1.09] - 2015-07-12
- add const + constructor
## [0.1.08]
- memset for clr()
## [0.1.07]
- faster first/next/last/prev; interface
## [0.1.06]
- added flag to constructor to optimize +,-,*,
- set -> Set
## [0.1.05]
- bug fixing + performance a.o. count()
## [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)
## [0.1.00]
- initial version by Rob Tillaart (09/11/2014)

View File

@ -82,6 +82,4 @@ See examples
## Future
- update documentation
- separate releaseNotes.md

View File

@ -1,32 +1,10 @@
//
// FILE: set.cpp
// AUTHOR: Rob Tillaart
// VERSION: 0.2.5
// VERSION: 0.2.6
// DATE: 2014-09-11
// PURPOSE: SET library for Arduino
// URL: https://github.com/RobTillaart/SET
//
// HISTORY:
// 0.2.5 2021-12-28 update library.json, readme, license, minor edits
// 0.2.4 2021-05-06 getNth(n)
// 0.2.3 2021-05-05 Add addAll (256 elements) + setCurrent
// 0.2.2 2021-01-07 Arduino-CI, unit test
// 0.2.1 2020-06-19 fix library.json
// 0.2.0 2020-05-02 refactored, removed pre 1.0 support
// 0.1.11 2017-07-16 fix count() --> 16 bit when set is full !
// 0.1.10 2017-07-16 performance refactor. isEmpty()
// 0.1.09 2015-07-12 const + constructor
// 0.1.08 memset for clr()
// 0.1.07 faster first/next/last/prev; interface
// 0.1.06 added flag to constructor to optimize +,-,*,
// set -> Set
// 0.1.05 bug fixing + performance a.o. count()
// 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)
// 0.1.00 initial version by Rob Tillaart (09/11/2014)
//
#include "set.h"
@ -34,7 +12,7 @@
/////////////////////////////////////////////////////
//
// CONSTRUCTORS
// CONSTRUCTORS
//
Set::Set(const bool clear)
{
@ -58,7 +36,7 @@ Set::Set(const Set &t)
/////////////////////////////////////////////////////
//
// METHODS
// METHODS
//
void Set::add(const uint8_t value)
{
@ -101,7 +79,7 @@ uint16_t Set::count() const
uint8_t i = 32;
do
{
// Kerningham bit count trick
// Kerningham bit count trick
uint8_t b = _mem[--i];
for (; b; cnt++)
{
@ -144,10 +122,10 @@ bool Set::isEmpty()
bool Set::isFull()
{
// check two elements per loop
// is faster for full sets but slower for empty set.
// footprint is ~25 bytes larger
// overall performance gain
// check two elements per loop
// is faster for full sets but slower for empty set.
// footprint is ~25 bytes larger
// overall performance gain
uint8_t i = 32;
do
{
@ -228,7 +206,7 @@ int Set::findNext(const uint8_t p, uint8_t q)
uint8_t b = _mem[i];
if (b != 0)
{
uint8_t mask = 1 << q; // _masks[q]
uint8_t mask = 1 << q; // _masks[q]
for (uint8_t j = q; j < 8; j++)
{
if (b & mask)
@ -325,7 +303,7 @@ Set Set::operator + (const Set &t) // union
}
Set Set::operator - (const Set &t) // diff
Set Set::operator - (const Set &t) // diff
{
Set s(false);
for (uint8_t i = 0; i < 32; i++)
@ -336,7 +314,7 @@ Set Set::operator - (const Set &t) // diff
}
Set Set::operator * (const Set &t) // intersection
Set Set::operator * (const Set &t) // intersection
{
Set s(false);
for (uint8_t i = 0; i < 32; i++)
@ -347,7 +325,7 @@ Set Set::operator * (const Set &t) // intersection
}
void Set::operator += (const Set &t) // union
void Set::operator += (const Set &t) // union
{
for (uint8_t i = 0; i < 32; i++)
{
@ -356,7 +334,7 @@ void Set::operator += (const Set &t) // union
}
void Set::operator -= (const Set &t) // diff
void Set::operator -= (const Set &t) // diff
{
for (uint8_t i = 0; i < 32; i++)
{
@ -365,7 +343,7 @@ void Set::operator -= (const Set &t) // diff
}
void Set::operator *= (const Set &t) // intersection
void Set::operator *= (const Set &t) // intersection
{
for (uint8_t i = 0; i < 32; i++)
{
@ -374,7 +352,7 @@ void Set::operator *= (const Set &t) // intersection
}
bool Set::operator == (const Set &t) const // equal
bool Set::operator == (const Set &t) const // equal
{
for (uint8_t i = 0; i < 32; i++)
{
@ -384,7 +362,7 @@ bool Set::operator == (const Set &t) const // equal
}
bool Set::operator != (const Set &t) const // not equal
bool Set::operator != (const Set &t) const // not equal
{
for (uint8_t i = 0; i < 32; i++)
{
@ -394,7 +372,7 @@ bool Set::operator != (const Set &t) const // not equal
}
bool Set::operator <= (const Set &t) const // subSet
bool Set::operator <= (const Set &t) const // subSet
{
for (uint8_t i = 0; i < 32; i++)
{
@ -404,5 +382,5 @@ bool Set::operator <= (const Set &t) const // subSet
}
// -- END OF FILE --
// -- END OF FILE --

View File

@ -2,7 +2,7 @@
//
// FILE: set.h
// AUTHOR: Rob Tillaart
// VERSION: 0.2.5
// VERSION: 0.2.6
// DATE: 2014-09-11
// PURPOSE: SET library for Arduino
// URL: https://github.com/RobTillaart/SET
@ -11,55 +11,55 @@
#include "Arduino.h"
#define SET_LIB_VERSION (F("0.2.5"))
#define SET_LIB_VERSION (F("0.2.6"))
class Set
{
public:
explicit Set(const bool clear = true); // create empty Set
Set(const Set &t); // create copy Set
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
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
bool isEmpty();
bool isFull();
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
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
Set operator + (const Set &); // union
Set operator - (const Set &); // diff
Set operator * (const Set &); // intersection
Set operator + (const Set &); // union
Set operator - (const Set &); // diff
Set operator * (const Set &); // intersection
void operator += (const Set &); // union
void operator -= (const Set &); // diff
void operator *= (const Set &); // intersection
void operator += (const Set &); // union
void operator -= (const Set &); // diff
void operator *= (const Set &); // intersection
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
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
// 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)
// 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)
private:
@ -67,8 +67,8 @@ private:
uint8_t _masks[8] = {1, 2, 4, 8, 16, 32, 64, 128};
int _current = -1;
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
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
};

View File

@ -15,7 +15,7 @@
"type": "git",
"url": "https://github.com/RobTillaart/SET.git"
},
"version": "0.2.5",
"version": "0.2.6",
"license": "MIT",
"frameworks": "arduino",
"platforms": "*",

View File

@ -1,5 +1,5 @@
name=SET
version=0.2.5
version=0.2.6
author=Rob Tillaart <rob.tillaart@gmail.com>
maintainer=Rob Tillaart <rob.tillaart@gmail.com>
sentence=Arduino library to implement simple SET datastructure.