mirror of
https://github.com/RobTillaart/Arduino.git
synced 2024-09-19 16:46:11 -04:00
+ 0.1.11 fix count() + added isFull()
This commit is contained in:
parent
28d5d815a0
commit
40812a0d93
@ -1,11 +1,12 @@
|
||||
//
|
||||
// FILE: Set.cpp
|
||||
// AUTHOR: Rob Tillaart
|
||||
// VERSION: 0.1.10
|
||||
// VERSION: 0.1.11
|
||||
// PURPOSE: SET library for Arduino
|
||||
// URL:
|
||||
//
|
||||
// HISTORY:
|
||||
// 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()
|
||||
@ -74,9 +75,9 @@ bool Set::has(const uint8_t v)
|
||||
return (_mem[idx] & masks[v&7]) > 0;
|
||||
}
|
||||
|
||||
uint8_t Set::count() const
|
||||
uint16_t Set::count() const
|
||||
{
|
||||
uint8_t cnt = 0;
|
||||
uint16_t cnt = 0;
|
||||
for (uint8_t i=0; i<32; i++)
|
||||
{
|
||||
// kerningham bit count trick
|
||||
@ -104,9 +105,6 @@ void Set::invert()
|
||||
|
||||
bool Set::isEmpty()
|
||||
{
|
||||
// uint8_t i = 31;
|
||||
// while (!_mem[i--]);
|
||||
// return (i==0);
|
||||
for (uint8_t i=0; i<32; i++)
|
||||
{
|
||||
if (_mem[i]) return false;
|
||||
@ -114,6 +112,15 @@ bool Set::isEmpty()
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Set::isFull()
|
||||
{
|
||||
for (uint8_t i=0; i<32; i++)
|
||||
{
|
||||
if (_mem[i] != 255) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
int Set::first()
|
||||
{
|
||||
return findNext(0,0);
|
||||
|
@ -1,7 +1,7 @@
|
||||
//
|
||||
// FILE: Set.h
|
||||
// AUTHOR: Rob Tillaart
|
||||
// VERSION: 0.1.10
|
||||
// VERSION: 0.1.11
|
||||
// PURPOSE: SET library for Arduino
|
||||
// URL:
|
||||
//
|
||||
@ -18,7 +18,7 @@
|
||||
#include <Arduino.h>
|
||||
#endif
|
||||
|
||||
#define SET_LIB_VERSION "0.1.10"
|
||||
#define SET_LIB_VERSION "0.1.11"
|
||||
|
||||
class Set
|
||||
{
|
||||
@ -28,9 +28,10 @@ public:
|
||||
|
||||
void clr(); // clear the Set
|
||||
void invert(); // flip all elements in the Set
|
||||
uint8_t count() const; // return the #elements
|
||||
uint16_t count() const; // return the #elements
|
||||
bool isEmpty();
|
||||
|
||||
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
|
||||
|
@ -1,7 +1,7 @@
|
||||
//
|
||||
// FILE: allTest.ino
|
||||
// AUTHOR: Rob Tillaart
|
||||
// VERSION: 0.1.1
|
||||
// VERSION: 0.1.3
|
||||
// PURPOSE: demo/test Set class
|
||||
// DATE: 2014-11-16
|
||||
// URL:
|
||||
@ -93,10 +93,30 @@ void timingTest()
|
||||
Serial.println(stop-start);
|
||||
Serial.println();
|
||||
|
||||
Serial.print("isEmpty():\t");
|
||||
Serial.print("100x isEmpty(): empty\t");
|
||||
myset.clr();
|
||||
start = micros();
|
||||
myset.count();
|
||||
for (uint8_t i=0; i<100; i++) b = myset.isEmpty();
|
||||
stop = micros();
|
||||
Serial.println(stop-start);
|
||||
Serial.print("100x isEmpty(): full\t");
|
||||
myset.clr();
|
||||
myset.invert();
|
||||
start = micros();
|
||||
for (uint8_t i=0; i<100; i++) b = myset.isEmpty();
|
||||
stop = micros();
|
||||
Serial.println(stop-start);
|
||||
Serial.print("100x isFull(): empty\t");
|
||||
myset.clr();
|
||||
start = micros();
|
||||
for (uint8_t i=0; i<100; i++) b = myset.isFull();
|
||||
stop = micros();
|
||||
Serial.println(stop-start);
|
||||
Serial.print("100x isFull(): full\t");
|
||||
myset.clr();
|
||||
myset.invert();
|
||||
start = micros();
|
||||
for (uint8_t i=0; i<100; i++) b = myset.isFull();
|
||||
stop = micros();
|
||||
Serial.println(stop-start);
|
||||
Serial.println();
|
||||
|
92
libraries/Set/examples/allTest/reference 0.1.11.txt
Normal file
92
libraries/Set/examples/allTest/reference 0.1.11.txt
Normal file
@ -0,0 +1,92 @@
|
||||
Start set_demo : 0.1.11
|
||||
|
||||
TIMING TEST
|
||||
100x clr(): 1204
|
||||
100x add(): 244
|
||||
100x sub(): 188
|
||||
100x has(): 200
|
||||
100x invert(v): 184
|
||||
invert(): 20
|
||||
count() empty: 24
|
||||
count() full: 184
|
||||
|
||||
100x isEmpty(): empty 1620
|
||||
100x isEmpty(): full 84
|
||||
100x isFull(): empty 84
|
||||
100x isFull(): full 1620
|
||||
|
||||
a = b + c: 64
|
||||
a = b - c: 60
|
||||
a = b * c: 64
|
||||
a += b: 24
|
||||
a -= b: 24
|
||||
a *= b: 36
|
||||
a == b: 4
|
||||
a != b: 4
|
||||
a <= b: 4
|
||||
|
||||
iteration 10 elements
|
||||
first: 12
|
||||
next: 16
|
||||
first + next until -1 : 152
|
||||
last + prev until -1 : 144
|
||||
|
||||
|
||||
EQUAL TEST
|
||||
true
|
||||
false
|
||||
true
|
||||
true
|
||||
1
|
||||
equal
|
||||
true
|
||||
1
|
||||
false
|
||||
0
|
||||
|
||||
INTERSECTION TEST
|
||||
110
|
||||
116
|
||||
51
|
||||
|
||||
union test
|
||||
110
|
||||
116
|
||||
175
|
||||
|
||||
diff test
|
||||
110
|
||||
116
|
||||
59
|
||||
|
||||
INTERSECTION2 TEST
|
||||
110
|
||||
116
|
||||
51
|
||||
|
||||
union2 test
|
||||
110
|
||||
116
|
||||
175
|
||||
|
||||
diff2 test
|
||||
110
|
||||
116
|
||||
59
|
||||
|
||||
SUBSET TEST
|
||||
5
|
||||
5
|
||||
subset
|
||||
subset
|
||||
subset
|
||||
no subset
|
||||
no subset
|
||||
no subset
|
||||
|
||||
ITERATE OVER SET TEST
|
||||
10
|
||||
42 67 77 130 167 200 216 217 241 254
|
||||
254 241 217 216 200 167 130 77 67 42
|
||||
done...
|
||||
|
@ -1,5 +1,5 @@
|
||||
name=Set
|
||||
version=0.1.10
|
||||
version=0.1.11
|
||||
author=Rob Tillaart <rob.tillaart@gmail.com>
|
||||
maintainer=Rob Tillaart <rob.tillaart@gmail.com>
|
||||
sentence=Library to implement SET datastructure.
|
||||
|
Loading…
Reference in New Issue
Block a user