mirror of
https://github.com/RobTillaart/Arduino.git
synced 2024-10-03 18:09:02 -04:00
add Set 0.2.4
This commit is contained in:
parent
1e2905b81e
commit
d0f103197b
@ -68,7 +68,7 @@ all iterator-functions returns the current element or -1 if not exist.
|
||||
- **next()** find the next element. Will not wrap zround when 'end' of the set is reached.
|
||||
- **prev()** find the previous element. Will not wrap zround when 'begin' of the set is reached.
|
||||
- **last()** find the last element.
|
||||
|
||||
- **getNth(n)** find the Nth element in a set if it exist.
|
||||
|
||||
## Operational
|
||||
|
||||
|
@ -1,12 +1,13 @@
|
||||
//
|
||||
// FILE: set.cpp
|
||||
// AUTHOR: Rob Tillaart
|
||||
// VERSION: 0.2.3
|
||||
// VERSION: 0.2.4
|
||||
// DATE: 2014-09-11
|
||||
// PURPOSE: SET library for Arduino
|
||||
// URL: https://github.com/RobTillaart/SET
|
||||
//
|
||||
// HISTORY:
|
||||
// 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
|
||||
@ -264,6 +265,21 @@ int Set::last()
|
||||
}
|
||||
|
||||
|
||||
int Set::getNth(const uint8_t n)
|
||||
{
|
||||
if (n == 0) return -1;
|
||||
if (n == 1) return first();
|
||||
_current = first();
|
||||
int i = 1;
|
||||
while ((_current > -1) && (i < n))
|
||||
{
|
||||
_current = next();
|
||||
i++;
|
||||
}
|
||||
return _current;
|
||||
}
|
||||
|
||||
|
||||
int Set::findPrev(const uint8_t p, uint8_t q)
|
||||
{
|
||||
uint8_t m = 1 << q;
|
||||
|
@ -2,7 +2,7 @@
|
||||
//
|
||||
// FILE: set.h
|
||||
// AUTHOR: Rob Tillaart
|
||||
// VERSION: 0.2.3
|
||||
// VERSION: 0.2.4
|
||||
// DATE: 2014-09-11
|
||||
// PURPOSE: SET library for Arduino
|
||||
// URL: https://github.com/RobTillaart/SET
|
||||
@ -11,7 +11,7 @@
|
||||
#include "Arduino.h"
|
||||
|
||||
|
||||
#define SET_LIB_VERSION (F("0.2.3"))
|
||||
#define SET_LIB_VERSION (F("0.2.4"))
|
||||
|
||||
|
||||
class Set
|
||||
@ -59,7 +59,7 @@ public:
|
||||
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:
|
||||
uint8_t _mem[32]; // can hold 0..255
|
||||
|
@ -20,7 +20,7 @@ first KEYWORD2
|
||||
next KEYWORD2
|
||||
prev KEYWORD2
|
||||
last KEYWORD2
|
||||
|
||||
getNth KEYWORD2
|
||||
|
||||
# Constants (LITERAL1)
|
||||
SET_LIB_VERSION LITERAL1
|
||||
|
@ -15,7 +15,8 @@
|
||||
"type": "git",
|
||||
"url": "https://github.com/RobTillaart/SET.git"
|
||||
},
|
||||
"version":"0.2.3",
|
||||
"version": "0.2.4",
|
||||
"license": "MIT",
|
||||
"frameworks": "arduino",
|
||||
"platforms": "*"
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
name=SET
|
||||
version=0.2.3
|
||||
version=0.2.4
|
||||
author=Rob Tillaart <rob.tillaart@gmail.com>
|
||||
maintainer=Rob Tillaart <rob.tillaart@gmail.com>
|
||||
sentence=Arduino library to implement simple SET datastructure.
|
||||
|
@ -147,6 +147,48 @@ unittest(test_operator)
|
||||
assertTrue( C <= B);
|
||||
}
|
||||
|
||||
|
||||
unittest(test_iterator)
|
||||
{
|
||||
fprintf(stderr, "VERSION: %s\n", SET_LIB_VERSION);
|
||||
|
||||
Set A;
|
||||
A.clear();
|
||||
|
||||
for (int i = 0; i < 20; i++)
|
||||
{
|
||||
A.add(i*3);
|
||||
}
|
||||
assertEqual(20, A.count());
|
||||
|
||||
fprintf(stderr, "\nFirst() -> next()\n");
|
||||
int cur = A.first();
|
||||
for (int i = 0; i < 20; i++)
|
||||
{
|
||||
assertEqual(i * 3, cur);
|
||||
cur = A.next();
|
||||
}
|
||||
|
||||
fprintf(stderr, "\nlast() -> prev()\n");
|
||||
cur = A.last();
|
||||
for (int i = 19; i > 0; i--)
|
||||
{
|
||||
assertEqual(i * 3, cur);
|
||||
cur = A.prev();
|
||||
}
|
||||
|
||||
fprintf(stderr, "\ngetNth()\n");
|
||||
assertEqual(0, A.getNth(1));
|
||||
assertEqual(3, A.getNth(2));
|
||||
assertEqual(6, A.getNth(3));
|
||||
assertEqual(9, A.getNth(4));
|
||||
assertEqual(12, A.getNth(5));
|
||||
assertEqual(15, A.getNth(6));
|
||||
assertEqual(18, A.getNth(7));
|
||||
assertEqual(21, A.getNth(8));
|
||||
|
||||
}
|
||||
|
||||
unittest_main()
|
||||
|
||||
// --------
|
||||
|
Loading…
x
Reference in New Issue
Block a user