0.2.5 Set

This commit is contained in:
rob tillaart 2021-12-28 10:38:33 +01:00
parent 022135259f
commit 51a3493a59
17 changed files with 166 additions and 108 deletions

View File

@ -2,6 +2,10 @@ compile:
# Choosing to run compilation tests on 2 different Arduino platforms
platforms:
- uno
- leonardo
- due
- zero
- leonardo
- m4
- esp32
- esp8266
- mega2560

View File

@ -4,10 +4,14 @@ name: Arduino CI
on: [push, pull_request]
jobs:
arduino_ci:
runTest:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: Arduino-CI/action@master
# Arduino-CI/action@v0.1.1
- uses: ruby/setup-ruby@v1
with:
ruby-version: 2.6
- run: |
gem install arduino_ci
arduino_ci.rb

View File

@ -1,6 +1,6 @@
MIT License
Copyright (c) 2014-2021 Rob Tillaart
Copyright (c) 2014-2022 Rob Tillaart
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal

View File

@ -1,8 +1,11 @@
[![Arduino CI](https://github.com/RobTillaart/SET/workflows/Arduino%20CI/badge.svg)](https://github.com/marketplace/actions/arduino_ci)
[![Arduino-lint](https://github.com/RobTillaart/SET/actions/workflows/arduino-lint.yml/badge.svg)](https://github.com/RobTillaart/SET/actions/workflows/arduino-lint.yml)
[![JSON check](https://github.com/RobTillaart/SET/actions/workflows/jsoncheck.yml/badge.svg)](https://github.com/RobTillaart/SET/actions/workflows/jsoncheck.yml)
[![License: MIT](https://img.shields.io/badge/license-MIT-green.svg)](https://github.com/RobTillaart/SET/blob/master/LICENSE)
[![GitHub release](https://img.shields.io/github/release/RobTillaart/SET.svg?maxAge=3600)](https://github.com/RobTillaart/SET/releases)
# SET
Arduino library to implement a simple SET data structure.
@ -29,7 +32,7 @@ datatypes.
- **clear()** empty the set.
- **invert()** flip all elements in the set.
- **addAll(n)** add all 256 elements to the set.
- **addAll()** add all 256 elements to the set.
- **count()** returns the number of elements.
- **isEmpty()** idem
- **isFull()** idem
@ -37,10 +40,10 @@ datatypes.
### Element level
- **add(n)** add element n to the Set.
- **sub(n)** remove element n from the Set.
- **invert(n)** flip element n in the Set.
- **has(n)** check if element n is in the Set.
- **add(uint8_t value)** add element n to the Set.
- **sub(uint8_t value)** remove element n from the Set.
- **invert(uint8_t value)** flip element n in the Set.
- **has(uint8_t value)** check if element n is in the Set.
### Operators
@ -65,11 +68,20 @@ all iterator-functions returns the current element or -1 if not exist.
- **setCurrent(n)** if n is in the Set, n will be the current
- **first()** find the first element
- **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.
- **next()** find the next element. Will not wrap around when 'end' of the set is reached.
- **prev()** find the previous element. Will not wrap around 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
See examples
## Future
- update documentation
- separate releaseNotes.md

View File

@ -1,12 +1,13 @@
//
// FILE: set.cpp
// AUTHOR: Rob Tillaart
// VERSION: 0.2.4
// VERSION: 0.2.5
// 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
@ -30,6 +31,7 @@
#include "set.h"
/////////////////////////////////////////////////////
//
// CONSTRUCTORS
@ -58,24 +60,24 @@ Set::Set(const Set &t)
//
// METHODS
//
void Set::add(const uint8_t v)
void Set::add(const uint8_t value)
{
uint8_t idx = v / 8;
_mem[idx] |= masks[v & 7];
uint8_t idx = value / 8;
_mem[idx] |= _masks[value & 7];
}
void Set::sub(const uint8_t v)
void Set::sub(const uint8_t value)
{
uint8_t idx = v / 8;
_mem[idx] &= ~masks[v & 7];
uint8_t idx = value / 8;
_mem[idx] &= ~_masks[value & 7];
}
void Set::invert(const uint8_t v)
void Set::invert(const uint8_t value)
{
uint8_t idx = v / 8;
_mem[idx] ^= masks[v & 7];
uint8_t idx = value / 8;
_mem[idx] ^= _masks[value & 7];
}
@ -85,10 +87,10 @@ void Set::addAll()
}
bool Set::has(const uint8_t v)
bool Set::has(const uint8_t value)
{
uint8_t idx = v / 8;
return (_mem[idx] & masks[v & 7]) > 0;
uint8_t idx = value / 8;
return (_mem[idx] & _masks[value & 7]) > 0;
}
@ -99,7 +101,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,8 +146,8 @@ bool Set::isFull()
{
// check two elements per loop
// is faster for full sets but slower for empty set.
// footprint is ~25 bytese larger
// overal performance gain
// footprint is ~25 bytes larger
// overall performance gain
uint8_t i = 32;
do
{
@ -156,12 +158,12 @@ bool Set::isFull()
}
int Set::setCurrent(const uint8_t cur)
int Set::setCurrent(const uint8_t current)
{
_current = -1;
if (has(cur))
if (has(current))
{
_current = cur;
_current = current;
}
return _current;
}
@ -226,7 +228,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)
@ -401,4 +403,6 @@ bool Set::operator <= (const Set &t) const // subSet
return true;
}
// -- END OF FILE --

View File

@ -2,7 +2,7 @@
//
// FILE: set.h
// AUTHOR: Rob Tillaart
// VERSION: 0.2.4
// VERSION: 0.2.5
// 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.4"))
#define SET_LIB_VERSION (F("0.2.5"))
class Set
@ -29,10 +29,10 @@ public:
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
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
@ -54,20 +54,23 @@ public:
// iterating through the Set
// returns value or -1 if not exist
int setCurrent(const uint8_t); // set element as current
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:
uint8_t _mem[32]; // can hold 0..255
uint8_t masks[8] = {1, 2, 4, 8, 16, 32, 64, 128};
uint8_t _masks[8] = {1, 2, 4, 8, 16, 32, 64, 128};
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
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
};
// -- END OF FILE --

View File

@ -1,7 +1,6 @@
//
// FILE: allTest.ino
// AUTHOR: Rob Tillaart
// VERSION: 0.2.2
// PURPOSE: demo/test Set class
// DATE: 2014-11-16
// URL: https://github.com/RobTillaart/SET
@ -33,10 +32,12 @@ void setup()
Serial.println();
}
void loop()
{
}
void timingTest()
{
Set myset;
@ -239,6 +240,7 @@ void timingTest()
Serial.println();
}
void equalTest()
{
Serial.println("EQUAL TEST");
@ -266,6 +268,7 @@ void equalTest()
Serial.println();
}
void intersectionTest()
{
Serial.println("INTERSECTION TEST");
@ -315,6 +318,7 @@ void intersectionTest()
Serial.println();
}
void intersection2Test()
{
Serial.println("INTERSECTION2 TEST");
@ -348,6 +352,7 @@ void intersection2Test()
Serial.println();
}
void subsetTest()
{
Serial.println("SUBSET TEST");
@ -373,6 +378,7 @@ void subsetTest()
Serial.println();
}
void iterationTest()
{
Serial.println("10x ITERATE OVER SET TEST");
@ -418,4 +424,6 @@ void iterationTest()
Serial.println();
}
// -- END OF FILE --

View File

@ -1,7 +1,6 @@
//
// FILE: equalTest.ino
// AUTHOR: Rob Tillaart
// VERSION: 0.2.2
// PURPOSE: demo equality operators
// DATE: 2014-11-09
// URL: https://github.com/RobTillaart/SET
@ -13,6 +12,7 @@
Set setA, setB;
volatile bool b;
void setup()
{
Serial.begin(115200);
@ -46,7 +46,11 @@ void setup()
Serial.println();
}
void loop()
{
}
// -- END OF FILE --

View File

@ -1,7 +1,6 @@
//
// FILE: set_demo.ino
// AUTHOR: Rob Tillaart
// VERSION: 0.2.2
// PURPOSE: demo set intersection union and diff
// DATE: 2014-11-09
// URL: https://github.com/RobTillaart/SET
@ -13,6 +12,7 @@
Set setA, setB;
volatile bool b;
void setup()
{
Serial.begin(115200);
@ -95,7 +95,11 @@ void setup()
Serial.println();
}
void loop()
{
}
// -- END OF FILE --

View File

@ -1,7 +1,6 @@
//
// FILE: iterationTest.ino
// AUTHOR: Rob Tillaart
// VERSION: 0.2.2
// PURPOSE: demo first, next, last, prev
// DATE: 2014-11-09
// URL: https://github.com/RobTillaart/SET
@ -15,6 +14,7 @@ Set setA, setB;
volatile bool b;
void setup()
{
Serial.begin(115200);
@ -52,7 +52,11 @@ void setup()
Serial.println();
}
void loop()
{
}
// -- END OF FILE --

View File

@ -1,12 +1,10 @@
//
// FILE: randomFromSet.ino
// AUTHOR: Rob Tillaart
// VERSION: 0.1.0
// PURPOSE: demo random playlist with set
// DATE: 2021-05-04
// URL: https://github.com/RobTillaart/SET
// https://github.com/RobTillaart/Prandom/issues/3
//
#include "set.h"
@ -18,6 +16,7 @@ int SONGS = 15;
uint32_t start, stop ;
void setup()
{
Serial.begin(115200);
@ -69,4 +68,6 @@ int getRandomSong()
return rv;
}
// -- END OF FILE --

View File

@ -1,7 +1,6 @@
//
// FILE: subsetTest.ino
// AUTHOR: Rob Tillaart
// VERSION: 0.2.2
// PURPOSE: demo
// DATE: 2014-11-09
// URL: https://github.com/RobTillaart/SET
@ -43,7 +42,11 @@ void setup()
Serial.println();
}
void loop()
{
}
// -- END OF FILE --

View File

@ -1,7 +1,6 @@
//
// FILE: timingTest.ino
// AUTHOR: Rob Tillaart
// VERSION: 0.2.2
// PURPOSE: timing test for set class methods
// DATE: 2014-11-09
// URL: https://github.com/RobTillaart/SET
@ -18,6 +17,7 @@ uint32_t stop;
volatile bool b;
void setup()
{
Serial.begin(115200);
@ -74,7 +74,11 @@ void setup()
Serial.println();
}
void loop()
{
}
// -- END OF FILE --

View File

@ -1,12 +1,15 @@
# Syntax Coloring Map For Set
# Syntax Colouring Map For Set
# Data types (KEYWORD1)
Set KEYWORD1
# Methods and Functions (KEYWORD2)
clear KEYWORD2
invert KEYWORD2
addAll KEYWORD2
count KEYWORD2
isEmpty KEYWORD2
isFull KEYWORD2
@ -22,5 +25,8 @@ prev KEYWORD2
last KEYWORD2
getNth KEYWORD2
# Constants (LITERAL1)
SET_LIB_VERSION LITERAL1

View File

@ -15,8 +15,9 @@
"type": "git",
"url": "https://github.com/RobTillaart/SET.git"
},
"version": "0.2.4",
"version": "0.2.5",
"license": "MIT",
"frameworks": "arduino",
"platforms": "*"
"platforms": "*",
"headers": "set.h"
}

View File

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

View File

@ -38,8 +38,10 @@
unittest_setup()
{
fprintf(stderr, "SET_LIB_VERSION: %s\n", (char *) SET_LIB_VERSION);
}
unittest_teardown()
{
}
@ -47,8 +49,6 @@ unittest_teardown()
unittest(test_constructor)
{
fprintf(stderr, "VERSION: %s\n", SET_LIB_VERSION);
Set A;
assertTrue(A.isEmpty());
@ -79,8 +79,6 @@ unittest(test_constructor)
unittest(test_count_has)
{
fprintf(stderr, "VERSION: %s\n", SET_LIB_VERSION);
Set A;
A.clear();
@ -107,8 +105,6 @@ unittest(test_count_has)
unittest(test_operator)
{
fprintf(stderr, "VERSION: %s\n", SET_LIB_VERSION);
Set A;
Set B;
Set C;
@ -150,8 +146,6 @@ unittest(test_operator)
unittest(test_iterator)
{
fprintf(stderr, "VERSION: %s\n", SET_LIB_VERSION);
Set A;
A.clear();
@ -189,6 +183,8 @@ unittest(test_iterator)
}
unittest_main()
// --------